Skip to content

Commit 7ffface

Browse files
committed
docs: describe Japanese interface contracts and regressions (#15)
1 parent 89520d0 commit 7ffface

15 files changed

Lines changed: 67 additions & 0 deletions

File tree

‎crates/ui-egui/src/app/commands.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl SlideApp {
5353
params.get("on").and_then(Value::as_bool).unwrap_or(!cur)
5454
}
5555

56+
/// Execute application commands, including validated interface-language changes.
5657
fn run_ui(&mut self, id: &str, p: &Value) -> Result<Value, String> {
5758
match id {
5859
"view.normal" => self.ui.view = ViewMode::Normal,

‎crates/ui-egui/src/dialogs.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl Dialog {
2929
}
3030
}
3131

32+
/// Resolve supported dialog captions without changing the dialog identifier.
3233
fn title(lang: i18n::Resolved, id: &str) -> &'static str {
3334
match id {
3435
"table" => i18n::text(lang, "dialog.table.title"),
@@ -126,14 +127,17 @@ pub fn show(app: &mut SlideApp, ctx: &egui::Context) {
126127
}
127128
}
128129

130+
/// Draw the default confirmation row with an English Cancel caption.
129131
fn buttons(ui: &mut Ui, ok_label: &str) -> (bool, bool) {
130132
buttons_labeled(ui, ok_label, "Cancel")
131133
}
132134

135+
/// Translate Cancel while retaining the caller's confirmation caption.
133136
fn localized_buttons(ui: &mut Ui, lang: i18n::Resolved, ok_label: &str) -> (bool, bool) {
134137
buttons_labeled(ui, ok_label, i18n::text(lang, "pref.cancel"))
135138
}
136139

140+
/// Lay out confirmation and cancellation actions and report which was activated.
137141
fn buttons_labeled(ui: &mut Ui, ok_label: &str, cancel_label: &str) -> (bool, bool) {
138142
let mut ok = false;
139143
let mut cancel = false;

‎crates/ui-egui/src/dialogs/about.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub(super) fn credits_block(ui: &mut Ui, models: bool) -> Rect {
1616
.rect
1717
}
1818

19+
/// Draw version and project information with the supported localized captions.
1920
pub fn about(app: &mut SlideApp, ui: &mut Ui) {
2021
let lang = app.lang();
2122
let t = Tokens::get(ui.ctx());

‎crates/ui-egui/src/dialogs/body.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fn run(app: &mut SlideApp, id: &str, p: Value) {
7979
let _ = app.run(id, p);
8080
}
8181

82+
/// Insert a table from the stable row/column fields behind translated captions.
8283
fn dlg_table(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
8384
let lang = app.lang();
8485
field(ui, d, i18n::text(lang, "dialog.table.columns"), "cols", "5");
@@ -91,6 +92,7 @@ fn dlg_table(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
9192
ok || cancel
9293
}
9394

95+
/// Edit exact slide dimensions and display localized preset names without changing preset identities.
9496
fn dlg_slide_size(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
9597
let lang = app.lang();
9698
let cur = app.session.active().map(|s| s.doc.slide_size).unwrap_or(deckcraft_model::defaults::WIDE);
@@ -141,6 +143,7 @@ fn dlg_slide_size(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
141143
ok || cancel
142144
}
143145

146+
/// Apply header/footer choices without rewriting untouched date-format values.
144147
fn dlg_header_footer(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
145148
let lang = app.lang();
146149
let hf = app.session.active().map(|s| s.doc.header_footer.clone()).unwrap_or_default();
@@ -200,6 +203,7 @@ fn dlg_header_footer(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
200203
apply || apply_all || d.fields.contains_key("cancel")
201204
}
202205

206+
/// Edit hyperlink display fields while preserving stored link kinds and target parameters.
203207
fn dlg_hyperlink(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
204208
let lang = app.lang();
205209
let seed = hyperlink_seed_of(app.session.active());
@@ -250,6 +254,7 @@ fn dlg_hyperlink(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
250254
ok || cancel
251255
}
252256

257+
/// Configure playback options with translated captions and the existing show values.
253258
fn dlg_setup_show(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
254259
let lang = app.lang();
255260
let sh = app.session.active().map(|s| s.doc.show.clone()).unwrap_or_default();
@@ -294,6 +299,7 @@ fn dlg_setup_show(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
294299
ok || cancel
295300
}
296301

302+
/// Resolve save/discard/cancel decisions for dirty presentations before application exit.
297303
fn dlg_quit(app: &mut SlideApp, ui: &mut Ui, _d: &mut Dialog) -> bool {
298304
let lang = app.lang();
299305
let names: Vec<String> = app.session.documents().iter().filter(|d| d.is_dirty()).map(|d| d.title()).collect();
@@ -338,6 +344,7 @@ fn dlg_quit(app: &mut SlideApp, ui: &mut Ui, _d: &mut Dialog) -> bool {
338344
done
339345
}
340346

347+
/// Resolve save/discard/cancel for the active presentation.
341348
fn dlg_close(app: &mut SlideApp, ui: &mut Ui, _d: &mut Dialog) -> bool {
342349
let lang = app.lang();
343350
// File › Close and Ctrl+W on a presentation with unsaved changes.
@@ -374,6 +381,7 @@ fn dlg_close(app: &mut SlideApp, ui: &mut Ui, _d: &mut Dialog) -> bool {
374381
done
375382
}
376383

384+
/// Post nonempty user-authored comment text through the existing comment command.
377385
fn dlg_comment(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
378386
let lang = app.lang();
379387
let mut v = d.get("text", "");
@@ -490,6 +498,7 @@ fn dlg_bullets(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
490498
ok || cancel || none
491499
}
492500

501+
/// Edit shape interaction settings while retaining their stored action kinds and targets.
493502
fn dlg_action(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
494503
let lang = app.lang();
495504
use deckcraft_model::text::Action;
@@ -615,6 +624,7 @@ fn dlg_action(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
615624
ok || cancel
616625
}
617626

627+
/// Edit descriptive text and the decorative flag without translating user-authored content.
618628
fn dlg_alt_text(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
619629
let lang = app.lang();
620630
let (cur, deco_now) = app
@@ -639,6 +649,7 @@ fn dlg_alt_text(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
639649
ok || cancel
640650
}
641651

652+
/// Insert slides from the entered outline, keeping the outline text literal.
642653
fn dlg_outline(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
643654
let lang = app.lang();
644655
ui.label(i18n::text(lang, "dialog.outline.description"));
@@ -652,6 +663,7 @@ fn dlg_outline(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
652663
ok || cancel
653664
}
654665

666+
/// Choose source slides for reuse while preserving presentation names and command parameters.
655667
fn dlg_reuse_slides(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
656668
let lang = app.lang();
657669
let path = d.params.get("path").and_then(Value::as_str).unwrap_or("").to_string();
@@ -716,6 +728,7 @@ fn dlg_reuse_slides(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
716728
cancel
717729
}
718730

731+
/// Rename a section, shape or layout while preserving its target identity.
719732
fn dlg_rename_section(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
720733
let lang = app.lang();
721734
let cur = d.params.get("name").and_then(Value::as_str).unwrap_or("").to_string();
@@ -732,6 +745,7 @@ fn dlg_rename_section(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
732745
ok || cancel
733746
}
734747

748+
/// Choose an export action using localized captions and the existing export parameters.
735749
fn dlg_export(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
736750
let lang = app.lang();
737751
ui.label(i18n::text(lang, "dialog.export.description"));
@@ -878,6 +892,7 @@ fn dlg_replace_fonts(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
878892
cancel
879893
}
880894

895+
/// Display localized symbol-group captions and insert the selected original character.
881896
fn dlg_symbol(app: &mut SlideApp, ui: &mut Ui, _d: &mut Dialog) -> bool {
882897
let lang = app.lang();
883898
ui.label(i18n::text(lang, "dialog.symbol.description"));
@@ -906,6 +921,7 @@ fn dlg_symbol(app: &mut SlideApp, ui: &mut Ui, _d: &mut Dialog) -> bool {
906921
ok || cancel
907922
}
908923

924+
/// Insert an equation from literal user input behind localized dialog captions.
909925
fn dlg_equation(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
910926
let lang = app.lang();
911927
ui.label(i18n::text(lang, "dialog.equation.description"));
@@ -947,6 +963,7 @@ fn dlg_paste_special(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
947963
ok || cancel
948964
}
949965

966+
/// Review spelling results and route actions to their original slide and shape identifiers.
950967
fn dlg_spelling(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
951968
let lang = app.lang();
952969
// Words skipped with Ignore All while the dialog is open, one per line.
@@ -1091,6 +1108,7 @@ fn dlg_spelling(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
10911108
ok || cancel
10921109
}
10931110

1111+
/// Display accessibility results and navigate to the original reported object.
10941112
fn dlg_accessibility(app: &mut SlideApp, ui: &mut Ui, _d: &mut Dialog) -> bool {
10951113
let lang = app.lang();
10961114
let v = app.session.execute("review.accessibility", &json!({})).unwrap_or_default();
@@ -1120,6 +1138,7 @@ fn dlg_accessibility(app: &mut SlideApp, ui: &mut Ui, _d: &mut Dialog) -> bool {
11201138
ok || cancel
11211139
}
11221140

1141+
/// Set text proofing language independently of the interface-language choice.
11231142
fn dlg_language(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
11241143
let ui_lang = app.lang();
11251144
// Starts from the selected text's language and Do Not Check Spelling.
@@ -1169,6 +1188,7 @@ fn dlg_language(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
11691188
ok || cancel
11701189
}
11711190

1191+
/// Manage custom shows without translating their names or stored slide lists.
11721192
fn dlg_custom_show(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
11731193
let lang = app.lang();
11741194
let shows = app.session.active().map(|s| s.doc.custom_shows.clone()).unwrap_or_default();
@@ -1199,6 +1219,7 @@ fn dlg_custom_show(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
11991219
ok || cancel
12001220
}
12011221

1222+
/// Edit literal chart data behind localized controls and retain the existing grid format.
12021223
fn dlg_chart_data(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
12031224
let lang = app.lang();
12041225
let ch = app.session.active().and_then(|s| {
@@ -1253,6 +1274,7 @@ fn dlg_chart_data(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
12531274
ok || cancel
12541275
}
12551276

1277+
/// Apply media trimming and fade values through the existing command fields.
12561278
fn dlg_trim(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
12571279
let lang = app.lang();
12581280
let seed = trim_seed(app.session.active());
@@ -1276,6 +1298,7 @@ fn dlg_trim(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
12761298
ok || cancel
12771299
}
12781300

1301+
/// Insert the chosen SmartArt kind with literal user-authored item text.
12791302
fn dlg_smartart(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
12801303
let lang = app.lang();
12811304
ui.label(i18n::text(lang, "dialog.smartart.description"));
@@ -1305,6 +1328,7 @@ fn dlg_smartart(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
13051328
ok || cancel
13061329
}
13071330

1331+
/// Switch credit sections by stable keys while localizing their visible captions.
13081332
fn dlg_about(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
13091333
let lang = app.lang();
13101334
let tab = d.get("tab", "about");
@@ -1330,6 +1354,7 @@ fn dlg_about(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
13301354
ok || cancel
13311355
}
13321356

1357+
/// Edit autocorrection preferences without translating user-defined replacements.
13331358
fn dlg_autocorrect(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
13341359
let lang = app.lang();
13351360
let pr = &mut app.session.prefs;
@@ -1376,6 +1401,7 @@ fn dlg_autocorrect(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
13761401
ok || cancel
13771402
}
13781403

1404+
/// Preview preferences and restore the opening snapshot, including language, on cancellation.
13791405
fn dlg_preferences(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
13801406
let lang = app.lang();
13811407
// The controls apply as they change, so the dialog remembers what it opened with and

‎crates/ui-egui/src/i18n.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub enum LanguageChoice {
1919
impl LanguageChoice {
2020
pub const ALL: [LanguageChoice; 3] = [Self::System, Self::En, Self::Ja];
2121

22+
/// Return this language's stable command or preference code.
2223
pub fn code(self) -> &'static str {
2324
match self {
2425
Self::System => "system",
@@ -42,6 +43,7 @@ impl LanguageChoice {
4243
None
4344
}
4445

46+
/// Resolve an explicit choice or system locale to a supported display language.
4547
pub fn resolve(self, system: Option<&str>) -> Resolved {
4648
match self {
4749
Self::En => Resolved::En,
@@ -52,12 +54,14 @@ impl LanguageChoice {
5254
}
5355

5456
impl Serialize for LanguageChoice {
57+
/// Save the language choice as its stable code rather than a translated caption.
5558
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
5659
serializer.serialize_str(self.code())
5760
}
5861
}
5962

6063
impl<'de> Deserialize<'de> for LanguageChoice {
64+
/// Read a saved language choice, falling back to System for unknown codes.
6165
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
6266
let raw = String::deserialize(deserializer)?;
6367
Ok(Self::parse(&raw).unwrap_or(Self::System))
@@ -72,6 +76,7 @@ pub enum Resolved {
7276
}
7377

7478
impl Resolved {
79+
/// Return this language's stable command or preference code.
7580
pub fn code(self) -> &'static str {
7681
match self {
7782
Self::En => "en",
@@ -89,6 +94,7 @@ pub fn resolve_tag(tag: &str) -> Resolved {
8994
Resolved::En
9095
}
9196

97+
/// Normalize locale separators, case and encoding suffixes for catalog selection.
9298
fn normalize(raw: &str) -> String {
9399
let trimmed = raw.trim();
94100
let head = trimmed.split(['.', '@']).next().unwrap_or(trimmed);
@@ -102,6 +108,7 @@ pub fn system_tag() -> Option<String> {
102108
CACHED.get_or_init(read_system_tag).clone()
103109
}
104110

111+
/// Read the platform locale when available; the web build has no native locale here.
105112
fn read_system_tag() -> Option<String> {
106113
#[cfg(not(target_arch = "wasm32"))]
107114
let tag = sys_locale::get_locale();
@@ -660,6 +667,7 @@ pub fn slide_size_label(lang: Resolved, name: &str) -> &str {
660667
text(lang, id)
661668
}
662669

670+
/// Return the localized caption for a stable language-preference choice.
663671
pub fn choice_label(lang: Resolved, choice: LanguageChoice) -> &'static str {
664672
let id = match choice {
665673
LanguageChoice::System => "pref.system",
@@ -684,6 +692,7 @@ pub(crate) fn japanese_font_input_available() -> bool {
684692
mod tests {
685693
use super::*;
686694

695+
/// Collect placeholder names in order so translated messages can be compared.
687696
fn holes(s: &str) -> Vec<&str> {
688697
let mut out = Vec::new();
689698
let mut rest = s;
@@ -697,6 +706,7 @@ mod tests {
697706
}
698707

699708
#[test]
709+
/// Require unique sorted keys, nonempty translations and matching message placeholders.
700710
fn the_shell_catalog_is_sorted_and_complete() {
701711
let mut previous = "";
702712
for (id, en, ja) in CATALOG {
@@ -713,6 +723,7 @@ mod tests {
713723
}
714724

715725
#[test]
726+
/// Verify Japanese locale variants and English fallback for unsupported locales.
716727
fn japanese_tags_resolve_and_other_tags_do_not() {
717728
for tag in ["ja", "ja-JP", "ja_JP.UTF-8", "ja-JP-mac", "JA-jp"] {
718729
assert_eq!(resolve_tag(tag), Resolved::Ja, "{tag}");
@@ -728,6 +739,7 @@ mod tests {
728739
}
729740

730741
#[test]
742+
/// Accept System, English and Japanese codes while rejecting unsupported choices.
731743
fn the_language_command_accepts_the_three_choices() {
732744
assert_eq!(LanguageChoice::parse("system"), Some(LanguageChoice::System));
733745
assert_eq!(LanguageChoice::parse("en"), Some(LanguageChoice::En));
@@ -739,6 +751,7 @@ mod tests {
739751
}
740752

741753
#[test]
754+
/// Preserve saved Japanese choices and use System for unrecognized saved codes.
742755
fn a_saved_choice_round_trips_and_an_unknown_code_falls_back() {
743756
let raw = serde_json::to_string(&LanguageChoice::Ja).expect("serialize");
744757
assert_eq!(raw, "\"ja\"");
@@ -749,6 +762,7 @@ mod tests {
749762
}
750763

751764
#[test]
765+
/// Fill named message arguments without losing unresolved placeholders.
752766
fn placeholders_keep_their_names() {
753767
let ja = text(Resolved::Ja, "status.slide_of");
754768
assert_eq!(fill(ja, &[("n", "2"), ("m", "9")]), "スライド 2/9");
@@ -758,6 +772,7 @@ mod tests {
758772
}
759773

760774
#[test]
775+
/// Translate tab captions while retaining English identifiers and unknown-tab fallback.
761776
fn tab_titles_follow_the_language_and_keep_the_english_id() {
762777
assert_eq!(tab_label(Resolved::Ja, "File"), "ファイル");
763778
assert_eq!(tab_label(Resolved::Ja, "Home"), "ホーム");
@@ -847,6 +862,7 @@ mod tests {
847862
}
848863

849864
#[test]
865+
/// Keep preset identities and preserve braces inside user-provided message arguments.
850866
fn preset_labels_keep_model_identity_and_user_placeholders_are_literal() {
851867
for &(name, _, _) in deckcraft_model::defaults::SLIDE_SIZES {
852868
assert_eq!(slide_size_label(Resolved::En, name), name);

0 commit comments

Comments
 (0)