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

getString should not rely on || for prefixing the result

Open wingedfox opened this issue 10 years ago • 4 comments

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

wingedfox avatar May 26 '15 09:05 wingedfox

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.

  1. Could you make a jsFiddle example (if possible)?
  2. Have you considered using $locale for number formatting? (this is what I recommend)

rubenv avatar May 26 '15 09:05 rubenv

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.

wingedfox avatar May 26 '15 10:05 wingedfox

$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.

rubenv avatar May 26 '15 11:05 rubenv

Ok, thank you for the explanation.

wingedfox avatar May 26 '15 11:05 wingedfox