How to check if a string has a translated value? I am using AngularJS and AngularTranslate.
I want to show the value only if it has been translated. Angular Translation will display an untranslated string if translation is not available.
I started to do this:
<div ng-if="question.text | translate != question.text">{{ question.text | translate }}</div>
But this will not work, since the comparison occurs before the translation filter has worked. (At least I think this is happening).
What I did in the end:
.filter('isTranslated', function(){ return function(translatedVal, originalVal){ return (translatedVal === originalVal) ? false : true; }
})
<div ng-if="question.text | translate | isTranslated:question.text">{{ question.text | translate }}</div>
This works fine, but I wonder if there is a better way to do this?
javascript angularjs angularjs-filter angular-translate
Neil
source share