Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify languages.json file and grab language names from Intl #26001

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 59 additions & 61 deletions scripts/copy-res.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,56 @@ const loaderUtils = require("loader-utils");
// copies the resources into the webapp directory.
//

// Languages are listed manually so we can choose when to include
// a translation in the app (because having a translation with only
// 3 strings translated is just frustrating)
// This could readily be automated, but it's nice to explicitly
// control when new languages are available.
// Languages are listed manually, so we can choose when to include a translation in the app
// (because having a translation with only 3 strings translated is just frustrating)
// This could readily be automated, but it's nice to explicitly control when new languages are available.
const INCLUDE_LANGS = [
{ value: "bg", label: "Български" },
{ value: "ca", label: "Català" },
{ value: "cs", label: "čeština" },
{ value: "da", label: "Dansk" },
{ value: "de_DE", label: "Deutsch" },
{ value: "el", label: "Ελληνικά" },
{ value: "en_EN", label: "English" },
{ value: "en_US", label: "English (US)" },
{ value: "eo", label: "Esperanto" },
{ value: "es", label: "Español" },
{ value: "et", label: "Eesti" },
{ value: "eu", label: "Euskara" },
{ value: "fi", label: "Suomi" },
{ value: "fr", label: "Français" },
{ value: "gl", label: "Galego" },
{ value: "he", label: "עברית" },
{ value: "hi", label: "हिन्दी" },
{ value: "hu", label: "Magyar" },
{ value: "id", label: "Bahasa Indonesia" },
{ value: "is", label: "íslenska" },
{ value: "it", label: "Italiano" },
{ value: "ja", label: "日本語" },
{ value: "kab", label: "Taqbaylit" },
{ value: "ko", label: "한국어" },
{ value: "lo", label: "ລາວ" },
{ value: "lt", label: "Lietuvių" },
{ value: "lv", label: "Latviešu" },
{ value: "nb_NO", label: "Norwegian Bokmål" },
{ value: "nl", label: "Nederlands" },
{ value: "nn", label: "Norsk Nynorsk" },
{ value: "pl", label: "Polski" },
{ value: "pt", label: "Português" },
{ value: "pt_BR", label: "Português do Brasil" },
{ value: "ru", label: "Русский" },
{ value: "sk", label: "Slovenčina" },
{ value: "sq", label: "Shqip" },
{ value: "sr", label: "српски" },
{ value: "sv", label: "Svenska" },
{ value: "te", label: "తెలుగు" },
{ value: "th", label: "ไทย" },
{ value: "tr", label: "Türkçe" },
{ value: "uk", label: "українська мова" },
{ value: "vi", label: "Tiếng Việt" },
{ value: "vls", label: "West-Vlaams" },
{ value: "zh_Hans", label: "简体中文" }, // simplified chinese
{ value: "zh_Hant", label: "繁體中文" }, // traditional chinese
"bg",
"ca",
"cs",
"da",
"de_DE",
"el",
"en_EN",
"en_US",
"eo",
"es",
"et",
"eu",
"fi",
"fr",
"gl",
"he",
"hi",
"hu",
"id",
"is",
"it",
"ja",
"kab",
"ko",
"lo",
"lt",
"lv",
"nb_NO",
"nl",
"nn",
"pl",
"pt",
"pt_BR",
"ru",
"sk",
"sq",
"sr",
"sv",
"te",
"th",
"tr",
"uk",
"vi",
"vls",
"zh_Hans",
"zh_Hant",
];

// cpx includes globbed parts of the filename in the destination, but excludes
Expand Down Expand Up @@ -185,12 +183,12 @@ function genLangFile(lang, dest) {
function genLangList(langFileMap) {
const languages = {};
INCLUDE_LANGS.forEach(function (lang) {
const normalizedLanguage = lang.value.toLowerCase().replace("_", "-");
const normalizedLanguage = lang.toLowerCase().replace("_", "-");
const languageParts = normalizedLanguage.split("-");
if (languageParts.length == 2 && languageParts[0] == languageParts[1]) {
languages[languageParts[0]] = { fileName: langFileMap[lang.value], label: lang.label };
languages[languageParts[0]] = langFileMap[lang];
} else {
languages[normalizedLanguage] = { fileName: langFileMap[lang.value], label: lang.label };
languages[normalizedLanguage] = langFileMap[lang];
}
});
fs.writeFile("webapp/i18n/languages.json", JSON.stringify(languages, null, 4), function (err) {
Expand All @@ -204,11 +202,11 @@ function genLangList(langFileMap) {
}
}

/**
watch the input files for a given language,
regenerate the file, adding its content-hashed filename to langFileMap
and regenerating languages.json with the new filename
*/
/*
* watch the input files for a given language,
* regenerate the file, adding its content-hashed filename to langFileMap
* and regenerating languages.json with the new filename
*/
function watchLanguage(lang, dest, langFileMap) {
const reactSdkFile = "node_modules/matrix-react-sdk/src/i18n/strings/" + lang + ".json";
const riotWebFile = "src/i18n/strings/" + lang + ".json";
Expand Down Expand Up @@ -236,8 +234,8 @@ function watchLanguage(lang, dest, langFileMap) {
// language resources
const I18N_DEST = "webapp/i18n/";
const I18N_FILENAME_MAP = INCLUDE_LANGS.reduce((m, l) => {
const filename = genLangFile(l.value, I18N_DEST);
m[l.value] = filename;
const filename = genLangFile(l, I18N_DEST);
m[l] = filename;
return m;
}, {});
genLangList(I18N_FILENAME_MAP);
Expand Down
Loading