Using Angular Translate as a filter in the view has been very effective for me. I have implemented angular-translate-loader-static-files to load external files like locale-en.json
.
However, I encountered an issue when attempting to do something like this:
var placeholder = $translate('placeholder.NAME')
.then(function (translatedValue) {
return translatedValue;
});
Instead of getting the word NAME displayed in English, I always receive a promise object {}
in the UI.
What is the correct way to handle translations in JavaScript using angular-translate?
EDIT: I attempted the following solution but still faced the same issue:
var placeholder = '';
$translate('placeholder.NAME').then(function (translatedValue) {
console.log(translatedValue);
placeholder = translatedValue;
}, function(err){
console.log(err); // returns placeholder.NAME
});
console.log(placeholder); // returns empty string