From 2d60d95bc55431422952824d5085557c97f84c5e Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Mon, 5 Jun 2023 11:09:01 -0400 Subject: [PATCH] Update lang validation to detect duplicates There are still a few to remove. Remove lang:duplicates as it's now included in the linter --- bb.edn | 3 -- docs/contributing-to-translations.md | 16 --------- scripts/src/logseq/tasks/lang.clj | 54 +++++++++++++++------------- src/resources/dicts/fr.edn | 1 + 4 files changed, 31 insertions(+), 43 deletions(-) diff --git a/bb.edn b/bb.edn index fc11c03f27..979f094537 100644 --- a/bb.edn +++ b/bb.edn @@ -109,9 +109,6 @@ lang:missing logseq.tasks.lang/list-missing - lang:duplicates - logseq.tasks.lang/list-duplicates - lang:validate-translations logseq.tasks.lang/validate-translations diff --git a/docs/contributing-to-translations.md b/docs/contributing-to-translations.md index 2a0111d80e..b9ea9bec50 100644 --- a/docs/contributing-to-translations.md +++ b/docs/contributing-to-translations.md @@ -80,22 +80,6 @@ $ bb lang:missing es --copy Almost all translations are small. The only exceptions to this are the keys `:tutorial/text` and `:tutorial/dummy-notes`. These translations are files that are part of the onboarding tutorial and can be found under [src/resources/tutorials/](https://github.com/logseq/logseq/blob/master/src/resources/tutorials/). -## Fix Untranslated - -There is a lot to translate and sometimes we forget to translate a string. To see what translation keys are still left for your language use : - -```shell -$ bb lang:duplicates LOCALE - -Keys with duplicate values found: - -| :translation-key | :duplicate-value | -|-----------------------------------+------------------| -| :general | General | -| :logseq | Logseq | -| :no | No | -``` - ## Fix Mistakes Sometimes, we typo a translation key or forget to use it. If this happens, diff --git a/scripts/src/logseq/tasks/lang.clj b/scripts/src/logseq/tasks/lang.clj index 33e3f8a3fc..e38f9b79e9 100644 --- a/scripts/src/logseq/tasks/lang.clj +++ b/scripts/src/logseq/tasks/lang.clj @@ -154,31 +154,37 @@ (task-util/print-table (map #(hash-map :invalid-key %) expected-only))) (System/exit 1))))) +(def allowed-duplicates + "Allows certain keys in a language to have the same translation + as English. Rare but it does happen" + {:fr #{:port}}) + +(defn- validate-languages-dont-have-duplicates + "Looks up duplicates for all languages" + [] + (let [dicts (get-dicts) + en-dicts (dicts :en) + invalid-dicts + (->> (dissoc dicts :en) + (mapcat + (fn [[lang lang-dicts]] + (keep + #(when (= (en-dicts %) (lang-dicts %)) + {:translation-key % + :lang lang + :duplicate-value (shorten (lang-dicts %) 70)}) + (keys (apply dissoc lang-dicts (allowed-duplicates lang)))))) + (sort-by (juxt :lang :translation-key)))] + (if (empty? invalid-dicts) + (println "All languages have no duplicate English values!") + (do + (println "These translations keys are invalid because they are just copying the English value:") + (task-util/print-table invalid-dicts) + (System/exit 1))))) + (defn validate-translations "Runs multiple translation validations that fail fast if one of them is invalid" [] (validate-non-default-languages) - (validate-ui-translations-are-used)) - -(defn list-duplicates - "Lists translations that are the same as the one in English" - [& args] - (let [dicts (get-dicts) - en-dicts (dicts :en) - lang (or (keyword (first args)) - (task-util/print-usage "LOCALE")) - lang-dicts (dicts lang) - invalid-dicts - (sort-by - :translation-key - (keep - #(when (= (en-dicts %) (lang-dicts %)) - {:translation-key % - :duplicate-value (shorten (lang-dicts %) 70)}) - (keys lang-dicts)))] - (if (empty? invalid-dicts) - (println "No duplicated keys found!") - (do - (println "Keys with duplicate values found:") - (task-util/print-table invalid-dicts) - (System/exit 1))))) + (validate-ui-translations-are-used) + (validate-languages-dont-have-duplicates)) \ No newline at end of file diff --git a/src/resources/dicts/fr.edn b/src/resources/dicts/fr.edn index d707173574..01fad521ac 100644 --- a/src/resources/dicts/fr.edn +++ b/src/resources/dicts/fr.edn @@ -107,6 +107,7 @@ :open-a-directory "Ouvrir un dossier local" :open-new-window "Nouvelle fenêtre" :page-search "Chercher dans la page en cours" + :port "Port" :re-index-detail "Reconstruire le graphe" :re-index-discard-unsaved-changes-warning "La réindexation va effacer le graphe actuel, puis l'indéxer à nouveau. Ceci risque de vous faire perdre le travail non sauvegardé. Continuer ?" :re-index-multiple-windows-warning "Vous devez d'abord fermer les autres fenêtres avant de réindexer"