2019-07-30 09:35:42 +02:00
|
|
|
'use strict';
|
2017-07-17 22:26:19 +02:00
|
|
|
|
2019-06-05 19:07:11 +02:00
|
|
|
// Dependencies:
|
|
|
|
//
|
2020-11-19 15:03:40 +02:00
|
|
|
// sudo apt install gettext sudo apt install translate-toolkit
|
|
|
|
//
|
|
|
|
// gettext v21+ is required as versions before that have bugs when parsing
|
|
|
|
// JavaScript template strings which means we would lose translations.
|
2019-06-05 19:07:11 +02:00
|
|
|
|
2020-11-05 18:58:23 +02:00
|
|
|
const rootDir = `${__dirname}/../..`;
|
2018-02-01 22:15:31 +02:00
|
|
|
|
2020-11-07 17:59:37 +02:00
|
|
|
const markdownUtils = require('@joplin/lib/markdownUtils').default;
|
2017-11-03 02:09:34 +02:00
|
|
|
const fs = require('fs-extra');
|
2022-11-22 20:16:57 +02:00
|
|
|
const { translationExecutablePath, removePoHeaderDate, mergePotToPo, parsePoFile, parseTranslations } = require('./utils/translation');
|
2020-11-05 18:58:23 +02:00
|
|
|
const localesDir = `${__dirname}/locales`;
|
|
|
|
const libDir = `${rootDir}/packages/lib`;
|
2021-11-07 17:41:04 +02:00
|
|
|
const { execCommand, isMac, insertContentIntoFile, filename, dirname, fileExtension } = require('./tool-utils.js');
|
2020-11-07 17:59:37 +02:00
|
|
|
const { countryDisplayName, countryCodeOnly } = require('@joplin/lib/locale');
|
2017-07-17 22:26:19 +02:00
|
|
|
|
2021-11-09 14:20:07 +02:00
|
|
|
const { GettextExtractor, JsExtractors } = require('gettext-extractor');
|
|
|
|
|
2017-07-17 22:26:19 +02:00
|
|
|
function serializeTranslation(translation) {
|
2022-11-22 20:16:57 +02:00
|
|
|
const output = parseTranslations(translation);
|
2021-11-09 15:14:41 +02:00
|
|
|
return JSON.stringify(output, Object.keys(output).sort((a, b) => a.toLowerCase() < b.toLowerCase() ? -1 : +1), ' ');
|
2017-07-17 22:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveToFile(filePath, data) {
|
|
|
|
fs.writeFileSync(filePath, data);
|
|
|
|
}
|
|
|
|
|
2022-11-22 20:16:57 +02:00
|
|
|
async function buildLocale(inputFile, outputFile) {
|
|
|
|
const r = await parsePoFile(inputFile);
|
2017-07-17 22:26:19 +02:00
|
|
|
const translation = serializeTranslation(r);
|
|
|
|
saveToFile(outputFile, translation);
|
|
|
|
}
|
|
|
|
|
2020-06-02 21:33:08 +02:00
|
|
|
async function createPotFile(potFilePath) {
|
|
|
|
const excludedDirs = [
|
|
|
|
'./.git/*',
|
|
|
|
'./.github/*',
|
2020-11-05 18:58:23 +02:00
|
|
|
'./**/node_modules/*',
|
2020-06-02 21:33:08 +02:00
|
|
|
'./Assets/*',
|
2020-11-05 18:58:23 +02:00
|
|
|
'./Assets/TinyMCE/*',
|
2021-07-28 14:25:49 +02:00
|
|
|
'./docs/*',
|
2020-06-02 21:33:08 +02:00
|
|
|
'./node_modules/*',
|
2020-11-05 18:58:23 +02:00
|
|
|
'./packages/app-cli/build/*',
|
|
|
|
'./packages/app-cli/locales-build/*',
|
|
|
|
'./packages/app-cli/locales/*',
|
|
|
|
'./packages/app-cli/tests-build/*',
|
|
|
|
'./packages/app-cli/tests/*',
|
|
|
|
'./packages/app-clipper/*',
|
2021-12-21 19:10:59 +02:00
|
|
|
'./packages/app-desktop/build/*',
|
2020-11-05 18:58:23 +02:00
|
|
|
'./packages/app-desktop/dist/*',
|
|
|
|
'./packages/app-desktop/gui/note-viewer/pluginAssets/*',
|
|
|
|
'./packages/app-desktop/gui/style/*',
|
|
|
|
'./packages/app-desktop/lib/*',
|
|
|
|
'./packages/app-desktop/pluginAssets/*',
|
|
|
|
'./packages/app-desktop/tools/*',
|
2022-01-15 19:16:04 +02:00
|
|
|
'./packages/app-desktop/vendor/*',
|
2020-11-05 18:58:23 +02:00
|
|
|
'./packages/app-mobile/android/*',
|
|
|
|
'./packages/app-mobile/ios/*',
|
|
|
|
'./packages/app-mobile/pluginAssets/*',
|
|
|
|
'./packages/app-mobile/tools/*',
|
2021-07-28 14:25:49 +02:00
|
|
|
'./packages/fork-*/*',
|
|
|
|
'./packages/lib/rnInjectedJs/*',
|
|
|
|
'./packages/lib/vendor/*',
|
2020-11-05 18:58:23 +02:00
|
|
|
'./packages/renderer/assets/*',
|
2021-12-21 19:10:59 +02:00
|
|
|
'./packages/server/dist/*',
|
2020-11-05 18:58:23 +02:00
|
|
|
'./packages/tools/*',
|
2021-07-28 14:25:49 +02:00
|
|
|
'./packages/turndown-plugin-gfm/*',
|
|
|
|
'./packages/turndown/*',
|
2020-06-02 21:33:08 +02:00
|
|
|
'./patches/*',
|
|
|
|
'./readme/*',
|
|
|
|
];
|
|
|
|
|
2021-11-09 14:20:07 +02:00
|
|
|
const findCommand = `find . -type f \\( -iname \\*.js -o -iname \\*.ts -o -iname \\*.tsx \\) -not -path '${excludedDirs.join('\' -not -path \'')}'`;
|
2020-11-05 18:58:23 +02:00
|
|
|
process.chdir(rootDir);
|
2021-07-28 14:25:49 +02:00
|
|
|
let files = (await execCommand(findCommand)).split('\n');
|
|
|
|
|
2021-12-21 19:10:59 +02:00
|
|
|
// Further filter files - in particular remove some specific files and
|
|
|
|
// extensions we don't need. Also, when there's two file with the same
|
|
|
|
// basename, such as "exmaple.js", and "example.ts", we only keep the file
|
|
|
|
// with ".ts" extension (since the .js should be the compiled file).
|
|
|
|
|
2021-11-07 17:41:04 +02:00
|
|
|
const toProcess = {};
|
|
|
|
|
|
|
|
for (const file of files) {
|
|
|
|
if (!file) continue;
|
|
|
|
|
|
|
|
const nameNoExt = `${dirname(file)}/${filename(file)}`;
|
|
|
|
|
|
|
|
if (nameNoExt.endsWith('CodeMirror.bundle.min')) continue;
|
|
|
|
if (nameNoExt.endsWith('CodeMirror.bundle')) continue;
|
|
|
|
if (nameNoExt.endsWith('.test')) continue;
|
|
|
|
if (nameNoExt.endsWith('.eslintrc')) continue;
|
|
|
|
if (nameNoExt.endsWith('jest.config')) continue;
|
|
|
|
if (nameNoExt.endsWith('jest.setup')) continue;
|
2021-12-21 19:10:59 +02:00
|
|
|
if (nameNoExt.endsWith('webpack.config')) continue;
|
|
|
|
if (nameNoExt.endsWith('.prettierrc')) continue;
|
|
|
|
if (file.endsWith('.d.ts')) continue;
|
2021-11-07 17:41:04 +02:00
|
|
|
|
|
|
|
if (toProcess[nameNoExt] && ['ts', 'tsx'].includes(fileExtension(toProcess[nameNoExt]))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
toProcess[nameNoExt] = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
files = [];
|
|
|
|
for (const key of Object.keys(toProcess)) {
|
|
|
|
files.push(toProcess[key]);
|
|
|
|
}
|
2021-07-28 14:25:49 +02:00
|
|
|
|
|
|
|
files.sort();
|
|
|
|
|
2021-12-21 19:10:59 +02:00
|
|
|
// console.info(files.join('\n'));
|
|
|
|
// process.exit(0);
|
|
|
|
|
2021-11-09 14:20:07 +02:00
|
|
|
// Note: we previously used the xgettext utility, but it only partially
|
|
|
|
// supports TypeScript and doesn't support .tsx files at all. Besides; the
|
|
|
|
// TypeScript compiler now converts some `_('some string')` calls to
|
|
|
|
// `(0,locale1._)('some string')`, which cannot be detected by xgettext.
|
|
|
|
//
|
|
|
|
// So now we use this gettext-extractor utility, which seems to do the job.
|
|
|
|
// It supports .ts and .tsx files and appears to find the same strings as
|
|
|
|
// xgettext.
|
|
|
|
|
|
|
|
const extractor = new GettextExtractor();
|
|
|
|
|
2021-11-09 17:26:45 +02:00
|
|
|
// In the following string:
|
|
|
|
//
|
|
|
|
// _('Hello %s', 'Scott')
|
|
|
|
//
|
|
|
|
// "Hello %s" is the `text` (or "msgstr" in gettext parlance) , and "Scott"
|
|
|
|
// is the `context` ("msgctxt").
|
|
|
|
//
|
|
|
|
// gettext-extractor allows adding both the text and context to the pot
|
|
|
|
// file, however we should avoid this because a change in the context string
|
|
|
|
// would mark the associated string as fuzzy. We want to avoid this because
|
|
|
|
// the point of splitting into text and context is that even if the context
|
|
|
|
// changes we don't need to retranslate the text. We use this for URLs for
|
|
|
|
// instance.
|
|
|
|
//
|
|
|
|
// Because of this, below we don't set the "context" property.
|
|
|
|
|
2021-11-09 14:20:07 +02:00
|
|
|
const parser = extractor
|
|
|
|
.createJsParser([
|
|
|
|
JsExtractors.callExpression('_', {
|
|
|
|
arguments: {
|
|
|
|
text: 0,
|
2021-11-09 17:26:45 +02:00
|
|
|
// context: 1,
|
2021-11-09 14:20:07 +02:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
JsExtractors.callExpression('_n', {
|
|
|
|
arguments: {
|
|
|
|
text: 0,
|
|
|
|
textPlural: 1,
|
2021-11-09 17:26:45 +02:00
|
|
|
// context: 2,
|
2021-11-09 14:20:07 +02:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
|
|
|
|
for (const file of files) {
|
|
|
|
parser.parseFile(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
extractor.savePotFile(potFilePath, {
|
|
|
|
'Project-Id-Version': 'Joplin',
|
|
|
|
'Content-Type': 'text/plain; charset=UTF-8',
|
|
|
|
});
|
|
|
|
|
2020-06-02 21:33:08 +02:00
|
|
|
await removePoHeaderDate(potFilePath);
|
2017-07-18 20:04:47 +02:00
|
|
|
}
|
|
|
|
|
2019-07-29 11:47:50 +02:00
|
|
|
function buildIndex(locales, stats) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const output = [];
|
2017-07-19 23:26:30 +02:00
|
|
|
output.push('var locales = {};');
|
2019-07-29 11:47:50 +02:00
|
|
|
output.push('var stats = {};');
|
|
|
|
|
2017-07-19 23:26:30 +02:00
|
|
|
for (let i = 0; i < locales.length; i++) {
|
|
|
|
const locale = locales[i];
|
2019-09-19 23:51:18 +02:00
|
|
|
output.push(`locales['${locale}'] = require('./${locale}.json');`);
|
2017-07-19 23:26:30 +02:00
|
|
|
}
|
2019-07-29 11:47:50 +02:00
|
|
|
|
|
|
|
for (let i = 0; i < stats.length; i++) {
|
2023-06-01 13:02:36 +02:00
|
|
|
const stat = { ...stats[i] };
|
2019-07-29 11:47:50 +02:00
|
|
|
const locale = stat.locale;
|
|
|
|
delete stat.locale;
|
|
|
|
delete stat.translatorName;
|
|
|
|
delete stat.languageName;
|
2019-11-29 20:51:55 +02:00
|
|
|
delete stat.untranslatedCount;
|
2019-09-19 23:51:18 +02:00
|
|
|
output.push(`stats['${locale}'] = ${JSON.stringify(stat)};`);
|
2019-07-29 11:47:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
output.push('module.exports = { locales: locales, stats: stats };');
|
2019-07-30 09:35:42 +02:00
|
|
|
return output.join('\n');
|
2017-07-19 23:26:30 +02:00
|
|
|
}
|
|
|
|
|
2017-11-30 20:29:10 +02:00
|
|
|
function availableLocales(defaultLocale) {
|
|
|
|
const output = [defaultLocale];
|
2023-06-30 10:39:21 +02:00
|
|
|
// eslint-disable-next-line github/array-foreach -- Old code before rule was applied
|
2020-11-05 18:58:23 +02:00
|
|
|
fs.readdirSync(localesDir).forEach((path) => {
|
2017-11-30 20:29:10 +02:00
|
|
|
if (fileExtension(path) !== 'po') return;
|
|
|
|
const locale = filename(path);
|
|
|
|
if (locale === defaultLocale) return;
|
|
|
|
output.push(locale);
|
|
|
|
});
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2018-02-10 15:03:01 +02:00
|
|
|
function extractTranslator(regex, poContent) {
|
|
|
|
const translatorMatch = poContent.match(regex);
|
|
|
|
let translatorName = '';
|
2019-07-30 09:35:42 +02:00
|
|
|
|
2018-02-10 15:03:01 +02:00
|
|
|
if (translatorMatch && translatorMatch.length >= 1) {
|
|
|
|
translatorName = translatorMatch[1];
|
|
|
|
translatorName = translatorName.replace(/["\s]+$/, '');
|
|
|
|
translatorName = translatorName.replace(/\\n$/, '');
|
|
|
|
translatorName = translatorName.replace(/^\s*/, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (translatorName.indexOf('FULL NAME') >= 0) return '';
|
|
|
|
if (translatorName.indexOf('LL@li.org') >= 0) return '';
|
|
|
|
|
|
|
|
return translatorName;
|
|
|
|
}
|
|
|
|
|
2020-10-21 22:53:41 +02:00
|
|
|
function translatorNameToMarkdown(translatorName) {
|
|
|
|
const matches = translatorName.match(/^(.*?)\s*\((.*)\)$/);
|
|
|
|
if (!matches) return translatorName;
|
|
|
|
return `[${markdownUtils.escapeTitleText(matches[1])}](mailto:${markdownUtils.escapeLinkUrl(matches[2])})`;
|
|
|
|
}
|
|
|
|
|
2018-02-01 22:15:31 +02:00
|
|
|
async function translationStatus(isDefault, poFile) {
|
|
|
|
// "apt install translate-toolkit" to have pocount
|
2019-08-29 18:34:05 +02:00
|
|
|
let pocountPath = 'pocount';
|
2022-11-22 20:16:57 +02:00
|
|
|
if (isMac()) pocountPath = translationExecutablePath('pocount');
|
2019-08-29 18:34:05 +02:00
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
const command = `${pocountPath} "${poFile}"`;
|
2018-02-01 22:15:31 +02:00
|
|
|
const result = await execCommand(command);
|
2019-02-14 00:52:32 +02:00
|
|
|
const matches = result.match(/Translated:\s*?(\d+)\s*\((.+?)%\)/);
|
2019-09-19 23:51:18 +02:00
|
|
|
if (!matches || matches.length < 3) throw new Error(`Cannot extract status: ${command}:\n${result}`);
|
2018-02-01 22:15:31 +02:00
|
|
|
const percentDone = Number(matches[2]);
|
2019-09-19 23:51:18 +02:00
|
|
|
if (isNaN(percentDone)) throw new Error(`Cannot extract percent translated: ${command}:\n${result}`);
|
2018-02-01 22:15:31 +02:00
|
|
|
|
2019-11-28 20:27:38 +02:00
|
|
|
const untranslatedMatches = result.match(/Untranslated:\s*?(\d+)/);
|
|
|
|
if (!untranslatedMatches) throw new Error(`Cannot extract untranslated: ${command}:\n${result}`);
|
|
|
|
const untranslatedCount = Number(untranslatedMatches[1]);
|
|
|
|
|
2018-02-01 22:15:31 +02:00
|
|
|
let translatorName = '';
|
|
|
|
const content = await fs.readFile(poFile, 'utf-8');
|
2018-02-10 15:03:01 +02:00
|
|
|
|
|
|
|
translatorName = extractTranslator(/Last-Translator:\s*?(.*)/, content);
|
|
|
|
if (!translatorName) {
|
|
|
|
translatorName = extractTranslator(/Language-Team:\s*?(.*)/, content);
|
2018-02-01 22:15:31 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 19:04:48 +02:00
|
|
|
// Remove <> around email otherwise it's converted to HTML with (apparently) non-deterministic
|
|
|
|
// encoding, so it changes on every update.
|
2018-05-09 18:06:02 +02:00
|
|
|
translatorName = translatorName.replace(/ </, ' (');
|
|
|
|
translatorName = translatorName.replace(/>/, ')');
|
|
|
|
|
2020-10-21 22:53:41 +02:00
|
|
|
// Some users have very long names and very long email addresses and in that case gettext
|
|
|
|
// records it over several lines, and here we only have the first line. So if we're having a broken
|
|
|
|
// email, add a closing ')' so that at least rendering works fine.
|
|
|
|
if (translatorName.indexOf('(') >= 0 && translatorName.indexOf(')') < 0) translatorName += ')';
|
|
|
|
|
|
|
|
translatorName = translatorNameToMarkdown(translatorName);
|
|
|
|
|
2019-11-28 20:27:38 +02:00
|
|
|
const isAlways100 = poFile.endsWith('en_US.po');
|
2019-04-26 19:36:12 +02:00
|
|
|
|
2018-02-01 22:15:31 +02:00
|
|
|
return {
|
2019-04-26 19:58:40 +02:00
|
|
|
percentDone: isDefault || isAlways100 ? 100 : percentDone,
|
2018-02-01 22:15:31 +02:00
|
|
|
translatorName: translatorName,
|
2019-11-28 20:27:38 +02:00
|
|
|
untranslatedCount: untranslatedCount,
|
2018-02-01 22:15:31 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-02-10 14:52:57 +02:00
|
|
|
function flagImageUrl(locale) {
|
2019-04-18 15:59:17 +02:00
|
|
|
const baseUrl = 'https://joplinapp.org/images/flags';
|
2019-09-19 23:51:18 +02:00
|
|
|
if (locale === 'ar') return `${baseUrl}/country-4x3/arableague.png`;
|
|
|
|
if (locale === 'eu') return `${baseUrl}/es/basque_country.png`;
|
|
|
|
if (locale === 'gl_ES') return `${baseUrl}/es/galicia.png`;
|
|
|
|
if (locale === 'ca') return `${baseUrl}/es/catalonia.png`;
|
|
|
|
if (locale === 'ko') return `${baseUrl}/country-4x3/kr.png`;
|
|
|
|
if (locale === 'sv') return `${baseUrl}/country-4x3/se.png`;
|
|
|
|
if (locale === 'nb_NO') return `${baseUrl}/country-4x3/no.png`;
|
|
|
|
if (locale === 'ro') return `${baseUrl}/country-4x3/ro.png`;
|
2022-01-12 19:21:25 +02:00
|
|
|
if (locale === 'vi') return `${baseUrl}/country-4x3/vn.png`;
|
2019-09-19 23:51:18 +02:00
|
|
|
if (locale === 'fa') return `${baseUrl}/country-4x3/ir.png`;
|
2019-11-18 10:55:23 +02:00
|
|
|
if (locale === 'eo') return `${baseUrl}/esperanto.png`;
|
2019-09-19 23:51:18 +02:00
|
|
|
return `${baseUrl}/country-4x3/${countryCodeOnly(locale).toLowerCase()}.png`;
|
2018-02-10 14:52:57 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 23:45:28 +02:00
|
|
|
function poFileUrl(locale) {
|
2020-11-08 21:13:42 +02:00
|
|
|
return `https://github.com/laurent22/joplin/blob/dev/packages/tools/locales/${locale}.po`;
|
2018-02-16 23:45:28 +02:00
|
|
|
}
|
|
|
|
|
2018-02-01 22:15:31 +02:00
|
|
|
function translationStatusToMdTable(status) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const output = [];
|
2018-02-16 23:45:28 +02:00
|
|
|
output.push([' ', 'Language', 'Po File', 'Last translator', 'Percent done'].join(' | '));
|
2018-02-01 22:21:54 +02:00
|
|
|
output.push(['---', '---', '---', '---', '---'].join('|'));
|
2018-02-01 22:15:31 +02:00
|
|
|
for (let i = 0; i < status.length; i++) {
|
|
|
|
const stat = status[i];
|
2018-02-16 23:45:28 +02:00
|
|
|
const flagUrl = flagImageUrl(stat.locale);
|
2021-05-27 15:49:29 +02:00
|
|
|
output.push([`<img src="${flagUrl}" width="16px"/>`, stat.languageName, `[${stat.locale}](${poFileUrl(stat.locale)})`, stat.translatorName, `${stat.percentDone}%`].join(' | '));
|
2018-02-01 22:15:31 +02:00
|
|
|
}
|
|
|
|
return output.join('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function updateReadmeWithStats(stats) {
|
2019-07-18 19:36:29 +02:00
|
|
|
await insertContentIntoFile(
|
2019-09-19 23:51:18 +02:00
|
|
|
`${rootDir}/README.md`,
|
2019-07-18 19:36:29 +02:00
|
|
|
'<!-- LOCALE-TABLE-AUTO-GENERATED -->\n',
|
|
|
|
'\n<!-- LOCALE-TABLE-AUTO-GENERATED -->',
|
|
|
|
translationStatusToMdTable(stats)
|
|
|
|
);
|
2018-02-01 22:15:31 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 19:19:38 +02:00
|
|
|
async function translationStrings(poFilePath) {
|
|
|
|
const r = await parsePoFile(poFilePath);
|
|
|
|
return Object.keys(r.translations['']);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deletedStrings(oldStrings, newStrings) {
|
|
|
|
const output = [];
|
|
|
|
for (const s1 of oldStrings) {
|
|
|
|
if (newStrings.includes(s1)) continue;
|
|
|
|
output.push(s1);
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2017-07-18 20:04:47 +02:00
|
|
|
async function main() {
|
2019-11-28 20:27:38 +02:00
|
|
|
const argv = require('yargs').argv;
|
|
|
|
|
2021-11-08 19:10:33 +02:00
|
|
|
const missingStringsCheckOnly = !!argv['missing-strings-check-only'];
|
|
|
|
|
|
|
|
let potFilePath = `${localesDir}/joplin.pot`;
|
|
|
|
|
|
|
|
let tempPotFilePath = '';
|
|
|
|
|
|
|
|
if (missingStringsCheckOnly) {
|
|
|
|
tempPotFilePath = `${localesDir}/joplin-temp-${Math.floor(Math.random() * 10000000)}.pot`;
|
|
|
|
await fs.copy(potFilePath, tempPotFilePath);
|
|
|
|
potFilePath = tempPotFilePath;
|
|
|
|
}
|
|
|
|
|
2020-11-05 18:58:23 +02:00
|
|
|
const jsonLocalesDir = `${libDir}/locales`;
|
2017-07-18 20:04:47 +02:00
|
|
|
const defaultLocale = 'en_GB';
|
|
|
|
|
2020-11-08 19:19:38 +02:00
|
|
|
const oldStrings = await translationStrings(potFilePath);
|
2019-11-28 20:27:38 +02:00
|
|
|
const oldPotStatus = await translationStatus(false, potFilePath);
|
|
|
|
|
2020-06-02 21:33:08 +02:00
|
|
|
await createPotFile(potFilePath);
|
2017-07-18 20:04:47 +02:00
|
|
|
|
2020-11-08 19:19:38 +02:00
|
|
|
const newStrings = await translationStrings(potFilePath);
|
2019-11-28 20:27:38 +02:00
|
|
|
const newPotStatus = await translationStatus(false, potFilePath);
|
|
|
|
|
|
|
|
console.info(`Updated pot file. Total strings: ${oldPotStatus.untranslatedCount} => ${newPotStatus.untranslatedCount}`);
|
|
|
|
|
2021-11-08 19:10:33 +02:00
|
|
|
if (tempPotFilePath) await fs.remove(tempPotFilePath);
|
|
|
|
|
2019-11-28 20:27:38 +02:00
|
|
|
const deletedCount = oldPotStatus.untranslatedCount - newPotStatus.untranslatedCount;
|
2020-11-08 19:19:38 +02:00
|
|
|
if (deletedCount >= 5) {
|
2019-11-28 20:27:38 +02:00
|
|
|
if (argv['skip-missing-strings-check']) {
|
|
|
|
console.info(`${deletedCount} strings have been deleted, but proceeding anyway due to --skip-missing-strings-check flag`);
|
|
|
|
} else {
|
2020-11-08 19:19:38 +02:00
|
|
|
const msg = [`${deletedCount} strings have been deleted - aborting as it could be a bug. To override, use the --skip-missing-strings-check flag.`];
|
|
|
|
msg.push('');
|
|
|
|
msg.push('Deleted strings:');
|
|
|
|
msg.push('');
|
|
|
|
msg.push(deletedStrings(oldStrings, newStrings).map(s => `"${s}"`).join('\n'));
|
|
|
|
throw new Error(msg.join('\n'));
|
2019-11-28 20:27:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-08 19:10:33 +02:00
|
|
|
if (missingStringsCheckOnly) return;
|
|
|
|
|
2020-11-05 18:58:23 +02:00
|
|
|
await execCommand(`cp "${potFilePath}" ` + `"${localesDir}/${defaultLocale}.po"`);
|
2017-07-18 20:04:47 +02:00
|
|
|
|
|
|
|
fs.mkdirpSync(jsonLocalesDir, 0o755);
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const stats = [];
|
2018-02-01 22:15:31 +02:00
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const locales = availableLocales(defaultLocale);
|
2017-07-18 20:04:47 +02:00
|
|
|
for (let i = 0; i < locales.length; i++) {
|
|
|
|
const locale = locales[i];
|
2018-12-06 00:30:30 +02:00
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
console.info(`Building ${locale}...`);
|
2018-12-06 00:30:30 +02:00
|
|
|
|
2020-11-05 18:58:23 +02:00
|
|
|
const poFilePäth = `${localesDir}/${locale}.po`;
|
2019-09-19 23:51:18 +02:00
|
|
|
const jsonFilePath = `${jsonLocalesDir}/${locale}.json`;
|
2022-07-23 11:33:12 +02:00
|
|
|
if (locale !== defaultLocale) await mergePotToPo(potFilePath, poFilePäth);
|
2022-11-22 20:16:57 +02:00
|
|
|
await buildLocale(poFilePäth, jsonFilePath);
|
2018-02-01 22:15:31 +02:00
|
|
|
|
|
|
|
const stat = await translationStatus(defaultLocale === locale, poFilePäth);
|
|
|
|
stat.locale = locale;
|
|
|
|
stat.languageName = countryDisplayName(locale);
|
|
|
|
stats.push(stat);
|
2017-07-18 20:04:47 +02:00
|
|
|
}
|
|
|
|
|
2018-02-01 22:15:31 +02:00
|
|
|
stats.sort((a, b) => a.languageName < b.languageName ? -1 : +1);
|
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
saveToFile(`${jsonLocalesDir}/index.js`, buildIndex(locales, stats));
|
2017-07-19 23:26:30 +02:00
|
|
|
|
2018-02-01 22:15:31 +02:00
|
|
|
await updateReadmeWithStats(stats);
|
2017-07-18 20:04:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((error) => {
|
|
|
|
console.error(error);
|
2019-11-28 20:27:38 +02:00
|
|
|
process.exit(1);
|
2018-10-04 23:30:48 +02:00
|
|
|
});
|