Open macnewbold opened 2 years ago
This seems to be a replacement that is functioning well for me:
babel.ngettext = function(text, text_plural, n, variables) {
var p;
var str;
if (babel.plural) {
p = babel.plural(n);
} else {
p = (n !== 1);
}
p = (p ? 1 : 0);
str = [text, text_plural][p];
if ((str in babel.catalog) && babel.catalog.hasOwnProperty(str)) {
return babel.format(babel.catalog[str], variables);
} else {
return babel.format(str, variables);
}
};
I'm getting javascript exceptions from this section of code, when my translations define what plural means:
When the translation defines Plural-Forms: in the PO file, that leads to the creation and existence of
babel.plural
, which evaluates n to determine if it is plural, and returns a boolean true or false. The else branch though setsp
to an integer, 1 or 0. Then down below when it looks up the catalog property, it tries to take that catalog value for the text (which is a string) and use the boolean p value as a subscript, which throws an error. The other case, where it isn't in the catalog, works fine usingp
as a subscript, as long asbabel.plural
wasn't defined, but fails ifbabel.plural
exists.If I were proposing a fix, it would be to convert the babel.plural result to an integer, and remove the
[p]
subscript on the branch where the catalog has the value.