From 2aa5d1afbe0c9f1f1397a3acdd7573a6f43cf250 Mon Sep 17 00:00:00 2001 From: Thomas Lynch Date: Thu, 19 Jan 2023 21:30:34 +1100 Subject: [PATCH] make frontend translation fallback to keys if missing --- gulp/res/js/i18n.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gulp/res/js/i18n.js b/gulp/res/js/i18n.js index 6125a90f..ecadcfd2 100644 --- a/gulp/res/js/i18n.js +++ b/gulp/res/js/i18n.js @@ -8,11 +8,15 @@ const pluralMap = { //simple translation const __ = (key) => { - return LANG[key]; + return LANG[key] || key; }; //plurals+replace %s with count const __n = (key, count) => { const pluralKey = pluralMap[count] || 'other'; - return LANG[key][pluralKey].replace('%s', count); + const translationObj = LANG[key]; + if (!translationObj) { + return key; + } + return translationObj[pluralKey].replace('%s', count); };