Просмотр исходного кода

Update lang validation to detect duplicates

There are still a few to remove.
Remove lang:duplicates as it's now included in the linter
Gabriel Horner 2 лет назад
Родитель
Сommit
2d60d95bc5
4 измененных файлов с 27 добавлено и 39 удалено
  1. 0 3
      bb.edn
  2. 0 16
      docs/contributing-to-translations.md
  3. 26 20
      scripts/src/logseq/tasks/lang.clj
  4. 1 0
      src/resources/dicts/fr.edn

+ 0 - 3
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
 

+ 0 - 16
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,

+ 26 - 20
scripts/src/logseq/tasks/lang.clj

@@ -154,31 +154,37 @@
           (task-util/print-table (map #(hash-map :invalid-key %) expected-only)))
         (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))
+(def allowed-duplicates
+  "Allows certain keys in a language to have the same translation
+   as English. Rare but it does happen"
+  {:fr #{:port}})
 
-(defn list-duplicates
-  "Lists translations that are the same as the one in English"
-  [& args]
+(defn- validate-languages-dont-have-duplicates
+  "Looks up duplicates for all languages"
+  []
   (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)))]
+        (->> (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 "No duplicated keys found!")
+      (println "All languages have no duplicate English values!")
       (do
-        (println "Keys with duplicate values found:")
+        (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)
+  (validate-languages-dont-have-duplicates))

+ 1 - 0
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"