Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion crates/ui-egui/src/i18n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,14 @@ impl Language {
self.translated(text).unwrap_or_else(|| text.rsplit_once('|').map_or(text, |(_, label)| label))
}

/// The catalog's own translation of `text`, or `None` when it falls back to English.
/// A ribbon tab's name. Where a language names the tab differently from a command with the
/// same English label (Russian: the Insert tab is «Вставка», the Insert button «Вставить»), its
/// catalog keys the tab `Tab|name`; every other language falls back to the plain label.
pub fn tr_tab(self, tab: &str) -> &str {
self.translated(&format!("Tab|{tab}")).unwrap_or_else(|| self.tr(tab))
}

/// The catalog entry for `text`, if this language has one.
fn translated(self, text: &str) -> Option<&'static str> {
match self {
Self::En => None,
Expand Down Expand Up @@ -451,6 +458,13 @@ mod tests {
assert_eq!(language.tr("Sheet1!A1"), "Sheet1!A1");
assert_eq!(language.tr("Not in any catalog|Untranslated"), "Untranslated");
}
// The Insert tab and the Insert command have different Russian names; elsewhere the tab
// name is the plain label.
assert_eq!(Language::Ru.tr_tab("Insert"), "Вставка");
assert_eq!(Language::Ru.tr("Insert"), "Вставить");
assert_eq!(Language::Ru.tr_tab("Data"), "Данные");
assert_eq!(Language::Es.tr_tab("Insert"), Language::Es.tr("Insert"));
assert_eq!(Language::En.tr_tab("Insert"), "Insert");
// A `context|label` key shows only its label in English.
assert_eq!(Language::En.tr("Page Layout|Orientation"), "Orientation");
// Errors drop the `command `id`:` prefix before translating; an untranslated one stays whole.
Expand Down
Loading
Loading