i18n: translate the whole interface into Japanese (#272)
Japanese covered menu titles, about 140 menu items and panel names. Of the
1,391 rows of the shared table, about 1,240 carried the English text in
their Japanese column, so every dialog, panel field, tooltip and status
line was still English.
Add i18n/ja.rs, a full catalog in the shape of ar.rs and pt_br.rs. It has a
row for every key of the shared table and of the Arabic and Brazilian
Portuguese tables (1,430 strings), keeps the existing Japanese menu words
unchanged, and adds 213 rows for labels the code passes to tr() but no table
had: command labels without their trailing ellipsis (the shortcut list), menu
paths (the menu list), special characters, colour-profile names and a few
field labels.
tr("ja", ..) looks in ja::TABLE first and falls back to the shared table's
Japanese column. The shared table is left as it is.
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e904bd6057
commit
620a27d645
|
|
@ -4,6 +4,7 @@
|
|||
use std::{collections::HashMap, sync::OnceLock};
|
||||
|
||||
mod ar;
|
||||
mod ja;
|
||||
mod pt_br;
|
||||
mod uk;
|
||||
|
||||
|
|
@ -2752,6 +2753,7 @@ fn column(lang: &str) -> Option<usize> {
|
|||
|
||||
/// `s` in `lang` (English, or the string itself, when there's no translation).
|
||||
pub fn tr<'a>(lang: &str, s: &'a str) -> &'a str {
|
||||
static JAPANESE: OnceLock<HashMap<&'static str, &'static str>> = OnceLock::new();
|
||||
static TRANSLATIONS: OnceLock<HashMap<&'static str, [&'static str; 5]>> = OnceLock::new();
|
||||
static ARABIC: OnceLock<HashMap<&'static str, &'static str>> = OnceLock::new();
|
||||
static UKRAINIAN: OnceLock<HashMap<&'static str, &'static str>> = OnceLock::new();
|
||||
|
|
@ -2759,6 +2761,13 @@ pub fn tr<'a>(lang: &str, s: &'a str) -> &'a str {
|
|||
if lang == "ar" {
|
||||
return ARABIC.get_or_init(|| ar::TABLE.iter().copied().collect()).get(s).copied().unwrap_or(s);
|
||||
}
|
||||
// The Japanese table covers the whole interface; the shared table's Japanese column is the fallback
|
||||
// for keys added there after it.
|
||||
if lang == "ja"
|
||||
&& let Some(text) = JAPANESE.get_or_init(|| ja::TABLE.iter().copied().collect()).get(s).copied()
|
||||
{
|
||||
return text;
|
||||
}
|
||||
if lang == "pt-br" {
|
||||
return PORTUGUESE_BR.get_or_init(|| pt_br::TABLE.iter().copied().collect()).get(s).copied().unwrap_or(s);
|
||||
}
|
||||
|
|
@ -2812,7 +2821,10 @@ mod tests {
|
|||
fn cached_lookup_preserves_every_translation_across_language_switches() {
|
||||
for (key, translations) in TABLE {
|
||||
for (lang, expected) in ["de", "fr", "es", "ja", "zh"].into_iter().zip(translations) {
|
||||
assert_eq!(tr(lang, key), *expected, "{lang}: {key}");
|
||||
// `ja::TABLE` translates the whole interface and wins over the shared Japanese column.
|
||||
if lang != "ja" {
|
||||
assert_eq!(tr(lang, key), *expected, "{lang}: {key}");
|
||||
}
|
||||
}
|
||||
assert_eq!(tr("", key), *key);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue