From 1c663b7675724db0c3c69c7fe5db64d028fdb6bc Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Wed, 8 Sep 2021 10:39:46 -0400 Subject: [PATCH 1/2] Log warning instead of error when dictionary has not loaded --- src/scripts/globalize.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/scripts/globalize.js b/src/scripts/globalize.js index c66ed2b7f..6ecedfeaf 100644 --- a/src/scripts/globalize.js +++ b/src/scripts/globalize.js @@ -1,5 +1,7 @@ -import * as userSettings from './settings/userSettings'; import { Events } from 'jellyfin-apiclient'; +import isEmpty from 'lodash-es/isEmpty'; + +import * as userSettings from './settings/userSettings'; /* eslint-disable indent */ @@ -189,7 +191,11 @@ import { Events } from 'jellyfin-apiclient'; dictionary = getDictionary(module, fallbackCulture); } if (!dictionary || !dictionary[key]) { - console.error(`Translation key is missing from dictionary: ${key}`); + if (dictionary && isEmpty(dictionary)) { + console.warn('Translation dictionary is empty.'); + } else { + console.error(`Translation key is missing from dictionary: ${key}`); + } return key; } return dictionary[key]; From 172e06ed3fae12897576dca9b16be5ca506a4d66 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Wed, 8 Sep 2021 13:11:20 -0400 Subject: [PATCH 2/2] Refactor translation method --- src/scripts/globalize.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/scripts/globalize.js b/src/scripts/globalize.js index 6ecedfeaf..6bffd8e55 100644 --- a/src/scripts/globalize.js +++ b/src/scripts/globalize.js @@ -187,18 +187,22 @@ import * as userSettings from './settings/userSettings'; function translateKeyFromModule(key, module) { let dictionary = getDictionary(module, getCurrentLocale()); - if (!dictionary || !dictionary[key]) { - dictionary = getDictionary(module, fallbackCulture); + if (dictionary && dictionary[key]) { + return dictionary[key]; } - if (!dictionary || !dictionary[key]) { - if (dictionary && isEmpty(dictionary)) { - console.warn('Translation dictionary is empty.'); - } else { - console.error(`Translation key is missing from dictionary: ${key}`); - } - return key; + + dictionary = getDictionary(module, fallbackCulture); + if (dictionary && dictionary[key]) { + return dictionary[key]; } - return dictionary[key]; + + if (!dictionary || isEmpty(dictionary)) { + console.warn('Translation dictionary is empty.'); + } else { + console.error(`Translation key is missing from dictionary: ${key}`); + } + + return key; } function replaceAll(str, find, replace) {