angular-gettext
angular-gettext copied to clipboard
Dynamic message interpolation
Every now and then I need to show a message that comes from a controller and this needs to get interpolated. The thing is I've only achieved to show the string I want to lookup, or the translated string but without getting the final result.
You can see an example in here http://jsfiddle.net/subarroca/ftjpfgk8/
@subarroca I think you might have the wrong idea about how this package works...
From your jsfiddle...
gettextCatalog.setStrings('ca', {
'welcome': 'Benvingut a {{appName}}',
});
The key is supposed to be the original untranslated string.
If you want the translated string to have an interpolated variable, the key needs to have an interpolated variable. That might be your issue. I'm not sure because I'm a bit confused with your wording.
Please close this issue :smile:
$rootScope.message = 'welcome';
Should be:
$rootScope.message = gettext('welcome');
See https://angular-gettext.rocketeer.be/dev-guide/annotate-js/
But @mattbrunetti is 100% correct, your keys should always be the untranslated English strings, otherwise your translators will hate you.
So it should be this:
$rootScope.message = gettext('Welcome to {{appName}}');