123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #! /usr/bin/env node
- "use strict";
- const fetch = require("node-fetch");
- require("shelljs/global");
- const {CENTRAL_LOCALES, DEFAULT_LOCALE, LOCALES_SOURCE_DIRECTORY} = 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";
- async function getLocales() {
- console.log(`Getting locales from ${L10N_CENTRAL}`);
-
- const locales = [];
- const unbuilt = [];
- const subrepos = await (await fetch(`${L10N_CENTRAL}?style=json`)).json();
- subrepos.entries.forEach(({name}) => {
- if (CENTRAL_LOCALES.includes(name)) {
- locales.push(name);
- } else {
- unbuilt.push(name);
- }
- });
- console.log(`Got ${locales.length} mozilla-central locales: ${locales}`);
- console.log(`Skipped ${unbuilt.length} unbuilt locales: ${unbuilt}`);
- return locales;
- }
- const transvision = {};
- async function cherryPickString(locale) {
- const getTransvision = async string => {
- if (!transvision[string]) {
- const response = await fetch(`https://transvision.mozfr.org/api/v1/entity/gecko_strings/?id=${string}`);
- transvision[string] = response.ok ? await response.json() : {};
- }
- return transvision[string];
- };
- const expectedKey = "section_menu_action_add_search_engine";
- const expected = await getTransvision(`browser/chrome/browser/activity-stream/newtab.properties:${expectedKey}`);
- const target = await getTransvision("browser/chrome/browser/search.properties:searchAddFoundEngine2");
- return !expected[locale] && target[locale] ? `${expectedKey}=${target[locale]}\n` : "";
- }
- async function saveProperties(locale) {
-
- const url = `${L10N_CENTRAL}/${locale}/${PROPERTIES_PATH}`;
- const response = await fetch(url);
- if (!response.ok) {
-
- return locale;
- }
-
- const text = await response.text();
- mkdir(locale);
- cd(locale);
-
- ShellString(text + await cherryPickString(locale)).to(STRINGS_FILE);
- cd("..");
-
- return "";
- }
- async function updateLocales() {
- console.log(`Switching to and deleting existing l10n tree under: ${LOCALES_SOURCE_DIRECTORY}`);
- cd(LOCALES_SOURCE_DIRECTORY);
- ls().forEach(dir => {
-
- if (dir !== DEFAULT_LOCALE) {
- rm("-r", dir);
- }
- });
-
-
- 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(`
- Please check the diffs, add/remove files, and then commit the result. Suggested commit message:
- chore(l10n): Update from l10n-central ${new Date()}`);
- }
- updateLocales().catch(console.error);
|