fix(strings): Sequentially fetch built strings to avoid server rejecting connections (#4247)

Fix Bug 1476086 - Stop importing locales not explicitly in CENTRAL_LOCALES, e.g., "pbb"
This commit is contained in:
Ed Lee 2018-07-16 13:19:45 -07:00 коммит произвёл GitHub
Родитель 05f0199da8
Коммит d2965234a4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 132 добавлений и 118 удалений

111
bin/locales.js Normal file
Просмотреть файл

@ -0,0 +1,111 @@
exports.DEFAULT_LOCALE = "en-US";
// This locales list is to find any similar locales that we can reuse strings
// instead of falling back to the default, e.g., use bn-BD strings for bn-IN.
// https://hg.mozilla.org/mozilla-central/file/tip/browser/locales/l10n.toml
exports.CENTRAL_LOCALES = [
"ach",
"af",
"an",
"ar",
"as",
"ast",
"az",
"be",
"bg",
"bn-BD",
"bn-IN",
"br",
"bs",
"ca",
"cak",
"crh",
"cs",
"cy",
"da",
"de",
"dsb",
"el",
"en-CA",
"en-GB",
"en-ZA",
"eo",
"es-AR",
"es-CL",
"es-ES",
"es-MX",
"et",
"eu",
"fa",
"ff",
"fi",
"fr",
"fy-NL",
"ga-IE",
"gd",
"gl",
"gn",
"gu-IN",
"he",
"hi-IN",
"hr",
"hsb",
"hu",
"hy-AM",
"ia",
"id",
"is",
"it",
"ja",
"ja-JP-mac",
"ka",
"kab",
"kk",
"km",
"kn",
"ko",
"lij",
"lo",
"lt",
"ltg",
"lv",
"mai",
"mk",
"ml",
"mr",
"ms",
"my",
"nb-NO",
"ne-NP",
"nl",
"nn-NO",
"oc",
"or",
"pa-IN",
"pl",
"pt-BR",
"pt-PT",
"rm",
"ro",
"ru",
"si",
"sk",
"sl",
"son",
"sq",
"sr",
"sv-SE",
"ta",
"te",
"th",
"tl",
"tr",
"uk",
"ur",
"uz",
"vi",
"wo",
"xh",
"zh-CN",
"zh-TW"
];

Просмотреть файл

@ -6,7 +6,7 @@ const path = require("path");
// Note: this file is generated by webpack from content-src/activity-stream-prerender.jsx
const {prerender} = require("./prerender");
const DEFAULT_LOCALE = "en-US";
const {CENTRAL_LOCALES, DEFAULT_LOCALE} = require("./locales");
// Note: DEFAULT_OPTIONS.baseUrl should match BASE_URL in aboutNewTabService.js
// in mozilla-central.
@ -15,116 +15,6 @@ const DEFAULT_OPTIONS = {
baseUrl: "resource://activity-stream/"
};
// This locales list is to find any similar locales that we can reuse strings
// instead of falling back to the default, e.g., use bn-BD strings for bn-IN.
// https://hg.mozilla.org/mozilla-central/file/tip/browser/locales/l10n.toml
const CENTRAL_LOCALES = [
"ach",
"af",
"an",
"ar",
"as",
"ast",
"az",
"be",
"bg",
"bn-BD",
"bn-IN",
"br",
"bs",
"ca",
"cak",
"crh",
"cs",
"cy",
"da",
"de",
"dsb",
"el",
"en-CA",
"en-GB",
"en-ZA",
"eo",
"es-AR",
"es-CL",
"es-ES",
"es-MX",
"et",
"eu",
"fa",
"ff",
"fi",
"fr",
"fy-NL",
"ga-IE",
"gd",
"gl",
"gn",
"gu-IN",
"he",
"hi-IN",
"hr",
"hsb",
"hu",
"hy-AM",
"ia",
"id",
"is",
"it",
"ja",
"ja-JP-mac",
"ka",
"kab",
"kk",
"km",
"kn",
"ko",
"lij",
"lo",
"lt",
"ltg",
"lv",
"mai",
"mk",
"ml",
"mr",
"ms",
"my",
"nb-NO",
"ne-NP",
"nl",
"nn-NO",
"oc",
"or",
"pa-IN",
"pl",
"pt-BR",
"pt-PT",
"rm",
"ro",
"ru",
"si",
"sk",
"sl",
"son",
"sq",
"sr",
"sv-SE",
"ta",
"te",
"th",
"tl",
"tr",
"uk",
"ur",
"uz",
"vi",
"wo",
"xh",
"zh-CN",
"zh-TW"
];
// Locales that should be displayed RTL
const RTL_LIST = ["ar", "he", "fa", "ur"];

Просмотреть файл

@ -7,7 +7,7 @@ const fetch = require("node-fetch");
/* globals cd, ls, mkdir, rm, ShellString */
require("shelljs/global");
const DEFAULT_LOCALE = "en-US";
const {CENTRAL_LOCALES, DEFAULT_LOCALE} = require("./locales");
const L10N_CENTRAL = "https://hg.mozilla.org/l10n-central";
const PROPERTIES_PATH = "raw-file/default/browser/chrome/browser/activity-stream/newtab.properties";
const STRINGS_FILE = "strings.properties";
@ -16,16 +16,21 @@ const STRINGS_FILE = "strings.properties";
async function getLocales() {
console.log(`Getting locales from ${L10N_CENTRAL}`);
// Add all non-test sub repository locales
// Add sub repository locales that mozilla-central builds
const locales = [];
const unbuilt = [];
const subrepos = await (await fetch(`${L10N_CENTRAL}?style=json`)).json();
subrepos.entries.forEach(({name}) => {
if (name !== "x-testing") {
if (CENTRAL_LOCALES.includes(name)) {
locales.push(name);
} else {
unbuilt.push(name);
}
});
console.log(`Got ${locales.length} locales: ${locales}`);
console.log(`Got ${locales.length} mozilla-central locales: ${locales}`);
console.log(`Skipped ${unbuilt.length} unbuilt locales: ${unbuilt}`);
return locales;
}
@ -62,9 +67,17 @@ async function updateLocales() {
}
});
// Save the properties file for each locale in parallel
const locales = await getLocales();
const missing = (await Promise.all(locales.map(saveProperties))).filter(v => v);
// Save the properties file for each locale one at a time to avoid too many
// parallel connections (resulting in ECONNRESET / socket hang up)
const missing = [];
for (const locale of await getLocales()) {
process.stdout.write(`${locale} `);
if (await saveProperties(locale)) {
missing.push(locale);
}
}
console.log("");
console.log(`Skipped ${missing.length} locales without strings: ${missing.sort()}`);
console.log(`