Update lang validation to detect duplicates

There are still a few to remove.
Remove lang:duplicates as it's now included in the linter
This commit is contained in:
Gabriel Horner
2023-06-05 11:09:01 -04:00
parent 68a339c227
commit 2d60d95bc5
4 changed files with 31 additions and 43 deletions

3
bb.edn
View File

@@ -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

View File

@@ -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,

View File

@@ -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))

View File

@@ -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"