SimpleX-Chat/website/merge_translations.js

39 lines
1.3 KiB
JavaScript
Raw Normal View History

website internationalization (#1922) * website Internationalization (#1904) * added devcontainer config * internationalization under dev * internationalization of _data done * overlays internationalization done * improved routing * updated gitignore * remove .devcontainer * internationalization in progess deleted all the intermediate files added translation of few sections * remaining website strings are added to translation * done internationalization - fully converted to i18n plugin - wrote bash script for creating a combined translations.json * internationalization UI done * a quick fix * remove jq installation * Added translation using Weblate (German) * Translated using Weblate (French) Currently translated at 100.0% (212 of 212 strings) Translation: SimpleX Chat/SimpleX Chat website Translate-URL: https://hosted.weblate.org/projects/simplex-chat/website/fr/ * Translated using Weblate (German) Currently translated at 42.9% (91 of 212 strings) Translation: SimpleX Chat/SimpleX Chat website Translate-URL: https://hosted.weblate.org/projects/simplex-chat/website/de/ * fixes of web Internationalization (#1925) * a quick fix * blog route for all languages is shifted to root blog route * wrote merge_translations.js * remove language label from dropdown * update language names * refactor scripts * remove catch from script * Added translation using Weblate (Dutch) * Added translation using Weblate (Norwegian Bokmål) * Translated using Weblate (Dutch) Currently translated at 33.0% (70 of 212 strings) Translation: SimpleX Chat/SimpleX Chat website Translate-URL: https://hosted.weblate.org/projects/simplex-chat/website/nl/ * website: internationalization fixes (#1931) * added devcontainer config * internationalization under dev * internationalization of _data done * overlays internationalization done * improved routing * updated gitignore * remove .devcontainer * internationalization in progess deleted all the intermediate files added translation of few sections * remaining website strings are added to translation * done internationalization - fully converted to i18n plugin - wrote bash script for creating a combined translations.json * internationalization UI done * a quick fix * blog route for all languages is shifted to root blog route * wrote merge_translations.js * remove flag from blog * updated nav stylings & logo links * add enabled key * updated nav dropdown styling * gave specific lang to i18n plugin. overlay translations are now working. * enable nl & nb_NO * updated nav stylings * updated contact.js --------- Co-authored-by: M Sarmad Qadeer <msarmadqadeer@gmail.com> * Translated using Weblate (German) Currently translated at 47.6% (101 of 212 strings) Translation: SimpleX Chat/SimpleX Chat website Translate-URL: https://hosted.weblate.org/projects/simplex-chat/website/de/ * fixed internationalization issues * updated strings, refactor contact.js * updated nav stylings for mobile * a bit smaller padding on mobile * Added translation using Weblate (Czech) * Translated using Weblate (Czech) Currently translated at 100.0% (212 of 212 strings) Translation: SimpleX Chat/SimpleX Chat website Translate-URL: https://hosted.weblate.org/projects/simplex-chat/website/cs/ * Translated using Weblate (French) Currently translated at 100.0% (212 of 212 strings) Translation: SimpleX Chat/SimpleX Chat website Translate-URL: https://hosted.weblate.org/projects/simplex-chat/website/fr/ * Translated using Weblate (German) Currently translated at 100.0% (212 of 212 strings) Translation: SimpleX Chat/SimpleX Chat website Translate-URL: https://hosted.weblate.org/projects/simplex-chat/website/de/ * enabled languages * check/correct (#1949) --------- Co-authored-by: M Sarmad Qadeer <MSarmadQadeer@gmail.com> Co-authored-by: Ophiushi <Ophiushi@users.noreply.hosted.weblate.org> Co-authored-by: mlanp <github@lang.xyz> Co-authored-by: John m <jvanmanen@gmail.com> Co-authored-by: zenobit <zen@osowoso.xyz> Co-authored-by: Ophiushi <41908476+ishi-sama@users.noreply.github.com>
2023-02-24 21:03:57 +00:00
const fs = require("fs");
const path = require("path");
let supportedLangs = []
const translationsDirectoryPath = path.resolve(__dirname, "langs")
const files = fs.readdirSync(translationsDirectoryPath);
const jsonFileNames = files.filter(file => file.endsWith('.json'));
supportedLangs = jsonFileNames.map(file => file.replace('.json', ''))
// keys of the english language are used as the base keys
const enStrings = require("./langs/en.json")
const languages = {}
for (const lang of supportedLangs) {
languages[lang] = require(`./langs/${lang}.json`)
}
// this program generates a combined translations.json file
const translations = {}
for (const key in enStrings) {
const langStrings = {}
for (const lang of supportedLangs) {
const str = languages[lang][key]
if (str) langStrings[lang] = str
}
translations[key] = langStrings
}
saveFile("translations.json", translations)
// the list in the supported_languages.json file is used as the reference list for displaying available languages on the frontend
saveFile("src/_data/supported_languages.json", {"langs": supportedLangs})
function saveFile(relPath, data) {
filePath = path.resolve(__dirname, relPath)
fs.writeFileSync(filePath, JSON.stringify(data, undefined, " "), 'utf-8');
console.log(`Data was successfully written to ${filePath}`);
}