From 498e80f2d3e615a4f331f3c3e34deb224d63a355 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 8 Nov 2020 17:19:38 +0000 Subject: [PATCH] Tools: Display deleted strings when building translations, and run TypeScript before --- package.json | 2 +- packages/tools/.gitignore | 3 ++- packages/tools/build-translation.js | 26 ++++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 47c2160d8..a99182594 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "buildApiDoc": "npm start --prefix=packages/app-cli -- apidoc ../../readme/api/references/rest_api.md", "buildDoc": "./packages/tools/build-all.sh", "buildPluginDoc": "typedoc --name 'Joplin Plugin API Documentation' --mode file -theme './Assets/PluginDocTheme/' --readme './Assets/PluginDocTheme/index.md' --excludeNotExported --excludeExternals --excludePrivate --excludeProtected --out docs/api/references/plugin_api packages/lib/services/plugins/api/", - "buildTranslations": "node packages/tools/build-translation.js", + "buildTranslations": "npm run tsc && node packages/tools/build-translation.js", "buildWebsite": "npm run buildApiDoc && node ./packages/tools/build-website.js && npm run buildPluginDoc", "clean": "lerna clean -y && lerna run clean", "generatePluginTypes": "rm -rf ./plugin_types && node node_modules/typescript/bin/tsc --declaration --declarationDir ./plugin_types --project tsconfig.json", diff --git a/packages/tools/.gitignore b/packages/tools/.gitignore index bd2d21eca..2996106cf 100644 --- a/packages/tools/.gitignore +++ b/packages/tools/.gitignore @@ -1,3 +1,4 @@ *-kct.* github_username_cache.json -patreon_oauth_token.txt \ No newline at end of file +patreon_oauth_token.txt +*.po~ \ No newline at end of file diff --git a/packages/tools/build-translation.js b/packages/tools/build-translation.js index 6574495e7..ba6de6e3b 100644 --- a/packages/tools/build-translation.js +++ b/packages/tools/build-translation.js @@ -90,6 +90,7 @@ async function createPotFile(potFilePath) { './packages/app-cli/tests-build/*', './packages/app-cli/tests/*', './packages/app-clipper/*', + './packages/fork-*/*', './packages/app-desktop/dist/*', './packages/app-desktop/gui/note-viewer/pluginAssets/*', './packages/app-desktop/gui/style/*', @@ -285,6 +286,20 @@ async function updateReadmeWithStats(stats) { ); } +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; +} + async function main() { const argv = require('yargs').argv; @@ -292,20 +307,27 @@ async function main() { const jsonLocalesDir = `${libDir}/locales`; const defaultLocale = 'en_GB'; + const oldStrings = await translationStrings(potFilePath); const oldPotStatus = await translationStatus(false, potFilePath); await createPotFile(potFilePath); + const newStrings = await translationStrings(potFilePath); 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 (deletedCount >= 5) { 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.`); + 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')); } }