diff --git a/TRANSLATIONS.md b/TRANSLATIONS.md new file mode 100644 index 0000000..ff389d4 --- /dev/null +++ b/TRANSLATIONS.md @@ -0,0 +1,42 @@ +# Translations Guidelines + +## Overview +Translations for the "DualShock Calibration GUI" project are managed through +JSON files located in the [lang/ directory](https://github.com/dualshock-tools/dualshock-tools.github.io/tree/main/lang). + +This document provides guidelines on how to contribute translations for new languages. + +## Getting Started +To translate the project into a new language, follow these steps: + +1. **Duplicate an Existing File**: Start by duplicating an existing language file located in the `lang/` directory. For example, if you're translating into Spanish, duplicate `lang/it_it.json` and rename it to `lang/es_es.json`. + +2. **Edit the File**: Open the duplicated JSON file and replace the translations of strings with the corresponding translations in the target language. The first entry `.authorMsg` is customizable, write there your name and, if you want, your website! + +3. **Save the File**: Save the changes to the JSON file. + +4. **Update `core.js`**: Add the new language to the list of available languages (`available_langs`) in [core.js](https://github.com/dualshock-tools/dualshock-tools.github.io/blob/main/core.js). For example: + +```json +var available_langs = { + "zh_cn": { "name": "Chinese", "file": "zh_cn.json"}, + "fr_fr": { "name": "Français", "file": "fr_fr.json"}, + "hu_hu": { "name": "Hungarian", "file": "hu_hu.json"}, + "it_it": { "name": "Italiano", "file": "it_it.json"}, + "es_es": { "name": "Español", "file": "es_es.json"}, +}; +``` + +## Submitting Translations +Once you have completed the translation, you can contribute it in one of the following ways: + +- **Pull Request (PR)**: Open a Pull Request with the changes. +- **Discord**: Send the translated file to `the_al` on Discord. +- **Email**: Send the translated file to `ds4@the.al` via email. + +Feel free to adjust any details or formatting according to your preferences! + +## Thank you + +We extend our heartfelt gratitude to everyone who contributes translations to +make this project accessible to a wider audience. Thank you! diff --git a/core.js b/core.js index 858e99e..2f96956 100644 --- a/core.js +++ b/core.js @@ -8,10 +8,10 @@ var lang_cur = {}; var lang_disabled = true; var available_langs = { - "fr_fr": "fr_fr.json", - "hu_hu": "hu_hu.json", - "it_it": "it_it.json", - "zh_cn": "zh_cn.json", + "zh_cn": { "name": "中文", "file": "zh_cn.json"}, + "fr_fr": { "name": "Français", "file": "fr_fr.json"}, + "it_it": { "name": "Italiano", "file": "it_it.json"}, + "hu_hu": { "name": "Magyar", "file": "hu_hu.json"}, }; function dec2hex(i) { @@ -1030,7 +1030,38 @@ function lang_init() { var nlang = navigator.language.replace('-', '_').toLowerCase(); var ljson = available_langs[nlang]; if(ljson !== undefined) { - lang_translate(ljson); + lang_translate(ljson["file"], nlang); + } + + var langs = Object.keys(available_langs); + var olangs = ""; + olangs += '
  • English
  • '; + for(i=0;i' + name + ''; + } + olangs += '
  • '; + olangs += '
  • Missing your language?
  • '; + $("#availLangs").html(olangs); + + var force_lang = readCookie("force_lang"); + if (force_lang != null) { + lang_set(force_lang, true); + } +} + +function lang_set(l, skip_modal=false) { + if(l == "en_us") { + lang_reset_page(); + } else { + var file = available_langs[l]["file"]; + lang_translate(file, l); + } + + createCookie("force_lang", l); + if(!skip_modal) { + createCookie("welcome_accepted", "0"); + welcome_modal(); } } @@ -1040,6 +1071,8 @@ function lang_reset_page() { var item = items[i]; $(item).html(lang_orig_text[item.id]); } + $("#authorMsg").html(""); + $("#curLang").html("English"); } function l(text) { @@ -1055,9 +1088,9 @@ function l(text) { return text; } -function lang_translate(target_lang) { +function lang_translate(target_file, target_lang) { lang_cur = {} - $.getJSON("lang/" + target_lang, function(data) { + $.getJSON("lang/" + target_file, function(data) { $.each( data, function( key, val ) { if(lang_cur[key] !== undefined) { console.log("Warn: already exists " + key); @@ -1085,8 +1118,9 @@ function lang_translate(target_lang) { var old_title = lang_orig_text[".title"]; document.title = lang_cur[old_title]; if(lang_cur[".authorMsg"] !== undefined) { - $("#authorMsg").html(lang_cur[".authorMsg"]) + $("#authorMsg").html(lang_cur[".authorMsg"]); } + $("#curLang").html(available_langs[target_lang]["name"]); }); } diff --git a/index.html b/index.html index 31b6ade..9f1c135 100644 --- a/index.html +++ b/index.html @@ -36,13 +36,32 @@ + + + + + +
    -

    DualShock Calibration GUI