Skip to content

Commit 461b972

Browse files
committed
Plurals fixes & improvements
1 parent 9bf9f36 commit 461b972

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/simplin.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@ class StringProvider {
7878
if (Array.isArray(args)) // it's better to cut the string under multiple IDs to avoid any confusion during decision of the plural category
7979
throw new Error(`Passing multiple arguments to a plural string is not supported: ${str}`);
8080

81-
const pluralCategory = pluralRules[locale].select(args)
82-
const loadedPluralForm = loaded[pluralCategory];
8381

84-
if(!loadedPluralForm) // Translator probably forgot to define the requested plural
85-
return this._insertArguments(locales[this.defaultLocale][str.trim()][pluralRules[this.defaultLocale].select(args)],
86-
args); // => return fallback language
82+
let pluralCategory = pluralRules[locale].select(args)
83+
let loadedPluralForm = loaded[pluralCategory];
84+
if (loadedPluralForm === null || loadedPluralForm === undefined)
85+
{
86+
// Translator probably forgot to define the requested plural
87+
pluralCategory = pluralRules[this.defaultLocale].select(args); // return fallback language instead
88+
try { loadedPluralForm = locales[this.defaultLocale][str.trim()][pluralCategory] || str; }
89+
catch { loadedPluralForm = str; } // return input ID if default language do not define it either
90+
}
8791

8892
return this._insertArguments(loadedPluralForm, args);
8993
};

0 commit comments

Comments
 (0)