1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-11 11:12:03 +02:00

Tools: Added check on translation builder to prevent it from deleting too many translations

This commit is contained in:
Laurent Cozic 2019-11-28 18:27:38 +00:00
parent 1a1c87b5c4
commit f8cb908e0f

View File

@ -95,7 +95,8 @@ async function createPotFile(potFilePath, sources) {
args.push(sources[i]);
let xgettextPath = 'xgettext';
if (isMac()) xgettextPath = executablePath('xgettext'); // Needs to have been installed with `brew install gettext`
const result = await execCommand(`${xgettextPath} ${args.join(' ')}`);
const cmd = `${xgettextPath} ${args.join(' ')}`;
const result = await execCommand(cmd);
if (result) console.error(result);
await removePoHeaderDate(potFilePath);
}
@ -171,10 +172,13 @@ async function translationStatus(isDefault, poFile) {
const result = await execCommand(command);
const matches = result.match(/Translated:\s*?(\d+)\s*\((.+?)%\)/);
if (!matches || matches.length < 3) throw new Error(`Cannot extract status: ${command}:\n${result}`);
const percentDone = Number(matches[2]);
if (isNaN(percentDone)) throw new Error(`Cannot extract percent translated: ${command}:\n${result}`);
const untranslatedMatches = result.match(/Untranslated:\s*?(\d+)/);
if (!untranslatedMatches) throw new Error(`Cannot extract untranslated: ${command}:\n${result}`);
const untranslatedCount = Number(untranslatedMatches[1]);
let translatorName = '';
const content = await fs.readFile(poFile, 'utf-8');
@ -188,14 +192,12 @@ async function translationStatus(isDefault, poFile) {
translatorName = translatorName.replace(/ </, ' (');
translatorName = translatorName.replace(/>/, ')');
let isAlways100 = false;
if (poFile.endsWith('en_US.po')) {
isAlways100 = true;
}
const isAlways100 = poFile.endsWith('en_US.po');
return {
percentDone: isDefault || isAlways100 ? 100 : percentDone,
translatorName: translatorName,
untranslatedCount: untranslatedCount,
};
}
@ -240,10 +242,14 @@ async function updateReadmeWithStats(stats) {
}
async function main() {
const argv = require('yargs').argv;
let potFilePath = `${cliLocalesDir}/joplin.pot`;
let jsonLocalesDir = `${cliDir}/build/locales`;
const defaultLocale = 'en_GB';
const oldPotStatus = await translationStatus(false, potFilePath);
await createPotFile(potFilePath, [
`${cliDir}/app/*.js`,
`${cliDir}/app/gui/*.js`,
@ -259,6 +265,19 @@ async function main() {
`${rnDir}/lib/components/screens/*.js`,
]);
const newPotStatus = await translationStatus(false, potFilePath);
console.info(`Updated pot file. Total strings: ${oldPotStatus.untranslatedCount} => ${newPotStatus.untranslatedCount}`);
const deletedCount = oldPotStatus.untranslatedCount - newPotStatus.untranslatedCount;
if (deletedCount >= 10) {
if (argv['skip-missing-strings-check']) {
console.info(`${deletedCount} strings have been deleted, but proceeding anyway due to --skip-missing-strings-check flag`);
} else {
throw new Error(`${deletedCount} strings have been deleted - aborting as it could be a bug. To override, use the --skip-missing-strings-check flag.`);
}
}
await execCommand(`cp "${potFilePath}" ` + `"${cliLocalesDir}/${defaultLocale}.po"`);
fs.mkdirpSync(jsonLocalesDir, 0o755);
@ -297,4 +316,5 @@ async function main() {
main().catch((error) => {
console.error(error);
process.exit(1);
});