angular-gettext icon indicating copy to clipboard operation
angular-gettext copied to clipboard

Dynamic message interpolation

Open subarroca opened this issue 10 years ago • 2 comments
trafficstars

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 avatar Aug 05 '15 15:08 subarroca

@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:

mattbrunetti avatar Mar 29 '17 19:03 mattbrunetti

$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}}');

rubenv avatar Mar 29 '17 19:03 rubenv