penpot/frontend/test/frontend_tests/ui/shortcuts_labels_test.cljs
Andrey Antukh 4b978767ea
🌐 Clean up en translations (#11853)
Drop 277 keys nothing references from en.po (verified against
frontend/src and common/src) and let sync propagate the
deletions to every locale. Clear all 10 fuzzy entries: fill
the 5 empty translations, keep the 4 valid ones, and drop the
duplicated max-quote-reached in favor of max-quota-reached
(the backend code stays, the UI maps it to the quota text).

Recover 22 used-but-missing keys with translations: the 19
shortcuts section/subsection labels plus connected-to,
pixel-grid-color and tokens.add-set. Make the rest
statically visible to rehash instead: :label fns on shortcut
commands, sections and subsections (one debug-only and one
colorpicker-local id exempt); case branches in place of
dm/str-built keys (export modal, text decoration and
transform, undo history with raw-key fallback); hoist
conditionals out of tr calls; pre-translate modal props and
role labels; replace the lone (i18n/tr ...) site with tr.
Turn static :error/code data into eager :error/fn calls in
the common schemas and the auth/password forms. Rename the
two keys containing spaces and point team leave at
max-quota-reached. Backend-driven keys stay dynamic by
design, declared with (tr ...) comments: the five
weak-password details, team and organization notifications.

Tooling: rehash also scans common/src and no longer treats
a missing -l as no locale; new clj-kondo tr-dynamic warning
flags non-literal tr args (lint scripts use --fail-level
error so it never fails CI); tr docstring states the
literal-only rule. Tests cover the shortcut label wiring,
the undo-history fallback and the :error/fn schemas.
Translations memory rewritten to match; es check word list
gains three entries.

Rebased onto develop: adopt the register field-error UX
(the weak-password declarations move onto the :options
code), keep develop's newer keys (connection-error,
account-locked, save-retrying, tokens-source strings) with
fresh references, and reword the shortcuts.cljs prose
comment so rehash does not invent a "literal" key.

AI-assisted-by: muse-spark-1.3-contributor
2026-09-25 11:11:44 +02:00

78 lines
3.0 KiB
Clojure

;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS SUBSIDIARY SL
(ns frontend-tests.ui.shortcuts-labels-test
(:require
[app.main.data.dashboard.shortcuts :as dsc]
[app.main.data.viewer.shortcuts :as vsc]
[app.main.data.workspace.grid-layout.shortcuts :as gsc]
[app.main.data.workspace.path.shortcuts :as psc]
[app.main.data.workspace.shortcuts :as wsc]
[app.main.ui.shortcuts :as ss]
[app.util.i18n :as i18n]
[cljs.test :as t :include-macros true]
[frontend-tests.helpers.mock :as mock]))
;; Every shortcut command definition carries a :label fn holding a static
;; (tr "literal") (see :penpot/tr-dynamic). This locks the wiring: all
;; definition ids resolve through translation-keyname, and unknown ids
;; (stale custom shortcuts, debug commands) fall back to the raw key.
;; Exempt: :preview-frame (debug-only, no PO key) and :delete-stop
;; (colorpicker-local, never translated); both keep today's raw fallback.
(def ^:private definition-maps
[wsc/shortcuts
psc/shortcuts
dsc/shortcuts
dsc/shortcuts-sidebar-navigation
dsc/shortcut-search
dsc/shortcut-create-new-project
vsc/shortcuts
gsc/shortcuts])
(def ^:private exempt-ids
#{:preview-frame})
(def ^:private section-ids
[:basics :workspace :dashboard :viewer])
(def ^:private subsection-ids
[:alignment :basics :edit :generic :main-menu :modify-layers
:navigation-dashboard :navigation-viewer :navigation-workspace
:panels :path-editor :shape :text-editor :tools :zoom-viewer
:zoom-workspace])
(t/deftest command-definitions-carry-static-labels
(with-redefs [i18n/tr (mock/stub (fn [k] (str "TR:" k)))]
(t/testing "every definition id resolves its literal key"
(doseq [shortcuts definition-maps
[id entry] shortcuts
:when (not (contains? exempt-ids id))]
(t/is (fn? (:label entry)) (str id " has a :label fn"))
(t/is (= (str "TR:shortcuts." (name id))
(ss/translation-keyname :sc id))
(str id " resolves"))))
(t/testing "sections resolve their literal keys"
(doseq [id section-ids]
(t/is (= (str "TR:shortcuts.section." (name id))
(ss/translation-keyname :sec id))
(str id " resolves"))))
(t/testing "subsections resolve, bare basics falls back to raw"
(doseq [id (remove #{:basics} subsection-ids)]
(t/is (= (str "TR:shortcuts.subsection." (name id))
(ss/translation-keyname :sub-sec id))
(str id " resolves")))
(t/is (= "shortcuts.subsection.basics"
(ss/translation-keyname :sub-sec :basics))))
(t/testing "unknown ids fall back to the raw key"
(t/is (= "shortcuts.stale-id"
(ss/translation-keyname :sc :stale-id)))
(t/is (= "shortcuts.preview-frame"
(ss/translation-keyname :sc :preview-frame))))))