Translating doesn't work in a Factory
Using gettextCatalog.getString() doesn't work in a factory. It returns the untranslated string.
Is there anything I can do about this?
Can you post more of your code? You most likely have something misconfigured, and it's impossible to tell what's going on otherwise.
export function PersonService(gettextCatalog) {
return {
/**
* A dictionary with gender translations
*/
genders: {
'm': gettextCatalog.getString('Male'),
'f': gettextCatalog.getString('Female')
},
};
}
The problem might be that translations are not yet initialized when creating the factory?
I can confirm that it does not work in my factory.
I had the same issue, and solved it by setting the strings as translatable :
Instead of getting the translation for the strings, you do this :
export function PersonService(gettext) {
return {
/**
* A dictionary with genders
*/
genders: {
'm': gettext('Male'),
'f': gettext('Female')
},
};
}
And then using the translate filter in my view (supposing you do that through a controller) :
{{genders.m|translate}}
No answer to this still? How come in a directive: gettextCatalog.getString("yes") returns "oui" ...but in a factory: gettextCatalog.getString("yes") returns "yes" ? I'd be very grateful of assistance else I will need to so some horrible hacking Thanks :)
@rikpalmermm are you sure that factory is good place to translate strings? Could you anotate (call getext(key)) at factory layer and then use translate directive or filter at template;)
smth like: key string or {{factory.prop | filter}}