VectorCraft: An open-source, vector art tool written by scratch in pure Rust
i18n: the Swatches panel shows the default swatches' names in Japanese
Hiroshi Inukai75ee324e6c7b
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 5cd5aacad..e699d2a89 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -3536,6 +3536,52 @@ theme Appearance 外観# names and values in backticks or code (`colorModel rgb`, `document.export`) stay as they are.# Japanese: no final 。 (these are status lines, and reasons that follow a colon), unless the English ends# with a period; a space between Japanese text and an adjacent Latin word, number or {placeholder}.+# Swatches panel: the default swatches' names (shown in the UI language; documents keep them)+swatch [None] [なし]+swatch [Registration] [レジストレーション]+swatch White ホワイト+swatch Black ブラック+swatch Red レッド+swatch Orange Red オレンジレッド+swatch Orange オレンジ+swatch Amber アンバー+swatch Yellow イエロー+swatch Yellow Green イエローグリーン+swatch Lime ライム+swatch Green グリーン+swatch Emerald エメラルド+swatch Teal ティール+swatch Aqua アクア+swatch Cyan Green シアングリーン+swatch Cyan シアン+swatch Azure アジュール+swatch Blue ブルー+swatch Indigo インディゴ+swatch Violet バイオレット+swatch Purple パープル+swatch Magenta マゼンタ+swatch Rose ローズ+swatch Pink ピンク+swatch Brown ブラウン+swatch Tan タン+swatch Coffee コーヒー+swatch Chocolate チョコレート+swatch Sand サンド+swatch Copper カッパー+swatch Rust ラスト+swatch Walnut ウォルナット+swatch Espresso エスプレッソ+swatch White, Black ホワイト、ブラック+swatch Radial White, Black 円形 ホワイト、ブラック+swatch Sunset サンセット+swatch Ocean オーシャン+swatch Grays グレー+swatch Brights ビビッド+swatch Bright Red ビビッドレッド+swatch Bright Yellow ビビッドイエロー+swatch Bright Green ビビッドグリーン+swatch Bright Blue ビビッドブルー+swatch Bright Violet ビビッドバイオレット@msg Reset {_1} {_1} をリセットしました@msg Saving 保存中@msg Saving {_1} {_1} を保存中diff --git a/crates/ui-egui/src/i18n/mod.rs b/crates/ui-egui/src/i18n/mod.rsindex 348390cb2..6b06d87ad 100644--- a/crates/ui-egui/src/i18n/mod.rs+++ b/crates/ui-egui/src/i18n/mod.rs@@ -472,6 +472,12 @@ pub fn tr_ctx<'a>(lang: Lang, context: &str, s: &'a str) -> &'a str {lang.catalog().contextual(context, s).unwrap_or_else(|| tr(lang, s))}+/// A name the app gives something (a default swatch's), translated where the current language has+/// a `context` row for it; any other name (one the user gave) comes back as it is.+pub fn t_name<'a>(context: &str, name: &'a str) -> &'a str {+ current().catalog().contextual(context, name).unwrap_or(name)+}+/// A string keyed by its command id, falling back to the translation of the English `label`.pub fn tr_id<'a>(lang: Lang, id: &str, label: &'a str) -> &'a str {lang.catalog().id(id).unwrap_or_else(|| tr(lang, label))diff --git a/crates/ui-egui/src/i18n/tests.rs b/crates/ui-egui/src/i18n/tests.rsindex d959b3aff..359227658 100644--- a/crates/ui-egui/src/i18n/tests.rs+++ b/crates/ui-egui/src/i18n/tests.rs@@ -1469,3 +1469,20 @@ fn polish_reads_as_polish() {let nested = "command `object.group` is not available right now: nothing selected";assert_eq!(message(pl(), nested), "polecenie `object.group` jest teraz niedostępne: nic nie zaznaczono");}++/// Japanese names every default swatch and colour group the Swatches panel shows (the greys'+/// `K=` values read the same in any language); a name the user gave a swatch has no row.+#[test]+fn japanese_names_the_default_swatches() {+ let ja = Lang::from_code("ja").unwrap().catalog();+ let (swatches, groups) = vectorcraft_color::default_swatches(vectorcraft_color::cms::Model::Rgb);+ let names = swatches+ .iter()+ .map(|s| s.name.clone())+ .chain(groups.iter().flat_map(|g| std::iter::once(g.name.clone()).chain(g.swatches.iter().map(|s| s.name.clone()))))+ .chain([vectorcraft_color::swatch::REGISTRATION.to_string()]);+ let missing: Vec<String> = names.filter(|n| !n.starts_with("K=") && ja.contextual("swatch", n).is_none()).collect();+ assert!(missing.is_empty(), "{missing:?}");+ assert_eq!(ja.contextual("swatch", "White"), Some("ホワイト"));+ assert_eq!(ja.contextual("swatch", "My Red"), None);+}diff --git a/crates/ui-egui/src/panels/swatches.rs b/crates/ui-egui/src/panels/swatches.rsindex 219d510aa..ec2b89d81 100644--- a/crates/ui-egui/src/panels/swatches.rs+++ b/crates/ui-egui/src/panels/swatches.rs@@ -429,12 +429,14 @@ fn tile_input(ui: &Ui, resp: Response, e: &Entry, items: &[Entry], sel: &[Stringegui::DragAndDrop::set_payload(ui.ctx(), drag_of(e, names));}tile_drop(ui, &resp, e, list, ev);+ // The default swatches' names show in the UI's language; the document keeps them as they are.+ let shown = crate::i18n::t_name("swatch", name);let resp = match e {- Entry::Folder(n) => resp.on_hover_text(crate::i18n::fmt(tl!("Color Group: {name}"), &[("name", n)])),+ Entry::Folder(_) => resp.on_hover_text(crate::i18n::fmt(tl!("Color Group: {name}"), &[("name", shown)])),Entry::Swatch { paint, global, spot, .. } if list => resp.on_hover_ui(|ui| {- ui.label(format!("{name} ({})", describe(paint, *global, *spot)));+ ui.label(format!("{shown} ({})", describe(paint, *global, *spot)));}),- _ => resp.on_hover_text(name),+ _ => resp.on_hover_text(shown),};if resp.clicked() {ev.clicked = Some((e.clone(), ui.input(|i| i.modifiers)));@@ -682,7 +684,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui, salt: &'static str) {}Entry::Folder(_) => draw_folder(ui, chip),}- list_row_name(ui, r, chip, name);+ list_row_name(ui, r, chip, crate::i18n::t_name("swatch", name));tile_input(ui, resp, e, &items, sel, true, &mut ev);}} else {