Language Revamp (#1036)

* fix translations

* fix BCP 47 tags

* fix Credits

* auto lang

* missing logic

* clean up

* remove semicolon
This commit is contained in:
Allan Niles 2025-07-06 22:12:30 -06:00 committed by GitHub
parent e77610e890
commit 2052d68f84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 68 additions and 33 deletions

View File

@ -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;
}

View File

@ -2,24 +2,25 @@
Supported languages
`en-US` - English US<br>
`pt-BR` - Portuguese<br>
`es-ES` - Spanish<br>
`el-GR` - Greek<br>
`ja-JA` - Japanese<br>
`zh-CN` - Chinese<br>
`hi-HI` - Hindi<br>
`ar-AR` - Arabic<br>
`jv-JV` - Javanese<br>
`ben-BEN` - Bengali<br>
`ru-RU` - Russian<br>
`de-GER` - German<br>
`ko-KO` - Korean<br>
`af-FR` - French<br>
`it-IT` - Italian<br>
`tr-Tr` - Turkish<br>
`fa-AF` - Persian<br>
`ro-RO` - Romanian<br>
`en.json`: `en-US` - English (US)<br>
`pt.json`: `pt-BR` - Portuguese (Brazil)<br>
`es.json`: `es-419` - Spanish (Latin America)<br>
`el.json`: `el-GR` - Greek (Modern Greek)<br>
`ja.json`: `ja-JP` - Japanese (Japan)<br>
`zh.json`: `zh-CN` - Chinese (Simplified)<br>
`hi.json`: `hi-IN` - Hindi (India)<br>
`ar.json`: `ar-SA` - Arabic (Saudi Arabia)<br>
`jv.json`: `jv-ID` - Javanese (Indonesia)<br>
`bn.json`: `bn-BD` - Bengali (Bangladesh)<br>
`ru.json`: `ru-RU` - Russian (Russia)<br>
`de.json`: `de-DE` - German (Germany)<br>
`ko.json`: `ko-KR` - Korean (South Korea)<br>
`fr.json`: `fr-FR` - French (France)<br>
`it.json`: `it-IT` - Italian (Italy)<br>
`tr.json`: `tr-TR` - Turkish (Turkey)<br>
`fa.json`: `fa-AF` - Persian (Afghanistan)<br>
`ro.json`: `ro-RO` - Romanian (Romania)<br>
`vi.json`: `vi-VN` - Vietnamese (Vietnam)<br>
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) <br>
Translated for `es-419` originally by [@cesarcristianodeoliveira](https://github.com/cesarcristianodeoliveira) and updated by [@angelmarfil](https://github.com/angelmarfil) <br>
Translated for `el-GR` by [@imneckro](https://github.com/imneckro) <br>
Translated for `pt-BR` by [@zmarteline](https://github.com/zmarteline)<br>
Translated for `zh-CN` by [@eric183](https://github.com/eric183)<br>
Translated for `pt-BR` by [@zmarteline](https://github.com/zmarteline) <br>
Translated for `it-IT` by [@IvanMazzoli](https://github.com/IvanMazzoli) <br>
Translated for `tr-Tr` by [@iGoodie](https://github.com/iGoodie) <br>
Translated for `tr-TR` by [@iGoodie](https://github.com/iGoodie) <br>
Translated for `fa-AF` by [@rezamohdev](https://github.com/rezamohdev) <br>
Translated for `af-FR` by [@t3chnob0y](https://github.com/t3chnob0y) <br>
Translated for `fr-FR` by [@t3chnob0y](https://github.com/t3chnob0y) <br>
Translated for `ro-RO` by [@jurcaalexandrucristian](https://github.com/jurcaalexandrucristian) <br>
Translated for `ja-JA` by [@noel-forester](https://github.com/noel-forester) <br>
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 <br>
Translated for `ja-JP` by [@noel-forester](https://github.com/noel-forester) <br>
Translated for `vi-VN` by [@TimKieu](https://github.com/TimKieu) <br>
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 <br>
## 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.

View File

@ -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 {