🐛 Name Chinese readings Pinyin or Zhuyin in every text option

- The readings group of the Language view and its hide switch read
  Pinyin, Zhuyin or, when a text mixes both, Readings, instead of Ruby.
- The options toggle of the pinyin input and the options button of the
  text selection menu read Pinyin options.
- The text selection menu shows no presentation options for zhuyin,
  whose size and position are fixed, as the sidebar already does.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-24 16:51:51 +01:00
parent 8c6ce999d9
commit 243502d77c
7 changed files with 147 additions and 21 deletions

View File

@ -89,6 +89,13 @@
(true? zhuyin) (tr "workspace.text-selection-menu.zhuyin")
:else (tr "workspace.text-selection-menu.pinyin")))
(defn- reading-options-label
"Name of the presentation options of the reading of a `family` text."
[family]
(if (= family :japanese)
(tr "workspace.text-selection-menu.ruby-options")
(tr "workspace.text-selection-menu.pinyin-options")))
(defn- reading-glyph
"Glyph standing for the reading of a `family` text: a hiragana for
furigana, the first character of 拼音 for pinyin and the first zhuyin
@ -268,9 +275,10 @@
"Input for the ruby reading of the selected text, named `label`, starting
from its current `reading`. Enter applies it, Remove drops the current
one, and Escape and the back button return to the toolbar. A `validate`
fn rejects the readings it returns false for."
fn rejects the readings it returns false for. The `more-label` button
shows only with `on-more`."
{::mf/private true}
[{:keys [label reading validate invalid-hint on-apply on-back more-open on-more]}]
[{:keys [label reading validate invalid-hint on-apply on-back more-label more-open on-more]}]
(let [reading* (mf/use-state (or reading ""))
value (deref reading*)
valid? (or (str/blank? value) (nil? validate) (validate (str/trim value)))
@ -337,15 +345,16 @@
:class (stl/css :remove-button)
:on-click on-remove}
[:span {:class (stl/css :label)} (tr "workspace.text-selection-menu.remove")]])
[:button {:type "button"
:class (stl/css :more-button)
:aria-label (tr "workspace.text-selection-menu.ruby-options")
:aria-expanded more-open
:data-testid "selection-menu-ruby-options"
:on-click on-more}
[:> icon* {:icon-id i/menu
:class (stl/css :more-icon)
:aria-hidden true}]]]))
(when (some? on-more)
[:button {:type "button"
:class (stl/css :more-button)
:aria-label more-label
:aria-expanded more-open
:data-testid "selection-menu-ruby-options"
:on-click on-more}
[:> icon* {:icon-id i/menu
:class (stl/css :more-icon)
:aria-hidden true}]])]))
(mf/defc ruby-options*
"Size, alignment, overhang and side of the reading of the selection."
@ -464,11 +473,13 @@
:reading (:ruby annotations)
:validate (when zhuyin cjk/zhuyin-reading?)
:invalid-hint (tr "workspace.options.text-options.zhuyin-invalid")
:more-label (reading-options-label family)
:more-open more-open
:on-more toggle-more
;; Zhuyin has a fixed size and position.
:on-more (when-not zhuyin toggle-more)
:on-apply apply-ruby
:on-back close-ruby}]
(when ^boolean more-open
(when (and ^boolean more-open (not zhuyin))
[:> ruby-options* {:shape-id shape-id
:values ruby-values
:vertical vertical}])]

View File

