Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

i18n: Turkish section titles and in-sentence labels keep İ and ı (#3114)

ogzhnklvz13c86b40e84b
diff --git a/crates/ui-egui/src/i18n/mod.rs b/crates/ui-egui/src/i18n/mod.rs
index 5bb2889c9..0d097f6cd 100644
--- a/crates/ui-egui/src/i18n/mod.rs
+++ b/crates/ui-egui/src/i18n/mod.rs
@@ -411,7 +411,38 @@ pub fn set_current(lang: Lang) {
/// `label` as it reads inside a sentence ("add a text box"): lowercased, except in languages
/// that capitalise nouns (German), where lowercasing would misspell it.
pub fn in_sentence(label: &str) -> std::borrow::Cow<'_, str> {
- if current().code() == "de" { std::borrow::Cow::Borrowed(label) } else { std::borrow::Cow::Owned(label.to_lowercase()) }
+ match current().code() {
+ "de" => std::borrow::Cow::Borrowed(label),
+ "tr" => std::borrow::Cow::Owned(label.chars().flat_map(lower_turkish).collect()),
+ _ => std::borrow::Cow::Owned(label.to_lowercase()),
+ }
+}
+
+/// The translation of `english` in upper case, for section titles. Rust's case mapping knows no
+/// language, and Turkish has a dotted and a dotless i (`i` ↔ `İ`, `ı` ↔ `I`): "Gelişmiş" must
+/// become "GELİŞMİŞ", not "GELIŞMIŞ". A label without a Turkish row is still English and keeps
+/// the English rule.
+pub fn upper_label(english: &str) -> String {
+ let lang = current();
+ let shown = tr(lang, english);
+ if lang.code() == "tr" && has(lang, english) { shown.chars().flat_map(upper_turkish).collect() } else { shown.to_uppercase() }
+}
+
+fn upper_turkish(c: char) -> std::char::ToUppercase {
+ match c {
+ 'i' => 'İ'.to_uppercase(),
+ 'ı' => 'I'.to_uppercase(),
+ c => c.to_uppercase(),
+ }
+}
+
+fn lower_turkish(c: char) -> std::char::ToLowercase {
+ match c {
+ // `İ`.to_lowercase() is "i" plus a combining dot above.
+ 'İ' => 'i'.to_lowercase(),
+ 'I' => 'ı'.to_lowercase(),
+ c => c.to_lowercase(),
+ }
}
pub fn current() -> Lang {
@@ -1961,6 +1992,20 @@ mod tests {
set_current(Lang::EN);
}
+ #[test]
+ fn turkish_keeps_its_dotted_and_dotless_i_when_changing_case() {
+ set_current(Lang::from_code("tr").expect("tr registered"));
+ assert_eq!(upper_label("Advanced"), "GELİŞMİŞ");
+ assert_eq!(upper_label("Signatures"), "İMZALAR");
+ // A label with no Turkish row is still English and keeps the English rule.
+ assert_eq!(upper_label("Untranslated title"), "UNTRANSLATED TITLE");
+ assert_eq!(in_sentence("İmza Alanı"), "imza alanı");
+ assert_eq!(in_sentence("Işık"), "ışık");
+ set_current(Lang::EN);
+ assert_eq!(upper_label("Advanced"), "ADVANCED");
+ assert_eq!(in_sentence("Image"), "image");
+ }
+
#[test]
fn german_certificate_subject_has_a_distinct_context() {
let de = Lang::from_code("de").expect("de registered");
diff --git a/crates/ui-egui/src/print_ui.rs b/crates/ui-egui/src/print_ui.rs
index 4e0f06588..f4e039d51 100644
--- a/crates/ui-egui/src/print_ui.rs
+++ b/crates/ui-egui/src/print_ui.rs
@@ -1103,7 +1103,7 @@ pub(crate) fn body(
);
// Advanced (Acrobat's Advanced Print Setup): print as image. Folded unless it is on.
ui.add_space(6.0);
- egui::CollapsingHeader::new(egui::RichText::new(tl!("Advanced").to_uppercase()).font(theme::semibold(10.5)).color(t.text_faint))
+ egui::CollapsingHeader::new(egui::RichText::new(crate::i18n::upper_label("Advanced")).font(theme::semibold(10.5)).color(t.text_faint))
.id_salt("print-advanced")
.default_open(d.as_image)
.show(ui, |ui| {
diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs
index 4f5aaa79b..c39f4cf05 100644
--- a/crates/ui-egui/src/widgets.rs
+++ b/crates/ui-egui/src/widgets.rs
@@ -272,7 +272,7 @@ pub fn section_title(ui: &mut egui::Ui, text: &str) {
let t = Tokens::get(ui.ctx());
ui.add_space(10.0);
// Section titles across every panel go through here, so one translation point covers them.
- ui.label(egui::RichText::new(tl!(text).to_uppercase()).font(theme::semibold(10.5)).color(t.text_faint).extra_letter_spacing(0.6));
+ ui.label(egui::RichText::new(crate::i18n::upper_label(text)).font(theme::semibold(10.5)).color(t.text_faint).extra_letter_spacing(0.6));
ui.add_space(2.0);
}