From f838b77adfcac8c25ff0508f695e9222ad60d6f6 Mon Sep 17 00:00:00 2001 From: "Mike D." <62747981+mrd83@users.noreply.github.com> Date: Fri, 27 Jun 2025 02:12:01 +0200 Subject: [PATCH] Resolve the i18n file loading error if UI language = en --- core_js/log.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/core_js/log.js b/core_js/log.js index 6132683..b7904ae 100644 --- a/core_js/log.js +++ b/core_js/log.js @@ -51,8 +51,9 @@ function getLog() log.log.sort(function(a,b) { return b.timestamp - a.timestamp; }); - - $('#logTable').DataTable({ + + let lang = getUILanguageCode(); + let dataTableOptions = { "data": log.log, "columns": [ { @@ -78,21 +79,30 @@ function getLog() render: toDate } ], - "pageLength": 10, - "language": { - "url": getDataTableTranslation() - } - } ).order([3, 'desc']).draw(); + "pageLength": 10 + }; + if (lang !== "en") { + dataTableOptions.language = { + "url": getDataTableTranslation(lang) + }; + } + + $('#logTable').DataTable(dataTableOptions).order([3, 'desc']).draw(); }).catch(handleError); } /** - * Get the translation file for the DataTable + * Get the two-letter language code of the browser's UI language */ -function getDataTableTranslation() -{ +function getUILanguageCode() { let lang = browser.i18n.getUILanguage(); - lang = lang.substring(0,2); + return lang.substring(0, 2).toLowerCase(); +} + +/** + * Get the translation file for the DataTable + */ +function getDataTableTranslation(lang) { return browser.runtime.getURL('./external_js/dataTables/i18n/' + lang + '.json'); }