Move to smartling for translation services

This commit is contained in:
Scott Nonnenberg 2022-09-27 14:01:06 -07:00 committed by GitHub
parent 620067342a
commit 5957c111cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
73 changed files with 1394 additions and 64465 deletions

View file

@ -1,76 +1,36 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { join, resolve } from 'path';
import { existsSync, readdirSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';
import { readJsonSync } from 'fs-extra';
import type { LocaleMessagesType } from '../types/I18N';
import * as Errors from '../types/errors';
const { SMARTLING_USER, SMARTLING_SECRET } = process.env;
console.log('Getting latest strings!');
// Note: we continue after tx failures so we always restore placeholders on json files
let failed = false;
console.log();
console.log('Getting strings, allow for new ones over 80% translated');
try {
execSync('tx pull --all --use-git-timestamps --minimum-perc=80', {
stdio: [null, process.stdout, process.stderr],
});
} catch (error: unknown) {
failed = true;
console.log(
'Failed first tx fetch, continuing...',
Errors.toLogFormat(error)
);
if (!SMARTLING_USER) {
console.error('Need to set SMARTLING_USER environment variable!');
process.exit(1);
}
if (!SMARTLING_SECRET) {
console.error('Need to set SMARTLING_SECRET environment variable!');
process.exit(1);
}
console.log('Fetching latest strings!');
console.log();
console.log('Getting strings, updating everything previously missed');
try {
execSync('tx pull --use-git-timestamps', {
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],
});
} catch (error: unknown) {
failed = true;
console.log(
'Failed second tx fetch, continuing...',
Errors.toLogFormat(error)
);
}
const BASE_DIR = join(__dirname, '../../_locales');
const locales = readdirSync(join(BASE_DIR, ''));
console.log();
console.log('Deleting placeholders for all locales');
locales.forEach((locale: string) => {
const target = resolve(join(BASE_DIR, locale, 'messages.json'));
if (!existsSync(target)) {
console.warn(`File not found for ${locale}: ${target}`);
return;
}
);
const messages: LocaleMessagesType = readJsonSync(target);
Object.keys(messages).forEach(key => {
delete messages[key].placeholders;
if (!messages[key].description) {
delete messages[key].description;
}
});
console.log(`Writing ${target}`);
writeFileSync(target, `${JSON.stringify(messages, null, 4)}\n`);
});
console.log('Formatting newly-downloaded strings!');
console.log();
execSync('yarn format', {
stdio: [null, process.stdout, process.stderr],
});
if (failed) {
process.exit(1);
}