@ -454,14 +454,15 @@
:icon i/menu}])]))
(mf/defc ruby-hidden-option*
"Switch hiding the readings, unset when the spans differ."
[{:keys [values on-change on-blur]}]
"Switch hiding the readings, unset when the spans differ. It reads
`(:hidden labels)` when given."
[{:keys [values labels on-change on-blur]}]
(let [value (:ruby-hidden values)
enabled? (cond
(mixed-span-value? value) nil
(true? value) true
:else false)
label (tr "workspace.options.text-options.ruby-hidden")
label (or (:hidden labels) (tr "workspace.options.text-options.ruby-hidden"))
handle-change
(mf/use-fn
(mf/deps on-change on-blur)

View File

@ -220,12 +220,12 @@
(if zhuyin?
{:input (tr "workspace.options.text-options.zhuyin")
:placeholder (tr "workspace.options.text-options.zhuyin-placeholder")
:advanced (tr "workspace.options.text-options.ruby-advanced-options")
:validate cjk/zhuyin-reading?
:invalid (tr "workspace.options.text-options.zhuyin-invalid")}
{:input (tr "workspace.options.text-options.pinyin")
:placeholder (tr "workspace.options.text-options.pinyin-placeholder")
:advanced (tr "workspace.options.text-options.ruby-advanced-options")}))
:advanced (tr "workspace.options.text-options.pinyin-advanced-options")
:hidden (tr "workspace.options.text-options.pinyin-hidden")}))
(mf/defc chinese-selection-options*
"Chinese options of a text selection: its reading, pinyin or zhuyin, when
@ -312,12 +312,33 @@
;; Ruby
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn ruby-group-labels
"Title and hide switch label of the readings group of a `family` text:
ruby for Japanese; pinyin, zhuyin or, when the readings mix both
(`zhuyin` is `:multiple`), readings for Chinese."
[family zhuyin]
(cond
(not= family :chinese)
{:title (tr "workspace.options.text-options.language-group-ruby")}
(true? zhuyin)
{:title (tr "workspace.options.text-options.zhuyin")
:hidden (tr "workspace.options.text-options.zhuyin-hidden")}
(= :multiple zhuyin)
{:title (tr "workspace.options.text-options.language-group-readings")
:hidden (tr "workspace.options.text-options.readings-hidden")}
:else
{:title (tr "workspace.options.text-options.pinyin")
:hidden (tr "workspace.options.text-options.pinyin-hidden")}))
(mf/defc ruby-group-options*
"How the readings of the text look. `values` are the ruby values of the
text (or of the selection), and `on-change` applies to every reading of
the text without a selection. Zhuyin readings can only be hidden."
[{:keys [values on-change on-blur]}]
(let [props (mf/props {:values values :on-change on-change :on-blur on-blur
[{:keys [values labels on-change on-blur]}]
(let [props (mf/props {:values values :labels labels :on-change on-change :on-blur on-blur
:vertical (tcc/vertical-writing? values)})]
[:*
[:> tcc/annotation-clearance-option* props]
@ -486,8 +507,11 @@
select-language (use-select-language on-change nil)
ruby-labels (ruby-group-labels family (:ruby-zhuyin ruby-values))
ruby-props
(mf/props {:values (assoc ruby-values :writing-mode (:writing-mode values))
:labels ruby-labels
:on-change on-ruby-presentation-change
:on-blur on-blur})]
@ -527,5 +551,5 @@
:korean [:> korean-layout-options* options-props])])
(when (and ^boolean has-ruby (not= :korean family) (some? family))
[:> language-group* {:title (tr "workspace.options.text-options.language-group-ruby")}
[:> language-group* {:title (:title ruby-labels)}
[:> ruby-group-options* ruby-props]])]))

View File

@ -212,6 +212,28 @@
(count-of (render-language-view "zh-Hant-TW" {:has-ruby true}) clearance))
"with readings, clearance shows once, in the Ruby group")))
(t/deftest chinese-readings-group-names-pinyin-or-zhuyin
(doseq [[zhuyin title hidden]
[[false "workspace.options.text-options.pinyin" "workspace.options.text-options.pinyin-hidden"]
[true "workspace.options.text-options.zhuyin" "workspace.options.text-options.zhuyin-hidden"]
[:multiple "workspace.options.text-options.language-group-readings"
"workspace.options.text-options.readings-hidden"]]]
(let [markup (render-language-view "zh-Hant-TW" {:has-ruby true
:ruby-values {:ruby-zhuyin zhuyin}})]
(t/is (pos? (count-of markup title)) (str zhuyin))
(t/is (pos? (count-of markup hidden)) (str zhuyin))
(t/is (not (str/includes? markup "workspace.options.text-options.language-group-ruby")))
(t/is (zero? (count-of markup "workspace.options.text-options.ruby-hidden")))))
(t/is (str/includes? (render-language-view "ja" {:has-ruby true})
"workspace.options.text-options.language-group-ruby")
"Japanese keeps the ruby group"))
(t/deftest pinyin-input-names-its-options-pinyin
(with-redefs [hooks/use-portal-container (fn ([] nil) ([_] nil))]
(let [markup (render-language-view "zh-Hans-CN" {:selection true :reading true})]
(t/is (str/includes? markup "workspace.options.text-options.pinyin-advanced-options"))
(t/is (not (str/includes? markup "workspace.options.text-options.ruby-advanced-options"))))))
(t/deftest zhuyin-explains-what-selection-it-needs
(let [hint "workspace.options.text-options.zhuyin-selection-hint"]
(t/is (str/includes? (render-language-view "zh-Hant-TW" {:values {:ruby-zhuyin true}

View File

@ -81,3 +81,23 @@
(t/is (not (str/includes? pinyin "あ")))
(t/is (str/includes? zhuyin "ㄅ"))
(t/is (not (str/includes? zhuyin "あ")))))
(defn- render-ruby-input
"Static markup of the reading input, with a more button when `on-more`."
[on-more]
(rds/renderToStaticMarkup
(mf/element @#'selection-menu/ruby-input*
(mf/props {:label "reading"
:reading ""
:more-label "workspace.text-selection-menu.pinyin-options"
:more-open false
:on-more on-more
:on-apply identity
:on-back identity}))))
(t/deftest reading-input-shows-its-options-button-only-with-on-more
(let [markup (render-ruby-input identity)]
(t/is (str/includes? markup "data-testid=\"selection-menu-ruby-options\""))
(t/is (str/includes? markup "aria-label=\"workspace.text-selection-menu.pinyin-options\"")))
(t/is (not (str/includes? (render-ruby-input nil) "selection-menu-ruby-options"))
"zhuyin has no presentation options"))

View File

@ -8413,6 +8413,10 @@ msgstr "Clearance"
msgid "workspace.options.text-options.annotation-clearance-auto"
msgstr "Automatic"
#: src/app/main/ui/workspace/sidebar/options/menus/text_language_layout.cljs
msgid "workspace.options.text-options.language-group-readings"
msgstr "Readings"
#: src/app/main/ui/workspace/sidebar/options/menus/text_japanese_layout.cljs
msgid "workspace.options.text-options.line-adjustment"
msgstr "Line breaking"
@ -8477,6 +8481,18 @@ msgstr "Letter Spacing"
msgid "workspace.options.text-options.line-height"
msgstr "Line height"
#: src/app/main/ui/workspace/sidebar/options/menus/text_language_layout.cljs
msgid "workspace.options.text-options.pinyin-advanced-options"
msgstr "Pinyin options"
#: src/app/main/ui/workspace/sidebar/options/menus/text_language_layout.cljs
msgid "workspace.options.text-options.pinyin-hidden"
msgstr "Hide pinyin"
#: src/app/main/ui/workspace/sidebar/options/menus/text_language_layout.cljs
msgid "workspace.options.text-options.readings-hidden"
msgstr "Hide readings"
#: src/app/main/ui/workspace/sidebar/options/menus/text.cljs
msgid "workspace.options.text-options.ruby"
msgstr "Ruby"
@ -8677,6 +8693,10 @@ msgstr "Horizontal"
msgid "workspace.options.text-options.writing-mode-vertical"
msgstr "Vertical (right to left)"
#: src/app/main/ui/workspace/sidebar/options/menus/text_language_layout.cljs
msgid "workspace.options.text-options.zhuyin-hidden"
msgstr "Hide zhuyin"
#: src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs:788
msgid "workspace.options.use-play-button"
msgstr "Use the play button at the header to run the prototype view."
@ -9323,6 +9343,10 @@ msgstr "Furigana"
msgid "workspace.text-selection-menu.pinyin"
msgstr "Pinyin"
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
msgid "workspace.text-selection-menu.pinyin-options"
msgstr "Pinyin options"
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
msgid "workspace.text-selection-menu.reading"
msgstr "Reading"

View File

@ -8505,6 +8505,10 @@ msgstr "Ancho automático"
msgid "workspace.options.text-options.grow-fixed"
msgstr "Fijo"
#: src/app/main/ui/workspace/sidebar/options/menus/text_language_layout.cljs
msgid "workspace.options.text-options.language-group-readings"
msgstr "Lecturas"
#: src/app/main/ui/workspace/sidebar/options/menus/typography.cljs:732
msgid "workspace.options.text-options.letter-spacing"
msgstr "Espaciado entre letras"
@ -8513,6 +8517,18 @@ msgstr "Espaciado entre letras"
msgid "workspace.options.text-options.line-height"
msgstr "Altura de línea"
#: src/app/main/ui/workspace/sidebar/options/menus/text_language_layout.cljs
msgid "workspace.options.text-options.pinyin-advanced-options"
msgstr "Opciones de pinyin"
#: src/app/main/ui/workspace/sidebar/options/menus/text_language_layout.cljs
msgid "workspace.options.text-options.pinyin-hidden"
msgstr "Ocultar pinyin"
#: src/app/main/ui/workspace/sidebar/options/menus/text_language_layout.cljs
msgid "workspace.options.text-options.readings-hidden"
msgstr "Ocultar lecturas"
#: src/app/main/ui/workspace/sidebar/options/menus/text.cljs:212
msgid "workspace.options.text-options.strikethrough"
msgstr "Tachado (%s)"
@ -8564,6 +8580,10 @@ msgstr "Subrayado (%s)"
msgid "workspace.options.text-options.zhuyin"
msgstr "Zhuyin"
#: src/app/main/ui/workspace/sidebar/options/menus/text_language_layout.cljs
msgid "workspace.options.text-options.zhuyin-hidden"
msgstr "Ocultar zhuyin"
msgid "workspace.options.text-options.zhuyin-invalid"
msgstr ""
"Escribe entre 1 y 3 símbolos zhuyin con un solo tono como máximo. Coloca el "
@ -9226,6 +9246,10 @@ msgstr "Furigana"
msgid "workspace.text-selection-menu.pinyin"
msgstr "Pinyin"
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
msgid "workspace.text-selection-menu.pinyin-options"
msgstr "Opciones de pinyin"
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
msgid "workspace.text-selection-menu.reading"
msgstr "Lectura"