mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-02 06:36:51 -06:00
Merge #272: i18n: translate the whole interface into Japanese
Conflict: crates/ui-egui/src/i18n.rs: kept both module declarations (mod it; mod ja;)
This commit is contained in:
@@ -5,6 +5,7 @@ use std::{collections::HashMap, sync::OnceLock};
|
||||
|
||||
mod ar;
|
||||
mod it;
|
||||
mod ja;
|
||||
mod pt_br;
|
||||
mod uk;
|
||||
|
||||
@@ -2808,6 +2809,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();
|
||||
@@ -2816,6 +2818,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);
|
||||
}
|
||||
@@ -2872,7 +2881,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
Reference in New Issue
Block a user