From 2784072fb4e29ebc74e507b15dbfb677b74e4586 Mon Sep 17 00:00:00 2001 From: KOWX712 Date: Thu, 27 Feb 2025 04:51:05 +0800 Subject: [PATCH] fix: get language function --- module/webui/locales/A-translate.md | 7 ++++--- module/webui/locales/available-lang.json | 13 +++++++++++++ module/webui/scripts/language.js | 12 +++--------- 3 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 module/webui/locales/available-lang.json diff --git a/module/webui/locales/A-translate.md b/module/webui/locales/A-translate.md index 0e483c8..bca5ed5 100644 --- a/module/webui/locales/A-translate.md +++ b/module/webui/locales/A-translate.md @@ -1,7 +1,7 @@ # Translation Guide ## Fix Bad Translation 1. Fork this repository. -2. Find your language string file in `/module/webroot/locales/`. +2. Find your language string file in `/module/webui/locales/`. 3. Edit the string value with translated incorrectly. 4. Create a Pull Request. @@ -12,7 +12,8 @@ ### Advanced 1. Fork this repository. -2. Make a copy of `/module/webroot/locales/A-template.json` +2. Make a copy of `/module/webui/locales/A-template.json` 3. Rename it to `language_code-COUNTRY_CODE.json`, e.g., `en-US.json`. 4. Translate the string value inside. -6. Create a Pull Request. \ No newline at end of file +5. Add the language code to `/module/webui/locales/available-lang.json`. +6. Create a Pull Request. diff --git a/module/webui/locales/available-lang.json b/module/webui/locales/available-lang.json new file mode 100644 index 0000000..7d0555e --- /dev/null +++ b/module/webui/locales/available-lang.json @@ -0,0 +1,13 @@ +{ + "languages": [ + "en-US", + "es-ES", + "ja-JP", + "pl-PL", + "ru-RU", + "tl-PH", + "tr-TR", + "zh-CN", + "zh-TW" + ] +} \ No newline at end of file diff --git a/module/webui/scripts/language.js b/module/webui/scripts/language.js index 3b1d45f..12bdabf 100644 --- a/module/webui/scripts/language.js +++ b/module/webui/scripts/language.js @@ -12,15 +12,9 @@ let availableLanguages = ['en-US']; // Function to check for available language export async function initializeAvailableLanguages() { try { - const response = await fetch('locales/'); - const text = await response.text(); - const parser = new DOMParser(); - const html = parser.parseFromString(text, 'text/html'); - const files = Array.from(html.querySelectorAll('a')) - .map(a => a.href.split('/').pop()) - .filter(file => file.endsWith('.json') && file !== 'A-template.json') - .map(file => file.replace('.json', '')); - availableLanguages = files; + const response = await fetch('locales/available-lang.json'); + const config = await response.json(); + availableLanguages = config.languages; generateLanguageMenu(); } catch (error) { console.error('Failed to fetch available languages:', error);