2021-12-14 16:43:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { execSync } from 'child_process';
|
2023-04-17 19:26:57 +00:00
|
|
|
import fsExtra from 'fs-extra';
|
|
|
|
import path from 'path';
|
2023-05-17 17:19:27 +00:00
|
|
|
import fastGlob from 'fast-glob';
|
2021-12-14 16:43:46 +00:00
|
|
|
|
2022-09-27 21:01:06 +00:00
|
|
|
const { SMARTLING_USER, SMARTLING_SECRET } = process.env;
|
2021-12-14 16:43:46 +00:00
|
|
|
|
2022-09-27 21:01:06 +00:00
|
|
|
if (!SMARTLING_USER) {
|
|
|
|
console.error('Need to set SMARTLING_USER environment variable!');
|
|
|
|
process.exit(1);
|
2022-08-03 21:27:34 +00:00
|
|
|
}
|
2022-09-27 21:01:06 +00:00
|
|
|
if (!SMARTLING_SECRET) {
|
|
|
|
console.error('Need to set SMARTLING_SECRET environment variable!');
|
|
|
|
process.exit(1);
|
2022-08-03 21:27:34 +00:00
|
|
|
}
|
2021-12-14 16:43:46 +00:00
|
|
|
|
2023-05-17 17:19:27 +00:00
|
|
|
console.log('Cleaning _locales directory...');
|
|
|
|
const dirEntries = fastGlob.sync(['_locales/*', '!_locales/en'], {
|
|
|
|
onlyDirectories: true,
|
|
|
|
absolute: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const dirEntry of dirEntries) {
|
|
|
|
fsExtra.rmdirSync(dirEntry, { recursive: true });
|
|
|
|
}
|
|
|
|
|
2022-09-27 21:01:06 +00:00
|
|
|
console.log('Fetching latest strings!');
|
2021-12-14 16:43:46 +00:00
|
|
|
console.log();
|
2022-09-27 21:01:06 +00:00
|
|
|
execSync(
|
|
|
|
'smartling-cli' +
|
|
|
|
` --user "${SMARTLING_USER}"` +
|
|
|
|
` --secret "${SMARTLING_SECRET}"` +
|
|
|
|
' --config .smartling.yml' +
|
|
|
|
' --verbose' +
|
|
|
|
' --format "_locales/{{.Locale}}/messages.json"' +
|
|
|
|
' files pull',
|
|
|
|
{
|
|
|
|
stdio: [null, process.stdout, process.stderr],
|
2021-12-14 16:43:46 +00:00
|
|
|
}
|
2022-09-27 21:01:06 +00:00
|
|
|
);
|
2021-12-14 16:43:46 +00:00
|
|
|
|
2023-04-17 19:26:57 +00:00
|
|
|
function rename(from: string, to: string) {
|
|
|
|
console.log(`Renaming "${from}" to "${to}"`);
|
|
|
|
fsExtra.moveSync(path.join('_locales', from), path.join('_locales', to), {
|
|
|
|
overwrite: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Smartling uses "zh-YU" for Cantonese (or Yue Chinese).
|
|
|
|
// This is wrong.
|
|
|
|
// The language tag for Yue Chinese is "yue"
|
|
|
|
// "zh-YU" actually implies "Chinese as spoken in Yugoslavia (canonicalized to Serbia)"
|
|
|
|
rename('zh-YU', 'yue');
|
|
|
|
|
2023-05-04 23:50:14 +00:00
|
|
|
// For most of the Chinese-speaking world, where we don't have a region specific
|
|
|
|
// locale available (e.g. zh-HK), zh-TW is a suitable choice for "Traditional Chinese".
|
|
|
|
//
|
|
|
|
// However, Intl.LocaleMatcher won't match "zh-Hant-XX" to "zh-TW",
|
|
|
|
// we need to rename it to "zh-Hant" explicitly to make it work.
|
|
|
|
rename('zh-TW', 'zh-Hant');
|
|
|
|
|
2023-05-17 17:19:27 +00:00
|
|
|
// "YR" is not a valid region subtag. Smartling made it up.
|
|
|
|
rename('sr-YR', 'sr');
|
|
|
|
|
2022-09-27 21:01:06 +00:00
|
|
|
console.log('Formatting newly-downloaded strings!');
|
|
|
|
console.log();
|
2022-09-01 03:42:18 +00:00
|
|
|
execSync('yarn format', {
|
|
|
|
stdio: [null, process.stdout, process.stderr],
|
|
|
|
});
|