mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Brazilian Portuguese UI translation (pt-br) (#700)
* Brazilian Portuguese UI translation (pt-br) Add a pt-br catalog covering every key in the existing catalogs (2,492 entries), register it as "Português (Brasil)" with Portuguese plural rules, and resolve pt, pt-BR and pt-PT locales to it. i18n coverage 1404/1404. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Keyboard Shortcuts dialog: show menus and commands in the UI language The command list showed the raw English menu paths and labels while the rest of the dialog was translated. Translate them the way the menus do (tr / tr_id); search matches the translated and the English names, like the command palette. Also rustfmt the pt-br registry row. Co-Authored-By: Claude Opus 5.5 <[email protected]> * pt-br: gate it in xtask i18n-coverage (from #637, thanks @RicSchonfelder); licence note covers German too Co-Authored-By: RicSchonfelder <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Brandon Thomas <[email protected]> Co-authored-by: RicSchonfelder <[email protected]>
This commit is contained in:
8 files changed
+2592
-10
No files matched your search
@@ -12,6 +12,7 @@ next to them.
|
||||
|---|---|---|---|---|
|
||||
| `crates/ui-egui/src/i18n/de.tsv` | German UI translations | PhotoCraft contributors | Original translations of PhotoCraft's English labels | MIT OR Apache-2.0, [`LICENSE-translations.txt`](crates/ui-egui/src/i18n/LICENSE-translations.txt) |
|
||||
| `crates/ui-egui/src/i18n/ko.tsv` | Korean UI translations | PhotoCraft contributors | Original translations of PhotoCraft's English labels | MIT OR Apache-2.0, [`LICENSE-translations.txt`](crates/ui-egui/src/i18n/LICENSE-translations.txt) |
|
||||
| `crates/ui-egui/src/i18n/pt-br.tsv` | Brazilian Portuguese UI translations | PhotoCraft contributors | Original translations of PhotoCraft's English labels | MIT OR Apache-2.0, [`LICENSE-translations.txt`](crates/ui-egui/src/i18n/LICENSE-translations.txt) |
|
||||
| `assets/fonts/Inter-Regular.ttf`, `Inter-Medium.ttf`, `Inter-SemiBold.ttf` | Inter 4.001 (UI font) | The Inter Project Authors (Rasmus Andersson) | <https://github.com/rsms/inter> | SIL OFL 1.1, [`assets/fonts/OFL-Inter.txt`](assets/fonts/OFL-Inter.txt) |
|
||||
| `assets/fonts/JetBrainsMono-Regular.ttf` | JetBrains Mono 2.305 (numeric font) | The JetBrains Mono Project Authors | <https://github.com/JetBrains/JetBrainsMono> | SIL OFL 1.1, [`assets/fonts/OFL-JetBrainsMono.txt`](assets/fonts/OFL-JetBrainsMono.txt) |
|
||||
| `assets/icons/*.svg` except `slice-knife.svg`, `eraser-background.svg` and `eraser-magic.svg` (109 files) | Lucide icons | Lucide Icons and Contributors | <https://github.com/lucide-icons/lucide> (`icons/<name>.svg`; `align-*` are now named `text-align-*` upstream) | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
PhotoCraft's Korean UI translation catalog is licensed under MIT OR Apache-2.0,
|
||||
at your option. The full license texts are in ../../../../LICENSE-MIT and
|
||||
../../../../LICENSE-APACHE.
|
||||
PhotoCraft's Korean, German and Brazilian Portuguese UI translation catalogs are licensed
|
||||
under MIT OR Apache-2.0, at your option. The full license texts are in ../../../../LICENSE-MIT
|
||||
and ../../../../LICENSE-APACHE.
|
||||
|
||||
Korean translations: PhotoCraft contributors, original translations of
|
||||
PhotoCraft's English labels; no proprietary translation resources were used.
|
||||
|
||||
German translations: PhotoCraft contributors, original translations of
|
||||
PhotoCraft's English labels; no proprietary translation resources were used.
|
||||
|
||||
Brazilian Portuguese translations: PhotoCraft contributors, original translations of
|
||||
PhotoCraft's English labels; no proprietary translation resources were used.
|
||||
@@ -176,6 +176,26 @@ fn preferences_preview_does_not_commit_until_applied_and_survives_reload() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keyboard_shortcuts_list_commands_in_the_selected_language() {
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("prefs.set", json!({"path": "interface.language", "value": "pt-br"})).expect("language");
|
||||
h.step();
|
||||
let ctx = h.ctx.clone();
|
||||
let id = crate::menus::invoke(h.state_mut(), &ctx, "edit.keyboardShortcuts", json!({})).expect("dialog")["dialog"].as_u64().expect("id");
|
||||
// Search matches the translated label and the English one.
|
||||
for filter in ["salvar como", "save as"] {
|
||||
h.state_mut().ui.dialog_mut(id).expect("shortcuts").fields.insert("filter".into(), json!(filter));
|
||||
h.run_steps(3);
|
||||
let text = drawn_text(&h);
|
||||
assert!(text.iter().any(|text| text == "Arquivo"), "{filter}: the menu heading must be translated");
|
||||
assert!(text.iter().any(|text| text.trim() == "Salvar como…"), "{filter}: the command must be translated: {text:?}");
|
||||
assert!(!text.iter().any(|text| text.trim() == "Save As…"), "{filter}: no English command labels");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn drawn_text(h: &egui_kittest::Harness<'_, PhotocraftApp>) -> Vec<String> {
|
||||
fn collect(shape: &egui::Shape, text: &mut Vec<String>) {
|
||||
match shape {
|
||||
|
||||
@@ -74,8 +74,13 @@ fn plural_fr(n: u64) -> usize {
|
||||
usize::from(n > 1)
|
||||
}
|
||||
|
||||
/// Portuguese: 0 and 1 take the singular, everything else the plural.
|
||||
fn plural_pt(n: u64) -> usize {
|
||||
usize::from(n > 1)
|
||||
}
|
||||
|
||||
/// The registry. English first: it is the fallback and the source language.
|
||||
pub static LANGUAGES: [LangInfo; 11] = [
|
||||
pub static LANGUAGES: [LangInfo; 12] = [
|
||||
LangInfo { code: "en", name: "English", source: "", plural: plural_one_other, complete_menus: false, catalog: OnceLock::new() },
|
||||
LangInfo { code: "ja", name: "日本語", source: include_str!("ja.tsv"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo {
|
||||
@@ -93,6 +98,15 @@ pub static LANGUAGES: [LangInfo; 11] = [
|
||||
LangInfo { code: "id", name: "Bahasa Indonesia", source: include_str!("id.tsv"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "ko", name: "한국어", source: include_str!("ko.tsv"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "de", name: "Deutsch", source: include_str!("de.tsv"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
// Brazilian Portuguese; `pt`, `pt-BR` and `pt-PT` locales all resolve here (see `candidates`).
|
||||
LangInfo {
|
||||
code: "pt-br",
|
||||
name: "Português (Brasil)",
|
||||
source: include_str!("pt-br.tsv"),
|
||||
plural: plural_pt,
|
||||
complete_menus: true,
|
||||
catalog: OnceLock::new(),
|
||||
},
|
||||
];
|
||||
|
||||
impl LangInfo {
|
||||
@@ -174,6 +188,10 @@ fn candidates(tag: &str) -> Vec<String> {
|
||||
let script = if parts.iter().any(|p| matches!(*p, "tw" | "hk" | "mo")) { "zh-hant" } else { "zh-hans" };
|
||||
out.insert(out.len() - 1, script.to_string());
|
||||
}
|
||||
if primary == "pt" && !out.iter().any(|c| c == "pt-br") {
|
||||
// The only Portuguese catalog is Brazilian; other regions use it rather than English.
|
||||
out.insert(out.len() - 1, "pt-br".to_string());
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
@@ -431,6 +449,19 @@ mod tests {
|
||||
assert_eq!(trn(es, 3, "{n} item", "{n} items"), "3 elementos");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn brazilian_portuguese_resolves_and_pluralises() {
|
||||
let pt = Lang::from_code("pt-br").expect("pt-br registered");
|
||||
for tag in ["pt", "pt-BR", "pt_BR.UTF-8", "pt-PT", "pt_PT.UTF-8"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(pt), "{tag}");
|
||||
}
|
||||
assert_eq!(candidates("pt_PT"), ["pt-pt", "pt-br", "pt"]);
|
||||
assert_eq!(tr(pt, "Layer"), "Camada");
|
||||
assert_eq!(trn(pt, 0, "{n} item", "{n} items"), "0 item");
|
||||
assert_eq!(trn(pt, 1, "{n} item", "{n} items"), "1 item");
|
||||
assert_eq!(trn(pt, 2, "{n} item", "{n} items"), "2 itens");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lookups_fall_back_to_english() {
|
||||
assert_eq!(tr(JA(), "no such label"), "no such label");
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1059,6 +1059,11 @@ fn shortcuts_body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map<String
|
||||
let mut capture = f.get("capture").and_then(Value::as_bool).unwrap_or(false);
|
||||
let mut message = f.get("message").and_then(Value::as_str).unwrap_or("").to_string();
|
||||
let items = shortcut_items(app);
|
||||
// Menu path and command label as shown in the menus, in the UI language.
|
||||
let shown = |id: &str, label: &str, path: &[String]| -> (Vec<String>, String) {
|
||||
let lang = crate::i18n::current();
|
||||
(path.iter().map(|p| crate::i18n::tr(lang, p).to_string()).collect(), crate::i18n::tr_id(lang, id, label).to_string())
|
||||
};
|
||||
let eff = |overrides: &BTreeMap<String, String>, id: &str, def: &Option<String>| -> Option<String> {
|
||||
match overrides.get(id) {
|
||||
Some(s) if s.is_empty() => None,
|
||||
@@ -1088,7 +1093,10 @@ fn shortcuts_body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map<String
|
||||
let clash: Vec<String> = items
|
||||
.iter()
|
||||
.filter(|(id, _, _, def)| *id != selected && eff(&overrides, id, def).as_deref().and_then(prefs::normalize_shortcut) == Some(sc.clone()))
|
||||
.map(|(_, label, path, _)| format!("{} › {}", path.join(" › "), label.trim_end_matches('…')))
|
||||
.map(|(id, label, path, _)| {
|
||||
let (path, label) = shown(id, label, path);
|
||||
format!("{} › {}", path.join(" › "), label.trim_end_matches('…'))
|
||||
})
|
||||
.collect();
|
||||
overrides.insert(selected.clone(), sc.clone());
|
||||
message = if clash.is_empty() {
|
||||
@@ -1106,14 +1114,16 @@ fn shortcuts_body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map<String
|
||||
egui::Grid::new("shortcut-grid").num_columns(3).spacing([12.0, 3.0]).striped(true).show(ui, |ui| {
|
||||
for (id, label, path, def) in &items {
|
||||
let cur = eff(&overrides, id, def);
|
||||
let hay = format!("{} {} {}", path.join(" "), label, cur.clone().unwrap_or_default()).to_ascii_lowercase();
|
||||
let (shown_path, shown_label) = shown(id, label, path);
|
||||
// Match what is shown and the English name (commands are documented in English).
|
||||
let hay = format!("{} {} {} {} {}", shown_path.join(" "), shown_label, path.join(" "), label, cur.clone().unwrap_or_default()).to_lowercase();
|
||||
if !needle.is_empty() && !hay.contains(&needle) && !id.to_ascii_lowercase().contains(&needle) {
|
||||
continue;
|
||||
}
|
||||
if tab == 0 && path.is_empty() && def.is_none() && cur.is_none() {
|
||||
continue;
|
||||
}
|
||||
let top = path.first().cloned().unwrap_or_else(|| tl!("Other").into());
|
||||
let top = shown_path.first().cloned().unwrap_or_else(|| tl!("Other").into());
|
||||
if top != last_top {
|
||||
ui.label(RichText::new(&top).font(crate::theme::semibold(12.5)).color(t.text));
|
||||
ui.label("");
|
||||
@@ -1121,7 +1131,10 @@ fn shortcuts_body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map<String
|
||||
ui.end_row();
|
||||
last_top = top;
|
||||
}
|
||||
let name = if path.len() > 1 { format!("{} › {}", path[1..].join(" › "), label) } else { label.clone() };
|
||||
let name = match shown_path.get(1..) {
|
||||
Some(rest) if !rest.is_empty() => format!("{} › {}", rest.join(" › "), shown_label),
|
||||
_ => shown_label,
|
||||
};
|
||||
let sel = selected == *id;
|
||||
if ui.selectable_label(sel, RichText::new(format!(" {name}")).color(t.text_dim)).clicked() {
|
||||
selected = id.clone();
|
||||
|
||||
@@ -19,6 +19,7 @@ contextual, command-ID and plural translations; missing entries fall back to Eng
|
||||
| Čeština | `cs` | one / few / other |
|
||||
| Deutsch | `de` | one / other |
|
||||
| Bahasa Indonesia | `id` | one form |
|
||||
| Português (Brasil) | `pt-br` | singular for 0 and 1 / plural for 2+ |
|
||||
|
||||
Every non-English catalog covers the current menu labels, `tl!` literals, blend mode names,
|
||||
and generated preference labels. Tests enforce that coverage. This does not include every
|
||||
@@ -36,7 +37,8 @@ documents, undo history and tools remain available throughout a language change.
|
||||
The existing preference store saves the selection for future launches. `auto` follows the
|
||||
native system locale; an unsupported code follows the same fallback. Regional tags such as
|
||||
`fr-CA`, `ko-KR` and `zh-CN` resolve to the corresponding registered catalog. Traditional and
|
||||
Simplified Chinese remain distinct.
|
||||
Simplified Chinese remain distinct. Every Portuguese locale (`pt`, `pt-BR`, `pt-PT`) uses the
|
||||
Brazilian Portuguese catalog.
|
||||
|
||||
Agents use the existing `prefs.set` command through CLI, MCP or the desktop control channel:
|
||||
|
||||
|
||||
@@ -559,7 +559,7 @@ mod tests {
|
||||
fn source_key_set_is_covered_by_complete_catalogs() {
|
||||
let root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap_or(Path::new("."));
|
||||
let keys = source_keys(root).unwrap_or_default();
|
||||
for (code, path) in [("ja", "ja.tsv"), ("zh-hant", "zh-hant.tsv"), ("es", "es.tsv"), ("ru", "ru.tsv"), ("cs", "cs.tsv"), ("de", "de.tsv")] {
|
||||
for (code, path) in [("ja", "ja.tsv"), ("zh-hant", "zh-hant.tsv"), ("es", "es.tsv"), ("ru", "ru.tsv"), ("cs", "cs.tsv"), ("de", "de.tsv"), ("pt-br", "pt-br.tsv")] {
|
||||
let catalog_path = root.join("crates/ui-egui/src/i18n").join(path);
|
||||
let text = fs::read_to_string(&catalog_path).unwrap_or_default();
|
||||
let translations = parse_catalog(&catalog_path, &text).unwrap_or_default();
|
||||
|
||||
Reference in new issue
Block a user