Skip to content

Commit 86c563c

Browse files
authored
Simplify languages.json file and grab language names from Intl (#26001)
1 parent c13816d commit 86c563c

File tree

1 file changed

+59
-61
lines changed

1 file changed

+59
-61
lines changed

scripts/copy-res.js

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,56 @@ const loaderUtils = require("loader-utils");
55
// copies the resources into the webapp directory.
66
//
77

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

6260
// cpx includes globbed parts of the filename in the destination, but excludes
@@ -185,12 +183,12 @@ function genLangFile(lang, dest) {
185183
function genLangList(langFileMap) {
186184
const languages = {};
187185
INCLUDE_LANGS.forEach(function (lang) {
188-
const normalizedLanguage = lang.value.toLowerCase().replace("_", "-");
186+
const normalizedLanguage = lang.toLowerCase().replace("_", "-");
189187
const languageParts = normalizedLanguage.split("-");
190188
if (languageParts.length == 2 && languageParts[0] == languageParts[1]) {
191-
languages[languageParts[0]] = { fileName: langFileMap[lang.value], label: lang.label };
189+
languages[languageParts[0]] = langFileMap[lang];
192190
} else {
193-
languages[normalizedLanguage] = { fileName: langFileMap[lang.value], label: lang.label };
191+
languages[normalizedLanguage] = langFileMap[lang];
194192
}
195193
});
196194
fs.writeFile("webapp/i18n/languages.json", JSON.stringify(languages, null, 4), function (err) {
@@ -204,11 +202,11 @@ function genLangList(langFileMap) {
204202
}
205203
}
206204

207-
/**
208-
watch the input files for a given language,
209-
regenerate the file, adding its content-hashed filename to langFileMap
210-
and regenerating languages.json with the new filename
211-
*/
205+
/*
206+
* watch the input files for a given language,
207+
* regenerate the file, adding its content-hashed filename to langFileMap
208+
* and regenerating languages.json with the new filename
209+
*/
212210
function watchLanguage(lang, dest, langFileMap) {
213211
const reactSdkFile = "node_modules/matrix-react-sdk/src/i18n/strings/" + lang + ".json";
214212
const riotWebFile = "src/i18n/strings/" + lang + ".json";
@@ -236,8 +234,8 @@ function watchLanguage(lang, dest, langFileMap) {
236234
// language resources
237235
const I18N_DEST = "webapp/i18n/";
238236
const I18N_FILENAME_MAP = INCLUDE_LANGS.reduce((m, l) => {
239-
const filename = genLangFile(l.value, I18N_DEST);
240-
m[l.value] = filename;
237+
const filename = genLangFile(l, I18N_DEST);
238+
m[l] = filename;
241239
return m;
242240
}, {});
243241
genLangList(I18N_FILENAME_MAP);

0 commit comments

Comments
 (0)