From 046433a947d5507f55537cd5c7e3437f2fe400b4 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 5 Dec 2020 11:54:58 +0000 Subject: [PATCH] Tools: Fixed issue with gettext not knowing how to parse regex that includes backtick --- .eslintignore | 3 +++ .gitignore | 3 +++ package.json | 1 + packages/lib/services/KeymapService.ts | 2 +- packages/lib/services/KeymapService_keysRegExp.ts | 9 +++++++++ packages/tools/build-translation.js | 4 ++-- 6 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 packages/lib/services/KeymapService_keysRegExp.ts diff --git a/.eslintignore b/.eslintignore index ec0c4f2b2..2c9900c77 100644 --- a/.eslintignore +++ b/.eslintignore @@ -961,6 +961,9 @@ packages/lib/services/ExternalEditWatcher.js.map packages/lib/services/KeymapService.d.ts packages/lib/services/KeymapService.js packages/lib/services/KeymapService.js.map +packages/lib/services/KeymapService_keysRegExp.d.ts +packages/lib/services/KeymapService_keysRegExp.js +packages/lib/services/KeymapService_keysRegExp.js.map packages/lib/services/KvStore.d.ts packages/lib/services/KvStore.js packages/lib/services/KvStore.js.map diff --git a/.gitignore b/.gitignore index 03e1baf1a..e1a31474a 100644 --- a/.gitignore +++ b/.gitignore @@ -950,6 +950,9 @@ packages/lib/services/ExternalEditWatcher.js.map packages/lib/services/KeymapService.d.ts packages/lib/services/KeymapService.js packages/lib/services/KeymapService.js.map +packages/lib/services/KeymapService_keysRegExp.d.ts +packages/lib/services/KeymapService_keysRegExp.js +packages/lib/services/KeymapService_keysRegExp.js.map packages/lib/services/KvStore.d.ts packages/lib/services/KvStore.js packages/lib/services/KvStore.js.map diff --git a/package.json b/package.json index 56dc26076..e9ce33550 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "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": "npm run tsc && node packages/tools/build-translation.js", + "buildTranslationsNoTsc": "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", "generateDatabaseTypes": "node packages/tools/generate-database-types", diff --git a/packages/lib/services/KeymapService.ts b/packages/lib/services/KeymapService.ts index 4929d0325..587a0a88f 100644 --- a/packages/lib/services/KeymapService.ts +++ b/packages/lib/services/KeymapService.ts @@ -1,10 +1,10 @@ import eventManager from '../eventManager'; import shim from '../shim'; import { _ } from '../locale'; +import keysRegExp from './KeymapService_keysRegExp'; const BaseService = require('./BaseService').default; -const keysRegExp = /^([0-9A-Z)!@#$%^&*(:+<_>?~{|}";=,\-./`[\\\]']|F1*[1-9]|F10|F2[0-4]|Plus|Space|Tab|Backspace|Delete|Insert|Return|Enter|Up|Down|Left|Right|Home|End|PageUp|PageDown|Escape|Esc|VolumeUp|VolumeDown|VolumeMute|MediaNextTrack|MediaPreviousTrack|MediaStop|MediaPlayPause|PrintScreen|Numlock|Scrolllock|Capslock|num([0-9]|dec|add|sub|mult|div))$/; const modifiersRegExp = { darwin: /^(Ctrl|Option|Shift|Cmd)$/, default: /^(Ctrl|Alt|AltGr|Shift|Super)$/, diff --git a/packages/lib/services/KeymapService_keysRegExp.ts b/packages/lib/services/KeymapService_keysRegExp.ts new file mode 100644 index 000000000..1e8dc4430 --- /dev/null +++ b/packages/lib/services/KeymapService_keysRegExp.ts @@ -0,0 +1,9 @@ +// We move this regex outside KeymapService because it makes gettext parsing +// fail. In fact it doesn't fail at the regex itself but at the next backtick +// into the code. Probably their parser see a backtick in the regex and opens a +// JS template string, while it shouldn't. +// https://discourse.joplinapp.org/t/translations/12832?u=laurent + +const keysRegExp = /^([0-9A-Z)!@#$%^&*(:+<_>?~{|}";=,\-./`[\\\]']|F1*[1-9]|F10|F2[0-4]|Plus|Space|Tab|Backspace|Delete|Insert|Return|Enter|Up|Down|Left|Right|Home|End|PageUp|PageDown|Escape|Esc|VolumeUp|VolumeDown|VolumeMute|MediaNextTrack|MediaPreviousTrack|MediaStop|MediaPlayPause|PrintScreen|Numlock|Scrolllock|Capslock|num([0-9]|dec|add|sub|mult|div))$/; + +export default keysRegExp; diff --git a/packages/tools/build-translation.js b/packages/tools/build-translation.js index 968bd6119..2fa71cb2c 100644 --- a/packages/tools/build-translation.js +++ b/packages/tools/build-translation.js @@ -130,7 +130,7 @@ async function createPotFile(potFilePath) { if (isMac()) xgettextPath = executablePath('xgettext'); // Needs to have been installed with `brew install gettext` const cmd = `${xgettextPath} ${args.join(' ')}`; const result = await execCommand(cmd); - if (result) console.error(result); + if (result && result.trim()) console.error(result.trim()); await removePoHeaderDate(potFilePath); } @@ -140,7 +140,7 @@ async function mergePotToPo(potFilePath, poFilePath) { const command = `${msgmergePath} -U "${poFilePath}" "${potFilePath}"`; const result = await execCommand(command); - if (result) console.error(result); + if (result && result.trim()) console.info(result.trim()); await removePoHeaderDate(poFilePath); }