angular-gettext
angular-gettext copied to clipboard
getString should not rely on || for prefixing the result
Hello,
I met this issue when started to work on the numbers formatting. Certain locales like RU define thousand separator as an empty string 1000 when others represent it as 1 000.
When I tried to use empty string as an separator I found that
getString: function (string, scope, context) {
string = this.getStringForm(string, 0, context) || prefixDebug(string);
string = scope ? $interpolate(string)(scope) : string;
return addTranslatedMarkers(string);
},
prefixes the token with [MISSING] because an empty string threated as false.
I suggest to use explicit check for null or undefined to avoid such a problems.
E.g.
string = this.getStringForm(string, 0, context);
if (null === string || void(null) === string) {
string = prefixDebug(string);
}
I'm not sure I fully understand your issue, as far as I understand it, you might be using angular-gettext for something it's not designed for.
- Could you make a jsFiddle example (if possible)?
- Have you considered using
$localefor number formatting? (this is what I recommend)
here is the example https://jsfiddle.net/y8uy4x8h/
$locale is not an option for me as long as it is not connected to the translation tool.
$locale is not an option for me as long as it is not connected to the translation tool.
Well, it doesn't have to be, all locales should be translated already.
Also note that we don't compile empty strings into the translation files, so what you are proposing won't work. Even if we did, it'd be wrong to accept an empty string as ok, in pretty much all cases this does in fact mean "translation missing".
I highly recommend you look into $locale a bit more: it perfectly fits the need for number/date/currency localisation. I did not add support for those types of data because $locale solves that. Angular-gettext is designed for text: I suspect you're setting yourself up for a world of pain by trying to use it for other things.
Ok, thank you for the explanation.