From 2052d68f8464fe0e673d9d50fad609f010265325 Mon Sep 17 00:00:00 2001 From: Allan Niles Date: Sun, 6 Jul 2025 22:12:30 -0600 Subject: [PATCH] Language Revamp (#1036) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix translations * fix BCP 47 tags * fix Credits * auto lang * missing logic * clean up * remove semicolon --- data/loader.js | 44 ++++++++++++++--- data/localization/README.md | 53 +++++++++++---------- data/localization/{ar-AR.json => ar.json} | 0 data/localization/{ben-BEN.json => bn.json} | 0 data/localization/{de-GER.json => de.json} | 0 data/localization/{el-GR.json => el.json} | 0 data/localization/{en-US.json => en.json} | 0 data/localization/{es-ES.json => es.json} | 0 data/localization/{fa-AF.json => fa.json} | 0 data/localization/{af-FR.json => fr.json} | 0 data/localization/{hi-HI.json => hi.json} | 0 data/localization/{it-IT.json => it.json} | 0 data/localization/{ja-JA.json => ja.json} | 0 data/localization/{jv-JV.json => jv.json} | 0 data/localization/{ko-KO.json => ko.json} | 0 data/localization/{pt-BR.json => pt.json} | 0 data/localization/{ro-RO.json => ro.json} | 0 data/localization/{ru-RU.json => ru.json} | 0 data/localization/{tr-TR.json => tr.json} | 0 data/localization/{vi-VN.json => vi.json} | 0 data/localization/{zh-CN.json => zh.json} | 0 index.html | 4 +- 22 files changed, 68 insertions(+), 33 deletions(-) rename data/localization/{ar-AR.json => ar.json} (100%) rename data/localization/{ben-BEN.json => bn.json} (100%) rename data/localization/{de-GER.json => de.json} (100%) rename data/localization/{el-GR.json => el.json} (100%) rename data/localization/{en-US.json => en.json} (100%) rename data/localization/{es-ES.json => es.json} (100%) rename data/localization/{fa-AF.json => fa.json} (100%) rename data/localization/{af-FR.json => fr.json} (100%) rename data/localization/{hi-HI.json => hi.json} (100%) rename data/localization/{it-IT.json => it.json} (100%) rename data/localization/{ja-JA.json => ja.json} (100%) rename data/localization/{jv-JV.json => jv.json} (100%) rename data/localization/{ko-KO.json => ko.json} (100%) rename data/localization/{pt-BR.json => pt.json} (100%) rename data/localization/{ro-RO.json => ro.json} (100%) rename data/localization/{ru-RU.json => ru.json} (100%) rename data/localization/{tr-TR.json => tr.json} (100%) rename data/localization/{vi-VN.json => vi.json} (100%) rename data/localization/{zh-CN.json => zh.json} (100%) diff --git a/data/loader.js b/data/loader.js index 22e123b..3ea69f2 100644 --- a/data/loader.js +++ b/data/loader.js @@ -128,20 +128,52 @@ try { systemLang = Intl.DateTimeFormat().resolvedOptions().locale; } catch(e) {} //Ignore - if ((typeof window.EJS_language === "string" && window.EJS_language !== "en-US") || (systemLang && window.EJS_disableAutoLang !== false)) { + const defaultLangs = ["en", "en-US"]; + const isDefaultLang = (lang) => defaultLangs.includes(lang); + if ((typeof window.EJS_language === "string" && !isDefaultLang(window.EJS_language)) || (systemLang && window.EJS_disableAutoLang !== false)) { const language = window.EJS_language || systemLang; + const autoLang = !window.EJS_language && typeof systemLang === "string"; try { - let path; + let languagePath; + let fallbackPath = false; console.log("Loading language", language); if ("undefined" != typeof EJS_paths && typeof EJS_paths[language] === "string") { - path = EJS_paths[language]; + languagePath = EJS_paths[language]; } else { - path = scriptPath + "localization/" + language + ".json"; + languagePath = scriptPath + "localization/" + language + ".json"; + if (language.includes("-") || language.includes("_")) { + fallbackPath = scriptPath + "localization/" + language.split(/[-_]/)[0] + ".json"; + } } config.language = language; - config.langJson = JSON.parse(await (await fetch(path)).text()); + let langJson = {}; + let missingLang = false; + if (!isDefaultLang(language)) { + if (autoLang) { + try { + let languageJson = await fetch(languagePath); + if (!languageJson.ok) throw new Error(`Missing language file: ${languageJson.status}`); + langJson = JSON.parse(await languageJson.text()); + if (fallbackPath) { + let fallbackJson = await fetch(fallbackPath); + missingLang = !fallbackJson.ok; + if (!fallbackJson.ok) throw new Error(`Missing language file: ${fallbackJson.status}`); + langJson = { ...JSON.parse(await fallbackJson.text()), ...langJson }; + } + } catch(e) { + config.language = language.split(/[-_]/)[0]; + console.warn("Failed to load language:", language + ",", "trying default language:", config.language); + if (!missingLang) { + langJson = JSON.parse(await (await fetch(fallbackPath)).text()); + } + } + } else { + langJson = JSON.parse(await (await fetch(languagePath)).text()); + } + config.langJson = langJson; + } } catch(e) { - console.log("Missing language", language, "!!"); + console.log("Missing language:", language, "!!"); delete config.language; delete config.langJson; } diff --git a/data/localization/README.md b/data/localization/README.md index 399bb3c..edbc8c2 100644 --- a/data/localization/README.md +++ b/data/localization/README.md @@ -2,24 +2,25 @@ Supported languages -`en-US` - English US
-`pt-BR` - Portuguese
-`es-ES` - Spanish
-`el-GR` - Greek
-`ja-JA` - Japanese
-`zh-CN` - Chinese
-`hi-HI` - Hindi
-`ar-AR` - Arabic
-`jv-JV` - Javanese
-`ben-BEN` - Bengali
-`ru-RU` - Russian
-`de-GER` - German
-`ko-KO` - Korean
-`af-FR` - French
-`it-IT` - Italian
-`tr-Tr` - Turkish
-`fa-AF` - Persian
-`ro-RO` - Romanian
+`en.json`: `en-US` - English (US)
+`pt.json`: `pt-BR` - Portuguese (Brazil)
+`es.json`: `es-419` - Spanish (Latin America)
+`el.json`: `el-GR` - Greek (Modern Greek)
+`ja.json`: `ja-JP` - Japanese (Japan)
+`zh.json`: `zh-CN` - Chinese (Simplified)
+`hi.json`: `hi-IN` - Hindi (India)
+`ar.json`: `ar-SA` - Arabic (Saudi Arabia)
+`jv.json`: `jv-ID` - Javanese (Indonesia)
+`bn.json`: `bn-BD` - Bengali (Bangladesh)
+`ru.json`: `ru-RU` - Russian (Russia)
+`de.json`: `de-DE` - German (Germany)
+`ko.json`: `ko-KR` - Korean (South Korea)
+`fr.json`: `fr-FR` - French (France)
+`it.json`: `it-IT` - Italian (Italy)
+`tr.json`: `tr-TR` - Turkish (Turkey)
+`fa.json`: `fa-AF` - Persian (Afghanistan)
+`ro.json`: `ro-RO` - Romanian (Romania)
+`vi.json`: `vi-VN` - Vietnamese (Vietnam)
default: `en-US` @@ -33,18 +34,18 @@ If the language file is not found or there was an error fetching the file, the e ## Credits -Translated for `es-ES` originally by [@cesarcristianodeoliveira](https://github.com/cesarcristianodeoliveira) and updated by [@angelmarfil](https://github.com/angelmarfil)
+Translated for `es-419` originally by [@cesarcristianodeoliveira](https://github.com/cesarcristianodeoliveira) and updated by [@angelmarfil](https://github.com/angelmarfil)
Translated for `el-GR` by [@imneckro](https://github.com/imneckro)
Translated for `pt-BR` by [@zmarteline](https://github.com/zmarteline)
Translated for `zh-CN` by [@eric183](https://github.com/eric183)
-Translated for `pt-BR` by [@zmarteline](https://github.com/zmarteline)
Translated for `it-IT` by [@IvanMazzoli](https://github.com/IvanMazzoli)
-Translated for `tr-Tr` by [@iGoodie](https://github.com/iGoodie)
+Translated for `tr-TR` by [@iGoodie](https://github.com/iGoodie)
Translated for `fa-AF` by [@rezamohdev](https://github.com/rezamohdev)
-Translated for `af-FR` by [@t3chnob0y](https://github.com/t3chnob0y)
+Translated for `fr-FR` by [@t3chnob0y](https://github.com/t3chnob0y)
Translated for `ro-RO` by [@jurcaalexandrucristian](https://github.com/jurcaalexandrucristian)
-Translated for `ja-JA` by [@noel-forester](https://github.com/noel-forester)
-Translated for `hi-HI`, `ar-AR`, `jv-JV`, `ben-BEN`, `ru-RU`, `de-GER`, `ko-KO` by [@allancoding](https://github.com/allancoding), using a translate application
+Translated for `ja-JP` by [@noel-forester](https://github.com/noel-forester)
+Translated for `vi-VN` by [@TimKieu](https://github.com/TimKieu)
+Translated for `hi-IN`, `ar-SA`, `jv-iD`, `bn-BD`, `ru-RU`, `de-DE`, `ko-KR` by [@allancoding](https://github.com/allancoding), using a translate application
## Contributing @@ -52,7 +53,9 @@ To contribute, please download the default `en-US.json` language file to use as The EmulatorJS team will review and add your changes. -The `retroarch.json` are all the setting names for the menu. They will default to english if not found. You can set `EJS_settingsLanguage` to `true` to see the missing retroarch settings names for the current language. You can translate them and add the to the language file. +As of version `4.2.2` it will default to the system language. + +The `retroarch.json` are all the setting names for the menu. You can set `EJS_settingsLanguage` to `true` to see the missing retroarch settings names for the current language. You can translate them and add the to the language file. The control mapping translations for controllers are diffrent for each controller. They will need to be added to the language file if they are not in the default `en-US.json` file. diff --git a/data/localization/ar-AR.json b/data/localization/ar.json similarity index 100% rename from data/localization/ar-AR.json rename to data/localization/ar.json diff --git a/data/localization/ben-BEN.json b/data/localization/bn.json similarity index 100% rename from data/localization/ben-BEN.json rename to data/localization/bn.json diff --git a/data/localization/de-GER.json b/data/localization/de.json similarity index 100% rename from data/localization/de-GER.json rename to data/localization/de.json diff --git a/data/localization/el-GR.json b/data/localization/el.json similarity index 100% rename from data/localization/el-GR.json rename to data/localization/el.json diff --git a/data/localization/en-US.json b/data/localization/en.json similarity index 100% rename from data/localization/en-US.json rename to data/localization/en.json diff --git a/data/localization/es-ES.json b/data/localization/es.json similarity index 100% rename from data/localization/es-ES.json rename to data/localization/es.json diff --git a/data/localization/fa-AF.json b/data/localization/fa.json similarity index 100% rename from data/localization/fa-AF.json rename to data/localization/fa.json diff --git a/data/localization/af-FR.json b/data/localization/fr.json similarity index 100% rename from data/localization/af-FR.json rename to data/localization/fr.json diff --git a/data/localization/hi-HI.json b/data/localization/hi.json similarity index 100% rename from data/localization/hi-HI.json rename to data/localization/hi.json diff --git a/data/localization/it-IT.json b/data/localization/it.json similarity index 100% rename from data/localization/it-IT.json rename to data/localization/it.json diff --git a/data/localization/ja-JA.json b/data/localization/ja.json similarity index 100% rename from data/localization/ja-JA.json rename to data/localization/ja.json diff --git a/data/localization/jv-JV.json b/data/localization/jv.json similarity index 100% rename from data/localization/jv-JV.json rename to data/localization/jv.json diff --git a/data/localization/ko-KO.json b/data/localization/ko.json similarity index 100% rename from data/localization/ko-KO.json rename to data/localization/ko.json diff --git a/data/localization/pt-BR.json b/data/localization/pt.json similarity index 100% rename from data/localization/pt-BR.json rename to data/localization/pt.json diff --git a/data/localization/ro-RO.json b/data/localization/ro.json similarity index 100% rename from data/localization/ro-RO.json rename to data/localization/ro.json diff --git a/data/localization/ru-RU.json b/data/localization/ru.json similarity index 100% rename from data/localization/ru-RU.json rename to data/localization/ru.json diff --git a/data/localization/tr-TR.json b/data/localization/tr.json similarity index 100% rename from data/localization/tr-TR.json rename to data/localization/tr.json diff --git a/data/localization/vi-VN.json b/data/localization/vi.json similarity index 100% rename from data/localization/vi-VN.json rename to data/localization/vi.json diff --git a/data/localization/zh-CN.json b/data/localization/zh.json similarity index 100% rename from data/localization/zh-CN.json rename to data/localization/zh.json diff --git a/index.html b/index.html index d112a18..ea464fe 100644 --- a/index.html +++ b/index.html @@ -45,7 +45,7 @@ } #box:hover, #box[drag] { - border-color: #38f; + border-color: #1AAFFF; color: #ddd } @@ -88,7 +88,7 @@ .logo { width: 130px; height: 130px; - filter: drop-shadow(0 0 10px white); + filter: drop-shadow(0 0 8px white); } #top {