mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-19 08:51:41 +01:00
feat(i18n): look up translations through the craft-i18n crate
The i18n module becomes a thin Lang wrapper over craft_i18n::I18n and the catalogs embedded from craft-i18n. Plurals use trn_plain and PhotoCraft keeps its own fmt; @id rows come only from PhotoCraft's own rows that keep the label's shape. Detection, PHOTOCRAFT_LOCALE, tag bounds and the 35 offered languages are unchanged. Serbian: sr, sr-RS, sr-Cyrl-RS and sr-ME reach sr-latn, the only Serbian catalog, and a saved interface.language "sr" migrates to "sr-latn". The menu completeness test becomes a report that never fails, and `cargo xtask i18n-coverage` is replaced by `cargo xtask i18n-report`, which reads CRAFT_I18N_DIR through the crate. Docs describe the new system. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0c628208b5
commit
9dd39df78d
20 files changed
+815
-795
No files matched your search
Generated
+1
@@ -9742,6 +9742,7 @@ name = "xtask"
|
||||
version = "0.20.1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-i18n",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
|
||||
+2
-1
@@ -86,7 +86,8 @@ Rows and evidence: [target-app-parity › Feature areas](docs/target-app-parity.
|
||||
|
||||
## Languages
|
||||
|
||||
Measured with the `cargo xtask i18n-coverage` key universe (1,608 keys). `partial` everywhere
|
||||
Measured before the craft-i18n cutover with the former `cargo xtask i18n-coverage` key universe
|
||||
(1,608 keys); `cargo xtask i18n-report` now reports coverage. `partial` everywhere
|
||||
because engine messages are still English. Detail: [localization-parity](docs/localization-parity.md).
|
||||
|
||||
| Language | Code | UI strings | Status |
|
||||
|
||||
@@ -1637,6 +1637,13 @@ impl Session {
|
||||
// A partially migrated file may already contain a newer theme selection (#5139).
|
||||
interface.entry(slot).or_insert_with(|| json!(theme.name()));
|
||||
}
|
||||
// The Serbian interface catalog was `sr`; since the catalogs moved to craft-i18n it is
|
||||
// `sr-latn`, the same Latin text. A saved `sr` loads as `sr-latn` and is saved that way next.
|
||||
if let Some(language) = v.get_mut("interface").and_then(|interface| interface.get_mut("language"))
|
||||
&& language.as_str().is_some_and(|code| code.eq_ignore_ascii_case("sr"))
|
||||
{
|
||||
*language = json!("sr-latn");
|
||||
}
|
||||
let color = v.as_object_mut().and_then(|m| m.remove("colorSettings"));
|
||||
let presets = v.as_object_mut().and_then(|m| m.remove("presets"));
|
||||
let mut invalid = Vec::new();
|
||||
|
||||
@@ -116,6 +116,25 @@ fn appearance_defaults_and_legacy_theme_migrate() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Serbian interface language was saved as `sr` before the catalogs moved to craft-i18n,
|
||||
/// where it is `sr-latn`: a saved `sr` (any case) loads as `sr-latn` and is saved as `sr-latn`.
|
||||
/// Other codes, and `auto`, load as saved.
|
||||
#[test]
|
||||
fn a_saved_serbian_language_migrates_to_sr_latn() {
|
||||
for saved in ["sr", "SR"] {
|
||||
let mut s = Session::new();
|
||||
s.load_prefs_json(&json!({"interface": {"language": saved}}).to_string()).unwrap();
|
||||
assert_eq!(s.prefs().interface.language, "sr-latn", "{saved}");
|
||||
let resaved: Value = serde_json::from_str(&s.prefs_to_json()).unwrap();
|
||||
assert_eq!(resaved["interface"]["language"], "sr-latn", "saved under the new code");
|
||||
}
|
||||
for kept in ["sr-latn", "bs", "auto", "en"] {
|
||||
let mut s = Session::new();
|
||||
s.load_prefs_json(&json!({"interface": {"language": kept}}).to_string()).unwrap();
|
||||
assert_eq!(s.prefs().interface.language, kept);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_theme_migration_preserves_saved_theme_slots() {
|
||||
for (legacy, slot, saved) in [("proMedium", "darkTheme", "solarizedDark"), ("studioLight", "lightTheme", "adwaita")] {
|
||||
|
||||
+238
-266
@@ -1,17 +1,29 @@
|
||||
//! UI localisation. Strings in code stay English and are the default lookup keys; a per-language
|
||||
//! catalog (`*.tsv`, see `ja.tsv` for the format) maps them to display text at render time. Command
|
||||
//! ids, menu paths used for logic, the control channel, the CLI and MCP never see translated text,
|
||||
//! so agents and scripts are unaffected. A string without a translation is shown in English.
|
||||
//! UI localisation. Strings in code stay English and are the default lookup keys; the craft-i18n
|
||||
//! catalogs map them to display text at render time. Command ids, menu paths used for logic, the
|
||||
//! control channel, the CLI and MCP never see translated text, so agents and scripts are
|
||||
//! unaffected. A string without a translation is shown in English, and a missing translation never
|
||||
//! fails a build, a test or a release.
|
||||
//!
|
||||
//! The catalogs live in [storytold/craft-i18n](https://github.com/storytold/craft-i18n)
|
||||
//! (`locales/<code>/common.tsv`, shared by the Crafting Apps, and `photocraft.tsv`), not in this
|
||||
//! repository. `build.rs` embeds them from `CRAFT_I18N_DIR` (CI and releases check out the commit
|
||||
//! in `craft-i18n.rev`); without it the build is English only. Lookup, fallback (PhotoCraft's rows
|
||||
//! over shared ones), plural forms (CLDR) and language names are the `craft-i18n` crate's
|
||||
//! (craft-libs). Which languages are offered, how the system locale picks one, reading direction
|
||||
//! and `{name}` placeholders stay here.
|
||||
//!
|
||||
//! # Adding or changing a translation
|
||||
//! In craft-i18n: add rows to `locales/<code>/photocraft.tsv` (its `docs/integration.md`). They
|
||||
//! show here once `craft-i18n.rev` moves to a commit that has them. A feature PR here adds the
|
||||
//! English only; `cargo xtask i18n-report` lists what each language lacks.
|
||||
//!
|
||||
//! # Adding a language
|
||||
//! 1. Add `xx.tsv` next to `ja.tsv` (copy its header; translate from the *meaning* of the English
|
||||
//! text, clean-room, see `ja.tsv`).
|
||||
//! 2. Add one row to [`LANGUAGES`] (code, native name, catalog, plural rule).
|
||||
//! 1. craft-i18n gets `locales/<code>/photocraft.tsv` with its `@id language.name` row.
|
||||
//! 2. Add one row to [`LANGUAGES`].
|
||||
//!
|
||||
//! That is all: the Preferences dropdown, the system-locale match and the catalog tests (parse,
|
||||
//! placeholders, plural forms) pick it up from the registry. A right-to-left language (Arabic,
|
||||
//! Hebrew, Persian, Urdu, see [`dir_for_code`]) also mirrors the window's chrome
|
||||
//! ([`crate::direction`]).
|
||||
//! That is all: the Preferences dropdown and the system-locale match pick it up from the registry.
|
||||
//! A right-to-left language (Arabic, Hebrew, Persian, Urdu, see [`dir_for_code`]) also mirrors the
|
||||
//! window's chrome ([`crate::direction`]).
|
||||
//!
|
||||
//! # Looking strings up
|
||||
//! - [`tr`]: a plain string. [`tr_ctx`]: when one English word needs different translations.
|
||||
@@ -21,7 +33,6 @@
|
||||
//! translators may reorder placeholders freely.
|
||||
|
||||
mod casing;
|
||||
mod catalog;
|
||||
mod system;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -29,26 +40,32 @@ pub(crate) use system::with_decimal_separator;
|
||||
pub use system::{decimal_separator, system_lang};
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::sync::OnceLock;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::{LazyLock, OnceLock};
|
||||
|
||||
use catalog::Catalog;
|
||||
use craft_i18n::I18n;
|
||||
|
||||
/// One supported UI language.
|
||||
include!(concat!(env!("OUT_DIR"), "/craft_i18n.rs"));
|
||||
|
||||
/// The embedded catalogs, offering exactly the languages in [`LANGUAGES`]. Built on first use; a
|
||||
/// locale is parsed on its first lookup.
|
||||
static I18N: LazyLock<I18n> = LazyLock::new(|| {
|
||||
let offered: Vec<&str> = LANGUAGES.iter().map(|l| l.code).collect();
|
||||
let (i18n, problems) = I18n::new(CRAFT_I18N, &offered);
|
||||
for problem in problems {
|
||||
log::warn!("interface catalogs: {problem}");
|
||||
}
|
||||
i18n
|
||||
});
|
||||
|
||||
/// One UI language PhotoCraft offers, when its catalogs are embedded: what the app needs beyond
|
||||
/// them. Its name and translations come from craft-i18n.
|
||||
pub struct LangInfo {
|
||||
/// BCP 47 code, lowercase (`ja`, `zh-hans`, `pt-br`). Also the `interface.language` value.
|
||||
/// BCP 47 code, lowercase (`ja`, `zh-hans`, `pt-br`, `sr-latn`). Also the `interface.language`
|
||||
/// value and the craft-i18n locale.
|
||||
pub code: &'static str,
|
||||
/// The language's name in itself, shown in the Preferences dropdown.
|
||||
pub name: &'static str,
|
||||
/// Catalog file contents, raw-deflated by build.rs (empty for the built-in English); see
|
||||
/// [`LangInfo::text`].
|
||||
pub source: &'static [u8],
|
||||
/// Plural form index for a count (English: 0 = one, 1 = other; Japanese, Chinese and Hungarian: always 0;
|
||||
/// Czech: 0 = one, 1 = few (2–4), 2 = other; Russian, Ukrainian and Bosnian: 0 = one (1, 21 …), 1 = few (2–4, 22–24 …), 2 = other; French: 0 = one (0 and 1), 1 = other). A catalog's `@plural` entries list one form per
|
||||
/// index.
|
||||
pub plural: fn(u64) -> usize,
|
||||
/// Does the catalog cover every menu string? (`cargo xtask i18n-coverage` lists what it lacks)
|
||||
/// Does the catalog cover every menu string? (`cargo xtask i18n-report` lists what it lacks)
|
||||
pub complete_menus: bool,
|
||||
catalog: OnceLock<Catalog>,
|
||||
}
|
||||
|
||||
/// A script's reading direction.
|
||||
@@ -68,268 +85,126 @@ pub fn dir_for_code(code: &str) -> Dir {
|
||||
if RTL_LANGUAGES.iter().any(|l| l.eq_ignore_ascii_case(primary)) { Dir::Rtl } else { Dir::Ltr }
|
||||
}
|
||||
|
||||
fn plural_one_other(n: u64) -> usize {
|
||||
usize::from(n != 1)
|
||||
}
|
||||
/// How many languages [`LANGUAGES`] lists.
|
||||
const LANGUAGE_COUNT: usize = 35;
|
||||
|
||||
fn plural_none(_: u64) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
fn plural_russian(n: u64) -> usize {
|
||||
match (n % 10, n % 100) {
|
||||
(1, 11..=19) => 2,
|
||||
(1, _) => 0,
|
||||
(2..=4, 11..=19) => 2,
|
||||
(2..=4, _) => 1,
|
||||
_ => 2,
|
||||
}
|
||||
}
|
||||
|
||||
/// Czech: 1 → one, 2–4 → few, everything else (0, 5+) → other.
|
||||
fn plural_cs(n: u64) -> usize {
|
||||
match n {
|
||||
1 => 0,
|
||||
2..=4 => 1,
|
||||
_ => 2,
|
||||
}
|
||||
}
|
||||
|
||||
/// French: 0 and 1 take the singular, everything else the plural.
|
||||
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)
|
||||
}
|
||||
|
||||
/// Romanian (CLDR): 1 → one; 0, or n % 100 in 1–19 → few (these take the bare plural noun, e.g.
|
||||
/// "2 straturi", "0 straturi", "119 straturi"); everything else (20, 100, 121, ...) → other (these
|
||||
/// take "de" plus the plural noun, e.g. "20 de straturi", "121 de straturi"), which matches
|
||||
/// Romanian's grammatical rule for when counted nouns need "de" inserted before them.
|
||||
fn plural_romanian(n: u64) -> usize {
|
||||
if n == 1 {
|
||||
0
|
||||
} else if n == 0 || (1..=19).contains(&(n % 100)) {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
}
|
||||
|
||||
/// Polish: 1 → one; 2–4, except 12–14 → few; everything else → many.
|
||||
fn plural_polish(n: u64) -> usize {
|
||||
let last = n % 10;
|
||||
let last_two = n % 100;
|
||||
if n == 1 {
|
||||
0
|
||||
} else if (2..=4).contains(&last) && !(12..=14).contains(&last_two) {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
}
|
||||
|
||||
/// Arabic (CLDR): 0 → zero, 1 → one, 2 → two, n % 100 in 3–10 → few, in 11–99 → many, else other.
|
||||
fn plural_arabic(n: u64) -> usize {
|
||||
match (n, n % 100) {
|
||||
(0, _) => 0,
|
||||
(1, _) => 1,
|
||||
(2, _) => 2,
|
||||
(_, 3..=10) => 3,
|
||||
(_, 11..=99) => 4,
|
||||
_ => 5,
|
||||
}
|
||||
}
|
||||
|
||||
/// A catalog file as packed by build.rs (`pack_catalogs`; the binary would otherwise carry ~2.2 MB
|
||||
/// of translations, which the web build's size gate can't afford). See [`unpack`].
|
||||
macro_rules! catalog {
|
||||
($code:literal) => {
|
||||
include_bytes!(concat!(env!("OUT_DIR"), "/i18n/", $code, ".tsv.deflate"))
|
||||
};
|
||||
}
|
||||
|
||||
/// Inflated catalogs are bounded, so corrupt data can't exhaust memory (the largest is ~0.2 MB).
|
||||
const MAX_CATALOG_BYTES: u64 = 16 << 20;
|
||||
|
||||
/// Inflate a catalog. Bad data gives an error (and the language falls back to English), never a panic.
|
||||
fn inflate(source: &[u8]) -> Result<String, String> {
|
||||
use std::io::Read as _;
|
||||
let mut text = String::new();
|
||||
if source.is_empty() {
|
||||
return Ok(text);
|
||||
}
|
||||
flate2::read::DeflateDecoder::new(source).take(MAX_CATALOG_BYTES + 1).read_to_string(&mut text).map_err(|e| e.to_string())?;
|
||||
if text.len() as u64 > MAX_CATALOG_BYTES {
|
||||
return Err(format!("over {MAX_CATALOG_BYTES} bytes"));
|
||||
}
|
||||
Ok(text)
|
||||
}
|
||||
|
||||
/// Every catalog entry's `context<TAB>source`, stored once for all catalogs (build.rs).
|
||||
static KEYS: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/i18n/keys.deflate"));
|
||||
|
||||
/// Restore a catalog file from its packed form (build.rs `pack_catalogs`): entry lines refer to
|
||||
/// [`KEYS`] instead of repeating the English source. Bad data gives an error (and the language
|
||||
/// falls back to English), never a panic.
|
||||
fn unpack(source: &[u8]) -> Result<String, String> {
|
||||
static KEY_TEXT: OnceLock<Result<String, String>> = OnceLock::new();
|
||||
if source.is_empty() {
|
||||
return Ok(String::new());
|
||||
}
|
||||
let keys: Vec<&str> = KEY_TEXT.get_or_init(|| inflate(KEYS)).as_ref().map_err(|e| format!("catalog keys: {e}"))?.split('\n').collect();
|
||||
expand(&inflate(source)?, &keys)
|
||||
}
|
||||
|
||||
/// [`unpack`]'s second step: replace each packed entry line with its key and translation.
|
||||
fn expand(packed: &str, keys: &[&str]) -> Result<String, String> {
|
||||
let mut text = String::with_capacity(packed.len().saturating_mul(2));
|
||||
let mut next = 0usize;
|
||||
for (n, line) in packed.split('\n').enumerate() {
|
||||
if n > 0 {
|
||||
text.push('\n');
|
||||
}
|
||||
let bad = || format!("packed line {}: bad key reference", n + 1);
|
||||
let (index, tr) = if let Some(tr) = line.strip_prefix('\x01') {
|
||||
(next, tr)
|
||||
} else if let Some(rest) = line.strip_prefix('\x02') {
|
||||
let (offset, tr) = rest.split_once('\t').ok_or_else(bad)?;
|
||||
let offset: i64 = offset.parse().map_err(|_| bad())?;
|
||||
let index = i64::try_from(next).ok().and_then(|n| n.checked_add(offset)).and_then(|i| usize::try_from(i).ok()).ok_or_else(bad)?;
|
||||
(index, tr)
|
||||
} else {
|
||||
text.push_str(line.strip_prefix('\x03').unwrap_or(line));
|
||||
continue;
|
||||
};
|
||||
text.push_str(keys.get(index).ok_or_else(bad)?);
|
||||
text.push('\t');
|
||||
text.push_str(tr);
|
||||
next = index.saturating_add(1);
|
||||
if text.len() as u64 > MAX_CATALOG_BYTES {
|
||||
return Err(format!("over {MAX_CATALOG_BYTES} bytes"));
|
||||
}
|
||||
}
|
||||
Ok(text)
|
||||
}
|
||||
|
||||
/// The registry. English first: it is the fallback and the source language.
|
||||
pub static LANGUAGES: [LangInfo; 35] = [
|
||||
LangInfo { code: "en", name: "English", source: b"", plural: plural_one_other, complete_menus: false, catalog: OnceLock::new() },
|
||||
LangInfo { code: "ja", name: "日本語", source: catalog!("ja"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "zh-hans", name: "简体中文", source: catalog!("zh-hans"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
/// The registry. English first: it is the fallback and the source language. Plural forms follow
|
||||
/// each language's CLDR rules (the craft-i18n crate).
|
||||
pub static LANGUAGES: [LangInfo; LANGUAGE_COUNT] = [
|
||||
LangInfo { code: "en", complete_menus: false },
|
||||
LangInfo { code: "ja", complete_menus: true },
|
||||
LangInfo { code: "zh-hans", complete_menus: true },
|
||||
// Traditional Chinese in the vocabulary used in Taiwan; `zh-TW`, `zh-HK`, `zh-MO` and `zh-Hant-*`
|
||||
// locales all resolve here (see `candidates`).
|
||||
LangInfo { code: "zh-hant", name: "繁體中文", source: catalog!("zh-hant"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "es", name: "Español", source: catalog!("es"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "ru", name: "Русский", source: catalog!("ru"), plural: plural_russian, complete_menus: true, catalog: OnceLock::new() },
|
||||
// Ukrainian has the same one/few/many rule for integer counts.
|
||||
LangInfo { code: "uk", name: "Українська", source: catalog!("uk"), plural: plural_russian, complete_menus: true, catalog: OnceLock::new() },
|
||||
// Serbian (Latin script, Ekavian) has the same one/few/many rule for integer counts. `sr-RS`,
|
||||
// `sr-Latn-*` and `sr_RS@latin` resolve here; so do Cyrillic `sr` locales, which read Latin
|
||||
// rather than English.
|
||||
LangInfo { code: "sr", name: "Srpski", source: catalog!("sr"), plural: plural_russian, complete_menus: true, catalog: OnceLock::new() },
|
||||
// Bosnian (Latin script, Ijekavian), the same one/few/other rule for integer counts. `bs-BA`,
|
||||
// `bs-Latn-*` and `bs_BA.UTF-8` resolve here; so do Cyrillic `bs` locales, which read Latin
|
||||
// rather than English.
|
||||
LangInfo { code: "bs", name: "Bosanski", source: catalog!("bs"), plural: plural_russian, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "cs", name: "Čeština", source: catalog!("cs"), plural: plural_cs, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "fr", name: "Français", source: catalog!("fr"), plural: plural_fr, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "id", name: "Bahasa Indonesia", source: catalog!("id"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "ko", name: "한국어", source: catalog!("ko"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "pl", name: "Polski", source: catalog!("pl"), plural: plural_polish, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "de", name: "Deutsch", source: catalog!("de"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "zh-hant", complete_menus: true },
|
||||
LangInfo { code: "es", complete_menus: true },
|
||||
LangInfo { code: "ru", complete_menus: true },
|
||||
LangInfo { code: "uk", complete_menus: true },
|
||||
// Serbian (Latin script, Ekavian). `sr-RS`, `sr-Latn-*` and `sr_RS@latin` resolve here; so do
|
||||
// plain `sr` and Cyrillic `sr` locales, which read Latin rather than English (see `candidates`).
|
||||
// Saved as `sr` before the catalogs moved to craft-i18n (the engine migrates it).
|
||||
LangInfo { code: "sr-latn", complete_menus: true },
|
||||
// Bosnian (Latin script, Ijekavian). `bs-BA`, `bs-Latn-*` and `bs_BA.UTF-8` resolve here; so do
|
||||
// Cyrillic `bs` locales, which read Latin rather than English.
|
||||
LangInfo { code: "bs", complete_menus: true },
|
||||
LangInfo { code: "cs", complete_menus: true },
|
||||
LangInfo { code: "fr", complete_menus: true },
|
||||
LangInfo { code: "id", complete_menus: true },
|
||||
LangInfo { code: "ko", complete_menus: true },
|
||||
LangInfo { code: "pl", complete_menus: true },
|
||||
LangInfo { code: "de", complete_menus: true },
|
||||
// Brazilian Portuguese; `pt`, `pt-BR` and `pt-PT` locales all resolve here (see `candidates`).
|
||||
LangInfo { code: "pt-br", name: "Português (Brasil)", source: catalog!("pt-br"), plural: plural_pt, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "el", name: "Ελληνικά", source: catalog!("el"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "pt-br", complete_menus: true },
|
||||
LangInfo { code: "el", complete_menus: true },
|
||||
// Dutch; `nl-NL` and `nl-BE` locales both resolve here.
|
||||
LangInfo { code: "nl", name: "Nederlands", source: catalog!("nl"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "it", name: "Italiano", source: catalog!("it"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
// Hungarian: a count takes the singular noun ("3 réteg"), so one plural form.
|
||||
LangInfo { code: "hu", name: "Magyar", source: catalog!("hu"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "nl", complete_menus: true },
|
||||
LangInfo { code: "it", complete_menus: true },
|
||||
// Hungarian: a count takes the singular noun ("3 réteg"), so both plural forms read the same.
|
||||
LangInfo { code: "hu", complete_menus: true },
|
||||
// Turkish; `tr`, `tr-TR` and `tr_TR` locales resolve here.
|
||||
LangInfo { code: "tr", name: "Türkçe", source: catalog!("tr"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "tr", complete_menus: true },
|
||||
// Azerbaijani (Latin script); regional and explicit Latin-script tags resolve here.
|
||||
LangInfo { code: "az", name: "Azərbaycanca", source: catalog!("az"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "az", complete_menus: true },
|
||||
// Vietnamese; `vi-VN` resolves here.
|
||||
LangInfo { code: "vi", name: "Tiếng Việt", source: catalog!("vi"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
// Thai; `th`, `th-TH` and `th_TH.UTF-8` locales resolve here. Thai has no plural inflection,
|
||||
// so counts use one form.
|
||||
LangInfo { code: "th", name: "ไทย", source: catalog!("th"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "vi", complete_menus: true },
|
||||
// Thai; `th`, `th-TH` and `th_TH.UTF-8` locales resolve here. Thai has no plural inflection.
|
||||
LangInfo { code: "th", complete_menus: true },
|
||||
// Hindi; `hi`, `hi-IN` locales resolve here.
|
||||
LangInfo { code: "hi", name: "हिन्दी", source: catalog!("hi"), plural: plural_one_other, complete_menus: false, catalog: OnceLock::new() },
|
||||
LangInfo { code: "hi", complete_menus: false },
|
||||
// Arabic (Modern Standard); `ar-SA`, `ar-EG` and the other regional locales resolve here. The
|
||||
// chrome mirrors right to left (`dir_for_code`), and egui lays each label out right to left.
|
||||
LangInfo { code: "ar", name: "العربية", source: catalog!("ar"), plural: plural_arabic, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "ar", complete_menus: true },
|
||||
// Swedish; `sv-SE` and `sv-FI` locales resolve here.
|
||||
LangInfo { code: "sv", name: "Svenska", source: catalog!("sv"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
// Finnish; `fi-FI` resolves here (Swedish in Finland, `sv-FI`, stays Swedish). One/other: the
|
||||
// partitive singular follows any number but 1 ("1 taso", "2 tasoa").
|
||||
LangInfo { code: "fi", name: "Suomi", source: catalog!("fi"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "sv", complete_menus: true },
|
||||
// Finnish; `fi-FI` resolves here (Swedish in Finland, `sv-FI`, stays Swedish). The partitive
|
||||
// singular follows any number but 1 ("1 taso", "2 tasoa").
|
||||
LangInfo { code: "fi", complete_menus: true },
|
||||
// Danish; `da-DK` and the other `da-*` locales resolve here.
|
||||
LangInfo { code: "da", name: "Dansk", source: catalog!("da"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "da", complete_menus: true },
|
||||
// Norwegian Bokmål; `nb-NO`, and the macrolanguage `no` and Nynorsk `nn` from POSIX locales,
|
||||
// resolve here (see `candidates`).
|
||||
LangInfo { code: "nb", name: "Norsk bokmål", source: catalog!("nb"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
LangInfo { code: "nb", complete_menus: true },
|
||||
// Hebrew; `he-il` and `he_IL` resolve here. The chrome mirrors right to left (`dir_for_code`),
|
||||
// like Arabic. Modern Hebrew software UI collapses CLDR's one/two/many/other
|
||||
// into a plain one|other, so this uses `plural_one_other`.
|
||||
LangInfo { code: "he", name: "עברית", source: catalog!("he"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
// Urdu; written right to left like Arabic (`dir_for_code`). CLDR plural: one|other.
|
||||
LangInfo { code: "ur", name: "اردو", source: catalog!("ur"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
// Romanian; `ro-RO` and `ro-MD` resolve here. Standard left-to-right; see `plural_romanian`
|
||||
// for the one/few/other rule.
|
||||
LangInfo { code: "ro", name: "Română", source: catalog!("ro"), plural: plural_romanian, complete_menus: true, catalog: OnceLock::new() },
|
||||
// Tamil; `ta-IN`, `ta-LK` and `ta_IN.UTF-8` resolve here. CLDR plural: one|other.
|
||||
LangInfo { code: "ta", name: "தமிழ்", source: catalog!("ta"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
|
||||
// Georgian: nouns stay singular after a numeral (`შრე: 5`, `5 შრე`), so one form serves every count.
|
||||
LangInfo { code: "ka", name: "ქართული", source: catalog!("ka"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
|
||||
// like Arabic. Its `two` plural form repeats `other`, as modern Hebrew software UI does.
|
||||
LangInfo { code: "he", complete_menus: true },
|
||||
// Urdu; written right to left like Arabic (`dir_for_code`).
|
||||
LangInfo { code: "ur", complete_menus: true },
|
||||
// Romanian; `ro-RO` and `ro-MD` resolve here.
|
||||
LangInfo { code: "ro", complete_menus: true },
|
||||
// Tamil; `ta-IN`, `ta-LK` and `ta_IN.UTF-8` resolve here.
|
||||
LangInfo { code: "ta", complete_menus: true },
|
||||
// Georgian: nouns stay singular after a numeral (`შრე: 5`, `5 შრე`), so both plural forms read
|
||||
// the same.
|
||||
LangInfo { code: "ka", complete_menus: true },
|
||||
];
|
||||
|
||||
impl LangInfo {
|
||||
/// The catalog file's text (empty for English, or if the bundled data can't be inflated).
|
||||
pub fn text(&self) -> String {
|
||||
unpack(self.source).unwrap_or_else(|e| {
|
||||
log::error!("translation catalog {}: {e}; showing English", self.code);
|
||||
String::new()
|
||||
})
|
||||
}
|
||||
/// Per language of [`LANGUAGES`], the (context, source) keys of PhotoCraft's own catalog as
|
||||
/// written (escaped), read on first use ([`Lang::has_own`]).
|
||||
static OWN_ROWS: [OnceLock<HashSet<(&'static str, &'static str)>>; LANGUAGE_COUNT] = [const { OnceLock::new() }; LANGUAGE_COUNT];
|
||||
|
||||
fn catalog(&self) -> &Catalog {
|
||||
self.catalog.get_or_init(|| Catalog::parse(&self.text()))
|
||||
}
|
||||
}
|
||||
|
||||
/// A language the UI can be shown in (a handle into [`LANGUAGES`]).
|
||||
/// A language the UI can be shown in: English, or one of [`LANGUAGES`] whose catalogs are
|
||||
/// embedded.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Lang(&'static LangInfo);
|
||||
pub struct Lang {
|
||||
lang: craft_i18n::Lang,
|
||||
/// The catalogs it is looked up in: the embedded ones ([`I18N`]), or a test fixture's.
|
||||
catalogs: Option<&'static I18n>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Lang {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "Lang({})", self.0.code)
|
||||
write!(f, "Lang({})", self.code())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Lang {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0.code == other.0.code
|
||||
self.code() == other.code()
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Lang {}
|
||||
|
||||
impl Lang {
|
||||
pub const EN: Lang = Lang(&LANGUAGES[0]);
|
||||
pub const EN: Lang = Lang { lang: craft_i18n::Lang::EN, catalogs: None };
|
||||
|
||||
pub fn code(self) -> &'static str {
|
||||
self.0.code
|
||||
fn i18n(self) -> &'static I18n {
|
||||
self.catalogs.unwrap_or_else(|| LazyLock::force(&I18N))
|
||||
}
|
||||
|
||||
/// A language by its exact code.
|
||||
fn info(self) -> Option<&'static LangInfo> {
|
||||
let code = self.code();
|
||||
LANGUAGES.iter().find(|l| l.code == code)
|
||||
}
|
||||
|
||||
pub fn code(self) -> &'static str {
|
||||
self.i18n().code(self.lang)
|
||||
}
|
||||
|
||||
/// A language by its exact code (any case): one of [`LANGUAGES`] whose catalogs are embedded.
|
||||
pub fn from_code(code: &str) -> Option<Lang> {
|
||||
LANGUAGES.iter().find(|l| l.code.eq_ignore_ascii_case(code)).map(Lang)
|
||||
let info = LANGUAGES.iter().find(|l| l.code.eq_ignore_ascii_case(code))?;
|
||||
I18N.from_code(info.code).map(|lang| Lang { lang, catalogs: None })
|
||||
}
|
||||
|
||||
/// Resolve the `interface.language` preference: a language code, or `auto` (and anything
|
||||
@@ -341,9 +216,10 @@ impl Lang {
|
||||
Lang::from_code(pref).or_else(|| lang_from_tag(pref)).unwrap_or_else(system_lang)
|
||||
}
|
||||
|
||||
/// Every registered language.
|
||||
/// Every language the interface can be shown in: [`LANGUAGES`] in order, those whose catalogs
|
||||
/// are embedded (English alone in a build without craft-i18n).
|
||||
pub fn all() -> impl Iterator<Item = Lang> {
|
||||
LANGUAGES.iter().map(Lang)
|
||||
LANGUAGES.iter().filter_map(|l| Lang::from_code(l.code))
|
||||
}
|
||||
|
||||
/// Every registered language in the order a picker lists them: English first (the source
|
||||
@@ -356,25 +232,70 @@ impl Lang {
|
||||
std::iter::once(Lang::EN).chain(rest).collect()
|
||||
}
|
||||
|
||||
/// The language's name in itself (its `@id language.name` row), shown in the Preferences
|
||||
/// dropdown.
|
||||
pub fn name(self) -> &'static str {
|
||||
self.0.name
|
||||
self.i18n().name(self.lang)
|
||||
}
|
||||
|
||||
/// Does this language's catalog claim to cover every menu string and `tl!` literal?
|
||||
pub fn complete_menus(self) -> bool {
|
||||
self.0.complete_menus
|
||||
self.info().is_some_and(|l| l.complete_menus)
|
||||
}
|
||||
|
||||
/// The language's reading direction.
|
||||
pub fn dir(self) -> Dir {
|
||||
dir_for_code(self.0.code)
|
||||
dir_for_code(self.code())
|
||||
}
|
||||
|
||||
fn catalog(self) -> &'static Catalog {
|
||||
self.0.catalog()
|
||||
/// Whether PhotoCraft's own catalog (`photocraft.tsv`, not the shared `common.tsv`) has the
|
||||
/// row (`context`, `source`). The shared catalog's `@id` rows are keyed by the other apps'
|
||||
/// command ids, which can name another command, so command-id lookups ask this; every `@id`
|
||||
/// row PhotoCraft had is in its own catalog. A test fixture has no shared catalog: its rows are
|
||||
/// its own.
|
||||
fn has_own(self, context: &str, source: &str) -> bool {
|
||||
if let Some(fixture) = self.catalogs {
|
||||
return fixture.get(self.lang, context, source).is_some();
|
||||
}
|
||||
let code = self.code();
|
||||
let Some(slot) = LANGUAGES.iter().position(|l| l.code == code).and_then(|i| OWN_ROWS.get(i)) else { return false };
|
||||
let rows: &HashSet<(&str, &str)> = slot.get_or_init(|| {
|
||||
app_catalog(code)
|
||||
.lines()
|
||||
.filter(|l| !l.starts_with('#'))
|
||||
.filter_map(|l| {
|
||||
let mut columns = l.split('\t');
|
||||
Some((columns.next()?, columns.next()?))
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
let escape = |s: &str| s.replace('\\', "\\\\").replace('\n', "\\n").replace('\t', "\\t");
|
||||
rows.contains(&(escape(context).as_str(), escape(source).as_str()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Lang {
|
||||
/// The embedded catalog texts this language reads, the shared one then PhotoCraft's; none for
|
||||
/// English. For checks that the interface fonts draw every translation.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn catalog_texts(self) -> impl Iterator<Item = &'static str> {
|
||||
let code = self.code();
|
||||
CRAFT_I18N.iter().filter(move |(c, ..)| c.eq_ignore_ascii_case(code)).flat_map(|(_, shared, app)| [*shared, *app])
|
||||
}
|
||||
}
|
||||
|
||||
/// PhotoCraft's own embedded catalog text (`photocraft.tsv`) in the locale `code`; empty when
|
||||
/// there is none.
|
||||
fn app_catalog(code: &str) -> &'static str {
|
||||
CRAFT_I18N.iter().find(|(c, ..)| c.eq_ignore_ascii_case(code)).map_or("", |(_, _, app)| *app)
|
||||
}
|
||||
|
||||
/// Whether this build embeds the craft-i18n catalogs (`CRAFT_I18N_DIR` was set). Without them the
|
||||
/// interface is English only; tests that need a translation skip with a note.
|
||||
pub fn catalogs_embedded() -> bool {
|
||||
!CRAFT_I18N.is_empty()
|
||||
}
|
||||
|
||||
/// `name` lowercased with the Latin accents that occur in language names folded away, so a
|
||||
/// byte-wise sort reads alphabetically. Other scripts are left as they are.
|
||||
fn name_sort_key(name: &str) -> String {
|
||||
@@ -415,6 +336,12 @@ fn candidates(tag: &str) -> Vec<String> {
|
||||
// The only Portuguese catalog is Brazilian; other regions use it rather than English.
|
||||
out.insert(out.len() - 1, "pt-br".to_string());
|
||||
}
|
||||
if primary == "sr" && !out.iter().any(|c| c == "sr-latn") {
|
||||
// The only Serbian catalog is Latin (`sr-latn`). Plain, regional (`sr-RS`, `sr-ME`) and
|
||||
// Cyrillic (`sr-Cyrl-RS`) tags read it rather than English, as when it was PhotoCraft's
|
||||
// `sr` catalog; craft-i18n's own matching never takes `sr` to a script it doesn't name.
|
||||
out.insert(out.len() - 1, "sr-latn".to_string());
|
||||
}
|
||||
if matches!(primary, "no" | "nn") && !out.iter().any(|c| c == "nb") {
|
||||
// The only Norwegian catalog is Bokmål; the macrolanguage code and Nynorsk use it rather
|
||||
// than English.
|
||||
@@ -489,7 +416,7 @@ pub fn sync_context(ctx: &egui::Context, language: &str) {
|
||||
|
||||
/// Does `lang` have a catalog entry for this plain string? (English never does: it is the source.)
|
||||
pub fn has(lang: Lang, s: &str) -> bool {
|
||||
lang.catalog().plain(s).is_some()
|
||||
lang.i18n().get(lang.lang, "", s).is_some()
|
||||
}
|
||||
|
||||
/// Translate an English UI string into the current language ([`tr`] with [`current`]).
|
||||
@@ -499,17 +426,41 @@ pub fn t(s: &str) -> &str {
|
||||
|
||||
/// Translate an English UI string; unknown strings come back unchanged.
|
||||
pub fn tr(lang: Lang, s: &str) -> &str {
|
||||
lang.catalog().plain(s).unwrap_or(s)
|
||||
lang.i18n().t(lang.lang, s)
|
||||
}
|
||||
|
||||
/// Like [`tr`], for an English string that needs a disambiguating `context`.
|
||||
pub fn tr_ctx<'a>(lang: Lang, context: &str, s: &'a str) -> &'a str {
|
||||
lang.catalog().contextual(context, s).unwrap_or_else(|| tr(lang, s))
|
||||
lang.i18n().tc(lang.lang, context, s)
|
||||
}
|
||||
|
||||
/// A string keyed by its command id, falling back to the translation of the English `label`.
|
||||
/// A string keyed by its command id, falling back to the translation of the English `label`. Only
|
||||
/// PhotoCraft's own `@id` rows count ([`own_id`]).
|
||||
pub fn tr_id<'a>(lang: Lang, id: &str, label: &'a str) -> &'a str {
|
||||
lang.catalog().id(id).unwrap_or_else(|| tr(lang, label))
|
||||
if own_id(lang, id, label) { lang.i18n().tid(lang.lang, id, label) } else { tr(lang, label) }
|
||||
}
|
||||
|
||||
/// Whether `lang` has PhotoCraft's own `@id` row for `id` ([`Lang::has_own`]: command ids are each
|
||||
/// app's own) and it keeps the `{placeholders}` and trailing `…` of the English `label`. craft-i18n
|
||||
/// can't check that, because an `@id` row's source is the id, so a row that doesn't is skipped
|
||||
/// here and the label's translation shows instead.
|
||||
fn own_id(lang: Lang, id: &str, label: &str) -> bool {
|
||||
lang.has_own("@id", id) && lang.i18n().get(lang.lang, "@id", id).is_some_and(|translated| same_shape(translated, label))
|
||||
}
|
||||
|
||||
/// Whether `translated` has the `{placeholders}` (in any order) and the trailing `…` of `english`,
|
||||
/// the check craft-i18n makes on every row whose source is English text, and no `{` left open or
|
||||
/// `}` without its `{`.
|
||||
fn same_shape(translated: &str, english: &str) -> bool {
|
||||
let placeholders = |text: &str| -> Option<Vec<String>> {
|
||||
let mut names = text.split('{').skip(1).map(|p| p.split_once('}').map(|(name, _)| name.to_owned())).collect::<Option<Vec<_>>>()?;
|
||||
if text.matches('}').count() != names.len() {
|
||||
return None;
|
||||
}
|
||||
names.sort_unstable();
|
||||
Some(names)
|
||||
};
|
||||
translated.ends_with('…') == english.ends_with('…') && placeholders(translated).is_some_and(|names| Some(names) == placeholders(english))
|
||||
}
|
||||
|
||||
/// Fill `{name}` placeholders. Unknown placeholders are left as written.
|
||||
@@ -522,10 +473,31 @@ pub fn fmt(template: &str, args: &[(&str, &str)]) -> String {
|
||||
}
|
||||
|
||||
/// A plural-aware message: `one`/`other` are the English forms (with `{n}` where the count goes).
|
||||
/// The form is the language's CLDR category; `{n}` is written in `0`–`9` without grouping or
|
||||
/// isolate marks, as PhotoCraft always has.
|
||||
pub fn trn(lang: Lang, n: u64, one: &str, other: &str) -> String {
|
||||
let idx = (lang.0.plural)(n);
|
||||
let text = lang.catalog().plural(one, other, idx).unwrap_or(if n == 1 { one } else { other });
|
||||
fmt(text, &[("n", &n.to_string())])
|
||||
lang.i18n().trn_plain(lang.lang, n, one, other)
|
||||
}
|
||||
|
||||
/// A test language whose PhotoCraft catalog is `source` (catalog format), so tests of lookup code
|
||||
/// don't depend on the embedded catalogs' wording. `code` picks the CLDR plural rules.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn fixture_lang(code: &'static str, source: &'static str) -> Lang {
|
||||
let embedded: &'static craft_i18n::Embedded = Box::leak(Box::new([(code, "", source)]));
|
||||
let (i18n, _) = I18n::new(embedded, &[code]);
|
||||
let i18n: &'static I18n = Box::leak(Box::new(i18n));
|
||||
let lang = i18n.from_code(code).unwrap_or(craft_i18n::Lang::EN);
|
||||
Lang { lang, catalogs: Some(i18n) }
|
||||
}
|
||||
|
||||
/// For a test that needs the embedded catalogs: `false`, with a note, when none were embedded
|
||||
/// (`CRAFT_I18N_DIR` unset), so the test can skip; the interface is then English only.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn needs_catalogs() -> bool {
|
||||
if !catalogs_embedded() {
|
||||
eprintln!("skipped: built without craft-i18n (set CRAFT_I18N_DIR to a craft-i18n checkout); the interface is English only");
|
||||
}
|
||||
catalogs_embedded()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -19,6 +19,9 @@ fn lang(code: &str) -> Lang {
|
||||
/// a preference and as a system tag.
|
||||
#[test]
|
||||
fn requested_languages_resolve_regional_preferences() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
for (tag, code) in [
|
||||
("en-US", "en"),
|
||||
("zh-CN", "zh-hans"),
|
||||
@@ -29,7 +32,7 @@ fn requested_languages_resolve_regional_preferences() {
|
||||
("fr-CA", "fr"),
|
||||
("id-ID", "id"),
|
||||
("vi-VN", "vi"),
|
||||
("sr-RS", "sr"),
|
||||
("sr-RS", "sr-latn"),
|
||||
("az-Latn-AZ", "az"),
|
||||
("bs-BA", "bs"),
|
||||
] {
|
||||
@@ -43,6 +46,9 @@ fn requested_languages_resolve_regional_preferences() {
|
||||
/// Switching redraws the menu and persists through the shell's save/load services on restart.
|
||||
#[test]
|
||||
fn azerbaijani_draw_after_switching_and_restore_after_restart() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
let code = "az";
|
||||
@@ -94,6 +100,9 @@ fn azerbaijani_draw_after_switching_and_restore_after_restart() {
|
||||
/// Preferences draw the catalog terms verbatim and the bundled UI font covers their letters.
|
||||
#[test]
|
||||
fn azerbaijani_preferences_draw_terms_and_glyphs() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let code = "az";
|
||||
let interface = "İnterfeys";
|
||||
let light = "Açıq mövzu";
|
||||
@@ -116,6 +125,9 @@ fn azerbaijani_preferences_draw_terms_and_glyphs() {
|
||||
|
||||
#[test]
|
||||
fn ukrainian_native_app_menu_keeps_product_and_language_names() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let h = harness();
|
||||
let layout = crate::native_menu::photocraft_layout(&crate::menus::menu_items(h.state()), lang("uk"), "uk");
|
||||
@@ -130,6 +142,9 @@ fn ukrainian_native_app_menu_keeps_product_and_language_names() {
|
||||
|
||||
#[test]
|
||||
fn ukrainian_color_picker_titles_draw_in_the_selected_language() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
for (target, title) in [("foreground", "Color Picker (Foreground Color)"), ("background", "Color Picker (Background Color)")] {
|
||||
let mut h = harness();
|
||||
@@ -144,6 +159,9 @@ fn ukrainian_color_picker_titles_draw_in_the_selected_language() {
|
||||
|
||||
#[test]
|
||||
fn ukrainian_rasterize_prompt_draws_in_the_selected_language() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
use crate::rasterize_prompt::Kind;
|
||||
|
||||
with_language(Lang::EN, || {
|
||||
@@ -161,6 +179,9 @@ fn ukrainian_rasterize_prompt_draws_in_the_selected_language() {
|
||||
|
||||
#[test]
|
||||
fn scoped_preview_restores_language_even_after_a_panic() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
with_language(lang("fr"), || {
|
||||
assert_eq!(current(), lang("fr"));
|
||||
@@ -176,6 +197,9 @@ fn scoped_preview_restores_language_even_after_a_panic() {
|
||||
|
||||
#[test]
|
||||
fn drawing_languages_are_isolated_between_threads() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(lang("fr"), || {
|
||||
let thread = std::thread::spawn(|| {
|
||||
assert_eq!(current(), Lang::EN);
|
||||
@@ -188,6 +212,9 @@ fn drawing_languages_are_isolated_between_threads() {
|
||||
|
||||
#[test]
|
||||
fn dynamic_brush_sections_draw_in_the_selected_language() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("prefs.set", json!({"path": "interface.language", "value": "zh-hans"})).expect("language");
|
||||
@@ -202,6 +229,9 @@ fn dynamic_brush_sections_draw_in_the_selected_language() {
|
||||
|
||||
#[test]
|
||||
fn fill_dialog_draws_in_the_selected_language() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("prefs.set", json!({"path": "interface.language", "value": "pt-br"})).expect("language");
|
||||
@@ -218,6 +248,9 @@ fn fill_dialog_draws_in_the_selected_language() {
|
||||
|
||||
#[test]
|
||||
fn file_info_camera_data_draws_in_the_selected_language_read_only() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
let exif = photocraft_algo::exif::build(&photocraft_algo::exif::CameraInfo {
|
||||
@@ -252,6 +285,9 @@ fn file_info_camera_data_draws_in_the_selected_language_read_only() {
|
||||
|
||||
#[test]
|
||||
fn cjk_font_order_follows_the_selected_language() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
use photocraft_text::cjk::CjkScript;
|
||||
for (code, script) in [("zh-hans", CjkScript::SimplifiedChinese), ("ja", CjkScript::Japanese), ("ko", CjkScript::Korean)] {
|
||||
with_language(lang(code), || {
|
||||
@@ -264,6 +300,9 @@ fn cjk_font_order_follows_the_selected_language() {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn korean_glyphs_remain_available_after_repeated_language_switches() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
use photocraft_text::cjk::{self, CjkChar, CjkScript};
|
||||
#[cfg(target_os = "linux")]
|
||||
assert!(crate::cjk_fonts::wait_for_fontconfig_cjk_scan(), "Fontconfig CJK lookup did not finish within 10 seconds");
|
||||
@@ -273,7 +312,8 @@ fn korean_glyphs_remain_available_after_repeated_language_switches() {
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
let glyphs: std::collections::BTreeSet<_> = lang("ko").0.text().chars().filter(|c| cjk::classify(*c) == Some(CjkChar::Hangul)).collect();
|
||||
let glyphs: std::collections::BTreeSet<_> =
|
||||
lang("ko").catalog_texts().flat_map(str::chars).filter(|c| cjk::classify(*c) == Some(CjkChar::Hangul)).collect();
|
||||
for code in ["zh-hans", "ja", "ko", "fr", "ko"] {
|
||||
h.state_mut().run("prefs.set", json!({"path": "interface.language", "value": code})).expect("language");
|
||||
h.run_steps(12);
|
||||
@@ -309,6 +349,9 @@ fn harness_with_services(services: Services) -> egui_kittest::Harness<'static, P
|
||||
/// Auto draws the detected system language on first launch while keeping the Auto preference.
|
||||
#[test]
|
||||
fn first_launch_renders_the_system_language_without_overwriting_auto() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
for (tag, code) in [
|
||||
("en-US", "en"),
|
||||
("zh-CN", "zh-hans"),
|
||||
@@ -336,6 +379,9 @@ fn first_launch_renders_the_system_language_without_overwriting_auto() {
|
||||
|
||||
#[test]
|
||||
fn missing_or_unsupported_system_languages_render_english() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
for tags in [vec![], vec!["sw-KE", "is-IS"]] {
|
||||
system::with_system_tags(&tags, || {
|
||||
with_language(Lang::EN, || {
|
||||
@@ -350,6 +396,9 @@ fn missing_or_unsupported_system_languages_render_english() {
|
||||
|
||||
#[test]
|
||||
fn older_preferences_without_a_language_follow_the_system() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
system::with_system_tags(&["fr-CA"], || {
|
||||
with_language(Lang::EN, || {
|
||||
let services = Services { load_prefs: Some(Box::new(|| Some(r#"{"interface":{"uiScale":"125"}}"#.into()))), ..Default::default() };
|
||||
@@ -363,6 +412,9 @@ fn older_preferences_without_a_language_follow_the_system() {
|
||||
|
||||
#[test]
|
||||
fn an_explicit_language_survives_restart_on_a_different_system_language() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let saved = system::with_system_tags(&["ja-JP"], || {
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
@@ -386,6 +438,9 @@ fn an_explicit_language_survives_restart_on_a_different_system_language() {
|
||||
|
||||
#[test]
|
||||
fn a_control_request_changes_the_drawing_language_in_the_same_frame() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
let document = h.state().session.active().expect("document").doc.clone();
|
||||
@@ -409,6 +464,9 @@ fn a_control_request_changes_the_drawing_language_in_the_same_frame() {
|
||||
|
||||
#[test]
|
||||
fn preferences_preview_does_not_commit_until_applied_and_survives_reload() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
let id = crate::prefs_ui::open_preferences(h.state_mut(), "interface");
|
||||
@@ -439,6 +497,9 @@ fn preferences_preview_does_not_commit_until_applied_and_survives_reload() {
|
||||
|
||||
#[test]
|
||||
fn keyboard_shortcuts_list_commands_in_the_selected_language() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("prefs.set", json!({"path": "interface.language", "value": "pt-br"})).expect("language");
|
||||
@@ -475,6 +536,9 @@ fn drawn_text(h: &egui_kittest::Harness<'_, PhotocraftApp>) -> Vec<String> {
|
||||
|
||||
#[test]
|
||||
fn czech_status_notices_and_navigator_draw_translated_text() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("prefs.set", json!({"path": "interface.language", "value": "cs"})).expect("language");
|
||||
@@ -516,6 +580,9 @@ fn czech_status_notices_and_navigator_draw_translated_text() {
|
||||
|
||||
#[test]
|
||||
fn czech_shortcut_conflicts_keep_warning_state_and_shortcut_codes() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("prefs.set", json!({"path": "interface.language", "value": "cs"})).expect("language");
|
||||
@@ -547,6 +614,9 @@ fn czech_shortcut_conflicts_keep_warning_state_and_shortcut_codes() {
|
||||
/// the end of the sentence lands at the left.
|
||||
#[test]
|
||||
fn arabic_labels_are_laid_out_right_to_left() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("prefs.set", json!({"path": "interface.language", "value": "ar"})).unwrap();
|
||||
@@ -568,6 +638,9 @@ fn arabic_labels_are_laid_out_right_to_left() {
|
||||
/// right-to-left document name.
|
||||
#[test]
|
||||
fn arabic_names_are_laid_out_right_to_left() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_language(Lang::EN, || {
|
||||
let h = harness();
|
||||
let font = egui::FontId::proportional(13.0);
|
||||
|
||||
@@ -145,6 +145,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn system_preferences_are_negotiated_in_order() {
|
||||
if !crate::i18n::needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
for (tags, expected) in [
|
||||
(vec!["ja-JP", "en-US"], "ja"),
|
||||
(vec!["fr-CA", "en-US"], "fr"),
|
||||
@@ -162,8 +165,9 @@ mod tests {
|
||||
(vec!["nl-BE", "fr-BE"], "nl"),
|
||||
(vec!["hu-HU", "en-US"], "hu"),
|
||||
(vec!["tr-TR", "en-US"], "tr"),
|
||||
(vec!["sr-Latn-RS", "en-US"], "sr"),
|
||||
(vec!["sw-KE", "sr_RS@latin", "ru-RU"], "sr"),
|
||||
(vec!["sr-Latn-RS", "en-US"], "sr-latn"),
|
||||
(vec!["sr-Cyrl-RS", "en-US"], "sr-latn"),
|
||||
(vec!["sw-KE", "sr_RS@latin", "ru-RU"], "sr-latn"),
|
||||
(vec!["hi-IN", "en-US"], "hi"),
|
||||
(vec!["sv-SE", "en-US"], "sv"),
|
||||
(vec!["sv_FI.UTF-8", "fi-FI", "en-US"], "sv"),
|
||||
@@ -181,6 +185,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_system_preferences_restore_and_remain_thread_local() {
|
||||
if !crate::i18n::needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
with_system_tags(&["ko-KR"], || {
|
||||
with_system_tags(&["fr-FR"], || assert_eq!(system_lang().code(), "fr"));
|
||||
assert_eq!(system_lang().code(), "ko");
|
||||
|
||||
+283
-348
@@ -1,75 +1,74 @@
|
||||
use super::catalog::{parse_entries, placeholders};
|
||||
use super::*;
|
||||
|
||||
const JA: fn() -> Lang = || Lang::from_code("ja").expect("ja registered");
|
||||
const ZH: fn() -> Lang = || Lang::from_code("zh-hant").expect("zh-hant registered");
|
||||
const CS: fn() -> Lang = || Lang::from_code("cs").expect("cs registered");
|
||||
const ID: fn() -> Lang = || Lang::from_code("id").expect("id registered");
|
||||
const VI: fn() -> Lang = || Lang::from_code("vi").expect("vi registered");
|
||||
const HI: fn() -> Lang = || Lang::from_code("hi").expect("hi registered");
|
||||
const KA: fn() -> Lang = || Lang::from_code("ka").expect("ka registered");
|
||||
/// A registered language whose catalogs are embedded. Callers check [`needs_catalogs`] first.
|
||||
fn lang(code: &str) -> Lang {
|
||||
Lang::from_code(code).unwrap_or_else(|| panic!("{code} registered and embedded"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hindi_has_the_reveal_and_camera_raw_rows() {
|
||||
assert_eq!(tr(HI(), "Reveal in Explorer"), "Explorer में दिखाएँ");
|
||||
assert_eq!(tr(HI(), "Reveal in Finder"), "Finder में दिखाएँ");
|
||||
assert_eq!(tr(HI(), "Camera Raw…"), "Camera Raw…");
|
||||
let (rows, errors) = parse_entries(include_str!("hi.tsv"));
|
||||
assert!(errors.is_empty(), "{errors:?}");
|
||||
assert!(rows.iter().any(|(ctx, src, _)| ctx.is_empty() && src == "Camera Raw…"), "Camera Raw… is a catalog row, not a fallback");
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let hi = lang("hi");
|
||||
assert_eq!(tr(hi, "Reveal in Explorer"), "Explorer में दिखाएँ");
|
||||
assert_eq!(tr(hi, "Reveal in Finder"), "Finder में दिखाएँ");
|
||||
assert_eq!(tr(hi, "Camera Raw…"), "Camera Raw…");
|
||||
assert!(has(hi, "Camera Raw…"), "Camera Raw… is a catalog row, not a fallback");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hindi_tags_resolve() {
|
||||
for tag in ["hi", "hi-IN", "hi_IN", "hi_IN.UTF-8"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(HI()), "{tag}");
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
assert_eq!(HI().name(), "हिन्दी");
|
||||
assert_eq!(Lang::from_pref("hi"), HI());
|
||||
assert_eq!(Lang::from_pref("HI"), HI());
|
||||
let hi = lang("hi");
|
||||
for tag in ["hi", "hi-IN", "hi_IN", "hi_IN.UTF-8"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(hi), "{tag}");
|
||||
}
|
||||
assert_eq!(hi.name(), "हिन्दी");
|
||||
assert_eq!(Lang::from_pref("hi"), hi);
|
||||
assert_eq!(Lang::from_pref("HI"), hi);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn georgian_tags_resolve() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let ka = lang("ka");
|
||||
for tag in ["ka", "ka-GE", "ka_GE", "ka_GE.UTF-8"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(KA()), "{tag}");
|
||||
assert_eq!(lang_from_tag(tag), Some(ka), "{tag}");
|
||||
}
|
||||
assert_eq!(KA().name(), "ქართული");
|
||||
assert_eq!(Lang::from_pref("ka"), KA());
|
||||
assert_eq!(Lang::from_pref("KA"), KA());
|
||||
assert_eq!(tr(KA(), "Layer"), "შრე");
|
||||
assert_eq!(tr(KA(), "File"), "ფაილი");
|
||||
assert_eq!(trn(KA(), 1, "{n} layer", "{n} layers"), "შრე: 1");
|
||||
assert_eq!(trn(KA(), 3, "{n} layer", "{n} layers"), "შრე: 3");
|
||||
assert_eq!(ka.name(), "ქართული");
|
||||
assert_eq!(Lang::from_pref("ka"), ka);
|
||||
assert_eq!(Lang::from_pref("KA"), ka);
|
||||
assert_eq!(tr(ka, "Layer"), "შრე");
|
||||
assert_eq!(tr(ka, "File"), "ფაილი");
|
||||
assert_eq!(trn(ka, 1, "{n} layer", "{n} layers"), "შრე: 1");
|
||||
assert_eq!(trn(ka, 3, "{n} layer", "{n} layers"), "შრე: 3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indonesian_tags_resolve() {
|
||||
fn indonesian_vietnamese_and_thai_tags_resolve() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
for tag in ["id", "id-ID", "id_ID", "id_ID.UTF-8"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(ID()), "{tag}");
|
||||
assert_eq!(lang_from_tag(tag), Some(lang("id")), "{tag}");
|
||||
}
|
||||
assert_eq!(ID().name(), "Bahasa Indonesia");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vietnamese_tags_resolve() {
|
||||
assert_eq!(lang("id").name(), "Bahasa Indonesia");
|
||||
for tag in ["vi", "vi-VN", "vi_VN", "vi_VN.UTF-8"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(VI()), "{tag}");
|
||||
assert_eq!(lang_from_tag(tag), Some(lang("vi")), "{tag}");
|
||||
}
|
||||
assert_eq!(VI().name(), "Tiếng Việt");
|
||||
assert_eq!(Lang::from_pref("vi"), VI());
|
||||
assert_eq!(Lang::from_pref("VI"), VI());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thai_tags_resolve() {
|
||||
let th = Lang::from_code("th").expect("th registered");
|
||||
assert_eq!(lang("vi").name(), "Tiếng Việt");
|
||||
assert_eq!(Lang::from_pref("VI"), lang("vi"));
|
||||
let th = lang("th");
|
||||
for tag in ["th", "TH", "th-TH", "th_TH", "th_TH.UTF-8"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(th), "{tag}");
|
||||
assert_eq!(Lang::from_pref(tag), th, "{tag}");
|
||||
}
|
||||
assert_eq!(th.name(), "ไทย");
|
||||
assert_eq!((th.0.plural)(5), 0, "Thai has one plural form");
|
||||
assert_eq!(tr(th, "File"), "ไฟล์");
|
||||
assert_eq!(tr(th, "Layer"), "เลเยอร์");
|
||||
}
|
||||
@@ -77,12 +76,13 @@ fn thai_tags_resolve() {
|
||||
/// Tamil: regional tags resolve, counts take one|other, and placeholders stay untranslated.
|
||||
#[test]
|
||||
fn tamil_tags_plurals_and_placeholders() {
|
||||
let ta = Lang::from_code("ta").expect("ta registered");
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let ta = lang("ta");
|
||||
for tag in ["ta", "ta-IN", "ta_LK", "ta_IN.UTF-8"] {
|
||||
assert_eq!(Lang::from_pref(tag), ta, "{tag}");
|
||||
}
|
||||
let forms: Vec<usize> = [0, 1, 2, 21].into_iter().map(ta.0.plural).collect();
|
||||
assert_eq!(forms, [1, 0, 1, 1]);
|
||||
assert_eq!(trn(ta, 1, "{n} layer", "{n} layers"), "1 அடுக்கு");
|
||||
assert_eq!(trn(ta, 3, "{n} layer", "{n} layers"), "3 அடுக்குகள்");
|
||||
assert!(tr(ta, "Scratch: {size}").contains("{size}"));
|
||||
@@ -96,59 +96,65 @@ fn picker_lists_english_first_then_names_alphabetically() {
|
||||
assert_eq!(order.len(), Lang::all().count());
|
||||
let keys: Vec<String> = order[1..].iter().map(|l| name_sort_key(l.name())).collect();
|
||||
assert!(keys.windows(2).all(|w| w[0] <= w[1]), "{keys:?}");
|
||||
assert_eq!(name_sort_key("Tiếng Việt"), "tieng viet");
|
||||
assert_eq!(name_sort_key("Türkçe"), "turkce");
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
assert_eq!(order.len(), LANGUAGES.len(), "every registered language is embedded");
|
||||
let pos = |code: &str| order.iter().position(|l| l.code() == code).unwrap_or_else(|| panic!("{code} registered"));
|
||||
assert!(pos("cs") < pos("de"), "Čeština sorts under C, not after Z");
|
||||
assert!(pos("it") < pos("hu"), "Magyar sorts under M, not under its code");
|
||||
assert!(pos("tr") < pos("el"), "Latin names come before Greek");
|
||||
assert!(pos("uk") < pos("ja"), "Cyrillic names come before CJK");
|
||||
assert_eq!(name_sort_key("Tiếng Việt"), "tieng viet");
|
||||
assert_eq!(name_sort_key("Türkçe"), "turkce");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tags_map_to_languages() {
|
||||
western_and_legacy_tags_resolve();
|
||||
chinese_tags_resolve_by_region_and_script();
|
||||
}
|
||||
|
||||
fn western_and_legacy_tags_resolve() {
|
||||
assert_eq!(lang_from_tag("ja_JP.UTF-8"), Some(JA()));
|
||||
assert_eq!(lang_from_tag("ja-JP"), Some(JA()));
|
||||
assert_eq!(lang_from_tag("en_US.UTF-8"), Some(Lang::EN));
|
||||
assert_eq!(lang_from_tag("C"), Some(Lang::EN));
|
||||
assert_eq!(lang_from_tag("POSIX"), Some(Lang::EN));
|
||||
assert_eq!(lang_from_tag("cs_CZ.UTF-8"), Some(CS()));
|
||||
assert_eq!(lang_from_tag("cs-CZ"), Some(CS()));
|
||||
assert_eq!(lang_from_tag("fr_FR"), Lang::from_code("fr"));
|
||||
assert_eq!(lang_from_tag("de_DE"), Lang::from_code("de"));
|
||||
assert_eq!(lang_from_tag("de-AT"), Lang::from_code("de"));
|
||||
assert_eq!(lang_from_tag("it_IT.UTF-8"), Lang::from_code("it"));
|
||||
assert_eq!(lang_from_tag("it-CH"), Lang::from_code("it"));
|
||||
assert_eq!(lang_from_tag("nl_NL.UTF-8"), Lang::from_code("nl"));
|
||||
assert_eq!(lang_from_tag("nl-BE"), Lang::from_code("nl"));
|
||||
assert_eq!(lang_from_tag("hu_HU.UTF-8"), Lang::from_code("hu"));
|
||||
assert_eq!(lang_from_tag("hu-HU"), Lang::from_code("hu"));
|
||||
assert_eq!(lang_from_tag("tr_TR.UTF-8"), Lang::from_code("tr"));
|
||||
assert_eq!(lang_from_tag("tr-TR"), Lang::from_code("tr"));
|
||||
assert_eq!(lang_from_tag("tr"), Lang::from_code("tr"));
|
||||
}
|
||||
|
||||
fn chinese_tags_resolve_by_region_and_script() {
|
||||
// Traditional Chinese: by region, by script, and with a region after the script.
|
||||
assert_eq!(lang_from_tag("zh_TW.UTF-8"), Some(ZH()));
|
||||
assert_eq!(lang_from_tag("zh-TW"), Some(ZH()));
|
||||
assert_eq!(lang_from_tag("zh-HK"), Some(ZH()));
|
||||
assert_eq!(lang_from_tag("zh_MO"), Some(ZH()));
|
||||
assert_eq!(lang_from_tag("zh-Hant"), Some(ZH()));
|
||||
assert_eq!(lang_from_tag("zh-Hant-TW"), Some(ZH()));
|
||||
assert_eq!(lang_from_tag("zh-Hant-HK"), Some(ZH()));
|
||||
// Simplified Chinese locales never pick up the Traditional catalog: they resolve to `zh-hans`.
|
||||
for tag in ["zh-CN", "zh_CN.UTF-8", "zh_SG", "zh-Hans", "zh-Hans-CN", "zh"] {
|
||||
assert_ne!(lang_from_tag(tag), Some(ZH()), "{tag}");
|
||||
assert_eq!(lang_from_tag(tag), Lang::from_code("zh-hans"), "{tag}");
|
||||
}
|
||||
assert_eq!(lang_from_tag(""), None);
|
||||
assert_eq!(lang_from_tag("_"), None);
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
assert_eq!(lang_from_tag("ja_JP.UTF-8"), Some(lang("ja")));
|
||||
assert_eq!(lang_from_tag("ja-JP"), Some(lang("ja")));
|
||||
assert_eq!(lang_from_tag("cs_CZ.UTF-8"), Some(lang("cs")));
|
||||
assert_eq!(lang_from_tag("cs-CZ"), Some(lang("cs")));
|
||||
for (tag, code) in [
|
||||
("fr_FR", "fr"),
|
||||
("de_DE", "de"),
|
||||
("de-AT", "de"),
|
||||
("it_IT.UTF-8", "it"),
|
||||
("it-CH", "it"),
|
||||
("nl_NL.UTF-8", "nl"),
|
||||
("nl-BE", "nl"),
|
||||
("hu_HU.UTF-8", "hu"),
|
||||
("hu-HU", "hu"),
|
||||
("tr_TR.UTF-8", "tr"),
|
||||
("tr-TR", "tr"),
|
||||
("tr", "tr"),
|
||||
] {
|
||||
assert_eq!(lang_from_tag(tag), Some(lang(code)), "{tag}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chinese_tags_resolve_by_region_and_script() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let zh = lang("zh-hant");
|
||||
// Traditional Chinese: by region, by script, and with a region after the script.
|
||||
for tag in ["zh_TW.UTF-8", "zh-TW", "zh-HK", "zh_MO", "zh-Hant", "zh-Hant-TW", "zh-Hant-HK"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(zh), "{tag}");
|
||||
}
|
||||
// Simplified Chinese locales never pick up the Traditional catalog: they resolve to `zh-hans`.
|
||||
for tag in ["zh-CN", "zh_CN.UTF-8", "zh_SG", "zh-Hans", "zh-Hans-CN", "zh"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(lang("zh-hans")), "{tag}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -159,58 +165,72 @@ fn candidates_walk_from_specific_to_general() {
|
||||
assert_eq!(candidates("zh-Hant-HK"), ["zh-hant-hk", "zh-hant", "zh"]);
|
||||
assert_eq!(candidates("nn_NO.UTF-8"), ["nn-no", "nb", "nn"]);
|
||||
assert_eq!(candidates("no"), ["nb", "no"]);
|
||||
assert_eq!(candidates("pt_PT"), ["pt-pt", "pt-br", "pt"]);
|
||||
}
|
||||
|
||||
/// PhotoCraft's Serbian catalog was `sr` and is craft-i18n's `sr-latn`: plain, regional and
|
||||
/// Cyrillic Serbian tags still reach it, ahead of the bare `sr`, and the Latin tags keep their own
|
||||
/// order. Holds without embedded catalogs (the candidates are PhotoCraft's own).
|
||||
#[test]
|
||||
fn serbian_tags_reach_the_latin_catalog() {
|
||||
assert_eq!(candidates("sr"), ["sr-latn", "sr"]);
|
||||
assert_eq!(candidates("sr-RS"), ["sr-rs", "sr-latn", "sr"]);
|
||||
assert_eq!(candidates("sr_RS@latin"), ["sr-rs", "sr-latn", "sr"]);
|
||||
assert_eq!(candidates("sr-Cyrl-RS"), ["sr-cyrl-rs", "sr-cyrl", "sr-latn", "sr"]);
|
||||
assert_eq!(candidates("sr-ME"), ["sr-me", "sr-latn", "sr"]);
|
||||
assert_eq!(candidates("sr-Latn-RS"), ["sr-latn-rs", "sr-latn", "sr"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preferences_resolve_with_fallback() {
|
||||
assert_eq!(Lang::from_pref("ja"), JA());
|
||||
assert_eq!(Lang::from_pref("JA"), JA());
|
||||
assert_eq!(Lang::from_pref("zh-hant"), ZH());
|
||||
assert_eq!(Lang::from_pref("ZH-Hant"), ZH());
|
||||
assert_eq!(Lang::from_pref("en"), Lang::EN);
|
||||
// `auto` and unknown codes follow the system (English under test).
|
||||
assert_eq!(Lang::from_pref("auto"), Lang::EN);
|
||||
assert_eq!(Lang::from_pref("xx-unknown"), Lang::EN);
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
assert_eq!(Lang::from_pref("ja"), lang("ja"));
|
||||
assert_eq!(Lang::from_pref("JA"), lang("ja"));
|
||||
assert_eq!(Lang::from_pref("zh-hant"), lang("zh-hant"));
|
||||
assert_eq!(Lang::from_pref("ZH-Hant"), lang("zh-hant"));
|
||||
assert_eq!(Lang::from_pref("ZH-Hans"), lang("zh-hans"));
|
||||
}
|
||||
|
||||
/// Without embedded catalogs the interface is English: only English is offered, every lookup is
|
||||
/// the English text, and every preference resolves to it.
|
||||
#[test]
|
||||
fn a_build_without_catalogs_is_english_only() {
|
||||
if catalogs_embedded() {
|
||||
return;
|
||||
}
|
||||
assert_eq!(Lang::all().collect::<Vec<_>>(), [Lang::EN]);
|
||||
assert_eq!(Lang::from_code("ja"), None);
|
||||
assert_eq!(Lang::from_pref("ja"), Lang::EN);
|
||||
assert_eq!(tr(Lang::EN, "Layer"), "Layer");
|
||||
assert_eq!(Lang::EN.name(), "English");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simplified_chinese_resolves_from_preferences() {
|
||||
let zh = Lang::from_code("zh-hans").expect("zh-hans registered");
|
||||
assert_eq!(Lang::from_pref("ZH-Hans"), zh);
|
||||
assert_eq!(tr(zh, "no such label"), "no such label");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spanish_resolves_and_pluralises() {
|
||||
let es = Lang::from_code("es").expect("es registered");
|
||||
fn spanish_swedish_finnish_danish_and_norwegian_resolve() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let es = lang("es");
|
||||
for tag in ["es", "es_ES.UTF-8", "es-MX", "es-419"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(es), "{tag}");
|
||||
}
|
||||
let forms: Vec<usize> = [0, 1, 3].into_iter().map(es.0.plural).collect();
|
||||
assert_eq!(forms, [1, 0, 1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn swedish_resolves_and_pluralises() {
|
||||
let sv = Lang::from_code("sv").expect("sv registered");
|
||||
let sv = lang("sv");
|
||||
assert_eq!(sv.name(), "Svenska");
|
||||
for tag in ["sv", "SV", "sv-SE", "sv_SE.UTF-8", "sv-FI", "sv_FI.UTF-8", "sv-AX"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(sv), "{tag}");
|
||||
assert_eq!(Lang::from_pref(tag), sv, "{tag}");
|
||||
}
|
||||
let forms: Vec<usize> = [0, 1, 2, 21].into_iter().map(sv.0.plural).collect();
|
||||
assert_eq!(forms, [1, 0, 1, 1]);
|
||||
assert_eq!(tr(sv, "File"), "Arkiv");
|
||||
assert_eq!(trn(sv, 1, "{n} layer", "{n} layers"), "1 lager");
|
||||
assert_eq!(trn(sv, 3, "{n} layer", "{n} layers"), "3 lager");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn finnish_resolves_and_pluralises() {
|
||||
let fi = Lang::from_code("fi").expect("fi registered");
|
||||
let fi = lang("fi");
|
||||
assert_eq!(fi.name(), "Suomi");
|
||||
for tag in ["fi", "FI", "fi-FI", "fi_FI.UTF-8"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(fi), "{tag}");
|
||||
assert_eq!(Lang::from_pref(tag), fi, "{tag}");
|
||||
}
|
||||
// Filipino and Swedish in Finland don't pick Finnish.
|
||||
@@ -221,161 +241,102 @@ fn finnish_resolves_and_pluralises() {
|
||||
for (n, layer) in [(0, "tasoa"), (1, "taso"), (2, "tasoa"), (21, "tasoa")] {
|
||||
assert_eq!(trn(fi, n, "{n} layer", "{n} layers"), format!("{n} {layer}"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn danish_resolves_and_pluralises() {
|
||||
let da = Lang::from_code("da").expect("da registered");
|
||||
let da = lang("da");
|
||||
assert_eq!(da.name(), "Dansk");
|
||||
for tag in ["da", "DA", "da-DK", "da_DK.UTF-8", "da-GL"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(da), "{tag}");
|
||||
assert_eq!(Lang::from_pref(tag), da, "{tag}");
|
||||
}
|
||||
assert_eq!(tr(da, "File"), "Filer");
|
||||
assert_eq!(trn(da, 1, "{n} document", "{n} documents"), "1 dokument");
|
||||
assert_eq!(trn(da, 3, "{n} document", "{n} documents"), "3 dokumenter");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn norwegian_resolves_and_pluralises() {
|
||||
let nb = Lang::from_code("nb").expect("nb registered");
|
||||
let nb = lang("nb");
|
||||
assert_eq!(nb.name(), "Norsk bokmål");
|
||||
for tag in ["nb", "NB", "nb-NO", "nb_NO.UTF-8", "no", "no-NO", "no_NO.UTF-8", "nn", "nn-NO", "nn_NO.UTF-8"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(nb), "{tag}");
|
||||
assert_eq!(Lang::from_pref(tag), nb, "{tag}");
|
||||
}
|
||||
assert_eq!(tr(nb, "File"), "Fil");
|
||||
assert_eq!(trn(nb, 1, "{n} item", "{n} items"), "1 element");
|
||||
assert_eq!(trn(nb, 3, "{n} item", "{n} items"), "3 elementer");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hungarian_resolves_and_keeps_the_singular_after_counts() {
|
||||
let hu = Lang::from_code("hu").expect("hu registered");
|
||||
fn hungarian_and_portuguese_resolve() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let hu = lang("hu");
|
||||
for tag in ["hu", "hu_HU.UTF-8", "hu-HU"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(hu), "{tag}");
|
||||
}
|
||||
assert_eq!(hu.name(), "Magyar");
|
||||
let forms: Vec<usize> = [0, 1, 3, 21].into_iter().map(hu.0.plural).collect();
|
||||
assert_eq!(forms, [0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn brazilian_portuguese_resolves_and_pluralises() {
|
||||
let pt = Lang::from_code("pt-br").expect("pt-br registered");
|
||||
let pt = lang("pt-br");
|
||||
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"]);
|
||||
let forms: Vec<usize> = [0, 1, 2].into_iter().map(pt.0.plural).collect();
|
||||
assert_eq!(forms, [0, 0, 1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lookups_fall_back_to_english() {
|
||||
assert_eq!(tr(JA(), "no such label"), "no such label");
|
||||
assert_eq!(tr(Lang::EN, "Layer"), "Layer");
|
||||
assert_eq!(tr(ZH(), "no such label"), "no such label");
|
||||
assert_eq!(tr_id(ZH(), "no.such.id", "Layer"), tr(ZH(), "Layer"));
|
||||
assert_eq!(tr_id(JA(), "no.such.id", "Layer"), tr(JA(), "Layer"));
|
||||
assert_eq!(tr_ctx(JA(), "no such context", "Layer"), tr(JA(), "Layer"));
|
||||
assert_eq!(trn(JA(), 3, "{n} no such message", "{n} no such messages"), "3 no such messages");
|
||||
}
|
||||
|
||||
/// Romanian: 1 is one; 0 and counts ending in 01–19 are few ("2 straturi", "119 straturi");
|
||||
/// the rest take "de" ("20 de straturi", "121 de straturi").
|
||||
#[test]
|
||||
fn romanian_plural_rule() {
|
||||
let ro = Lang::from_code("ro").expect("ro registered");
|
||||
let counts = [0, 1, 2, 19, 20, 21, 100, 101, 119, 120, 121, 1001];
|
||||
let forms: Vec<usize> = counts.into_iter().map(ro.0.plural).collect();
|
||||
assert_eq!(forms, [1, 0, 1, 1, 2, 2, 2, 1, 1, 2, 2, 1]);
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let (ja, zh) = (lang("ja"), lang("zh-hant"));
|
||||
assert_eq!(tr(ja, "no such label"), "no such label");
|
||||
assert_eq!(tr(zh, "no such label"), "no such label");
|
||||
assert_eq!(tr_id(zh, "no.such.id", "Layer"), tr(zh, "Layer"));
|
||||
assert_eq!(tr_id(ja, "no.such.id", "Layer"), tr(ja, "Layer"));
|
||||
assert_eq!(tr_ctx(ja, "no such context", "Layer"), tr(ja, "Layer"));
|
||||
assert_eq!(trn(ja, 3, "{n} no such message", "{n} no such messages"), "3 no such messages");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn russian_plural_rule() {
|
||||
let ru = Lang::from_code("ru").expect("ru registered");
|
||||
let forms: Vec<usize> = [0, 1, 2, 5, 11, 12, 14, 21, 22, 25, 101, 111, 112].into_iter().map(ru.0.plural).collect();
|
||||
assert_eq!(forms, [2, 0, 1, 2, 2, 2, 2, 0, 1, 2, 0, 2, 2]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ukrainian_resolves_locales_and_preferences() {
|
||||
let uk = Lang::from_code("uk").expect("uk registered");
|
||||
fn ukrainian_and_arabic_resolve() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let uk = lang("uk");
|
||||
assert_eq!(uk.name(), "Українська");
|
||||
for tag in ["uk", "UK", "uk-UA", "uk_UA", "uk_UA.UTF-8", "uk-UA@euro", "uk-Cyrl-UA"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(uk), "{tag}");
|
||||
assert_eq!(Lang::from_pref(tag), uk, "{tag}");
|
||||
}
|
||||
assert_eq!(tr(uk, "unknown translation"), "unknown translation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ukrainian_plural_rule_handles_teens_and_compound_counts() {
|
||||
let uk = Lang::from_code("uk").expect("uk registered");
|
||||
let counts = [0, 1, 2, 4, 5, 11, 12, 14, 19, 21, 22, 24, 25, 100, 101, 111, 112, 114, 121, 122, u64::MAX];
|
||||
let forms: Vec<usize> = counts.into_iter().map(uk.0.plural).collect();
|
||||
assert_eq!(forms, [2, 0, 1, 1, 2, 2, 2, 2, 2, 0, 1, 1, 2, 2, 0, 2, 2, 2, 0, 1, 2]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arabic_resolves_locales_and_preferences() {
|
||||
let ar = Lang::from_code("ar").expect("ar registered");
|
||||
let ar = lang("ar");
|
||||
assert_eq!(ar.name(), "العربية");
|
||||
for tag in ["ar", "AR", "ar-SA", "ar_EG", "ar_EG.UTF-8", "ar-AE", "ar-MA"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(ar), "{tag}");
|
||||
assert_eq!(Lang::from_pref(tag), ar, "{tag}");
|
||||
}
|
||||
assert_eq!(dir_for_code("ar"), Dir::Rtl);
|
||||
assert_eq!(ar.dir(), Dir::Rtl);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arabic_plural_rule_has_six_forms() {
|
||||
let ar = Lang::from_code("ar").expect("ar registered");
|
||||
let counts = [0, 1, 2, 3, 10, 11, 99, 100, 101, 102, 103, 111, 199, 1000, u64::MAX];
|
||||
let forms: Vec<usize> = counts.into_iter().map(ar.0.plural).collect();
|
||||
assert_eq!(forms, [0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 3, 4, 4, 5, 4]);
|
||||
}
|
||||
|
||||
/// Every Serbian tag PhotoCraft matched to its `sr` catalog reaches `sr-latn`, as a system tag and
|
||||
/// as a preference (a saved `sr` included).
|
||||
#[test]
|
||||
fn serbian_resolves_locales_and_preferences() {
|
||||
let sr = Lang::from_code("sr").expect("sr registered");
|
||||
assert_eq!(sr.name(), "Srpski");
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let sr = lang("sr-latn");
|
||||
for tag in ["sr", "SR", "sr-RS", "sr_RS", "sr_RS.UTF-8", "sr_RS@latin", "sr-Latn", "sr-Latn-RS", "sr-Cyrl-RS", "sr-ME"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(sr), "{tag}");
|
||||
assert_eq!(Lang::from_pref(tag), sr, "{tag}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serbian_plural_rule_handles_teens_and_compound_counts() {
|
||||
let sr = Lang::from_code("sr").expect("sr registered");
|
||||
let counts = [0, 1, 2, 4, 5, 11, 12, 14, 21, 22, 25, 101, 111, 112, 122];
|
||||
let forms: Vec<usize> = counts.into_iter().map(sr.0.plural).collect();
|
||||
assert_eq!(forms, [2, 0, 1, 1, 2, 2, 2, 2, 0, 1, 2, 0, 2, 2, 1]);
|
||||
}
|
||||
|
||||
/// The catalog resolves regional tags, exposes its native name and falls back to English.
|
||||
#[test]
|
||||
fn azerbaijani_resolves_locales_and_preferences() {
|
||||
let lang = Lang::from_code("az").expect("az registered");
|
||||
assert_eq!(lang.name(), "Azərbaycanca");
|
||||
assert_eq!(lang.dir(), Dir::Ltr);
|
||||
assert!(lang.complete_menus());
|
||||
for tag in ["az", "AZ", "az-AZ", "az_AZ.UTF-8", "az-Latn", "AZ-LATN-AZ"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(lang), "{tag}");
|
||||
assert_eq!(Lang::from_pref(tag), lang, "{tag}");
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
assert_eq!(tr(lang, "unknown translation"), "unknown translation");
|
||||
}
|
||||
|
||||
/// Integer plural boundaries select one only at 1, including large counts without overflow.
|
||||
#[test]
|
||||
fn azerbaijani_plural_counts_include_hundreds_and_large_values() {
|
||||
let az = Lang::from_code("az").expect("az registered");
|
||||
let counts = [0, 1, 2, 11, 19, 20, 21, 99, 100, 101, 102, 119, 120, 1000, 1001, u64::MAX];
|
||||
assert_eq!(counts.map(az.0.plural), [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
|
||||
for n in counts {
|
||||
let az = lang("az");
|
||||
assert_eq!(az.name(), "Azərbaycanca");
|
||||
assert_eq!(az.dir(), Dir::Ltr);
|
||||
assert!(az.complete_menus());
|
||||
for tag in ["az", "AZ", "az-AZ", "az_AZ.UTF-8", "az-Latn", "AZ-LATN-AZ"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(az), "{tag}");
|
||||
assert_eq!(Lang::from_pref(tag), az, "{tag}");
|
||||
}
|
||||
assert_eq!(tr(az, "unknown translation"), "unknown translation");
|
||||
for n in [0, 1, 2, 11, 19, 20, 21, 99, 100, 101, 102, 119, 120, 1000, 1001, u64::MAX] {
|
||||
assert_eq!(trn(az, n, "{n} layer", "{n} layers"), format!("{n} qat"));
|
||||
}
|
||||
}
|
||||
@@ -383,56 +344,97 @@ fn azerbaijani_plural_counts_include_hundreds_and_large_values() {
|
||||
/// Exact lookups retain contextual meanings, dotted/dotless letters and product placeholders.
|
||||
#[test]
|
||||
fn azerbaijani_keeps_context_placeholders_and_command_names() {
|
||||
let lang = Lang::from_code("az").expect("az registered");
|
||||
for (source, translated) in [("File", "Fayl"), ("Layer", "Qat"), ("Kind", "Növ"), ("Type Layer", "Mətn qatı"), ("Light Theme", "Açıq mövzu")] {
|
||||
assert_eq!(tr(lang, source), translated);
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
assert_eq!(tr_ctx(lang, "cameraRaw", "Light"), "İşıq");
|
||||
assert_eq!(tr_ctx(lang, "fontWeight", "Light"), "İncə");
|
||||
assert_ne!(tr_id(lang, "edit.clear", "Clear"), "Clear");
|
||||
assert!(fmt(tr(lang, "About {app}"), &[("app", "PhotoCraft")]).contains("PhotoCraft"));
|
||||
let az = lang("az");
|
||||
for (source, translated) in [("File", "Fayl"), ("Layer", "Qat"), ("Kind", "Növ"), ("Type Layer", "Mətn qatı"), ("Light Theme", "Açıq mövzu")] {
|
||||
assert_eq!(tr(az, source), translated);
|
||||
}
|
||||
assert_eq!(tr_ctx(az, "cameraRaw", "Light"), "İşıq");
|
||||
assert_eq!(tr_ctx(az, "fontWeight", "Light"), "İncə");
|
||||
assert_ne!(tr_id(az, "edit.clear", "Clear"), "Clear");
|
||||
assert!(fmt(tr(az, "About {app}"), &[("app", "PhotoCraft")]).contains("PhotoCraft"));
|
||||
}
|
||||
|
||||
/// Bosnian locales, with or without region, script or encoding, select the Latin catalog.
|
||||
#[test]
|
||||
fn bosnian_resolves_locales_and_preferences() {
|
||||
let bs = Lang::from_code("bs").expect("bs registered");
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let bs = lang("bs");
|
||||
assert_eq!(bs.name(), "Bosanski");
|
||||
for tag in ["bs", "BS", "bs-BA", "bs_BA", "bs_BA.UTF-8", "bs-Latn", "bs-Latn-BA", "bs-Cyrl-BA", "bs_BA@cyrillic"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(bs), "{tag}");
|
||||
assert_eq!(Lang::from_pref(tag), bs, "{tag}");
|
||||
}
|
||||
assert_ne!(lang_from_tag("hr-HR"), Some(bs), "Croatian is not Bosnian");
|
||||
}
|
||||
|
||||
/// Bosnian counts: 1, 21, 101 are `one`; 2–4, 22–24 (not 12–14) `few`; everything else `other`.
|
||||
#[test]
|
||||
fn bosnian_plural_rule_handles_teens_and_compound_counts() {
|
||||
let bs = Lang::from_code("bs").expect("bs registered");
|
||||
let counts = [0, 1, 2, 4, 5, 11, 12, 14, 21, 22, 25, 101, 111, 112, 122];
|
||||
let forms: Vec<usize> = counts.into_iter().map(bs.0.plural).collect();
|
||||
assert_eq!(forms, [2, 0, 1, 1, 2, 2, 2, 2, 0, 1, 2, 0, 2, 2, 1]);
|
||||
assert_eq!(trn(bs, 3, "{n} pixel", "{n} pixels"), "3 piksela");
|
||||
assert_eq!(trn(bs, 5, "{n} document", "{n} documents"), "5 dokumenata");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn catalog_kinds_are_parsed_and_looked_up() {
|
||||
let c = Catalog::parse("# c\n\tHello\tこんにちは\n@id\tfile.save\t保存する\nmenu\tWindows\tウィンドウ群\n@plural\t{n} file|{n} files\t{n} 個\n\n");
|
||||
assert_eq!(c.plain("Hello"), Some("こんにちは"));
|
||||
assert_eq!(c.id("file.save"), Some("保存する"));
|
||||
assert_eq!(c.contextual("menu", "Windows"), Some("ウィンドウ群"));
|
||||
assert_eq!(c.contextual("other", "Windows"), None);
|
||||
assert_eq!(c.plural("{n} file", "{n} files", 0), Some("{n} 個"));
|
||||
assert_eq!(c.plural("{n} file", "{n} files", 5), Some("{n} 個"), "an index past the forms clamps");
|
||||
fn french_resolves() {
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let fr = lang("fr");
|
||||
for tag in ["fr", "fr_FR.UTF-8", "fr-CA", "fr_BE", "fr-CH"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(fr), "{tag}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Counts pick the form PhotoCraft's own plural rules picked before its catalogs moved to
|
||||
/// craft-i18n, now from CLDR (the crate): per language, the old rule's form index per count.
|
||||
/// Exceptions, from the spec's parity list or CLDR: Hungarian, Turkish and Georgian have two forms
|
||||
/// (their catalogs repeat the one form), Hebrew's `two` form repeats `other`
|
||||
/// ([`hebrew_counts_read_one_or_other`]), and Hindi's 0 takes the `one` form.
|
||||
#[test]
|
||||
fn malformed_lines_are_reported_not_fatal() {
|
||||
let (entries, errors) = parse_entries("\tok\tはい\nno tabs here\n\tonly\n\ta\tb\tc\textra\n\t\tempty source\n");
|
||||
assert_eq!(entries.len(), 1);
|
||||
assert_eq!(errors.len(), 4, "{errors:?}");
|
||||
assert_eq!(parse_entries("\ta\\tb\tx\\ny\\\\z\n").0[0], (String::new(), "a\tb".into(), "x\ny\\z".into()));
|
||||
fn counts_pick_the_same_plural_form_as_before() {
|
||||
const MAX: u64 = u64::MAX;
|
||||
let cases: &[(&'static str, usize, &[u64], &[usize])] = &[
|
||||
("ar", 6, &[0, 1, 2, 3, 10, 11, 99, 100, 101, 102, 103, 111, 199, 1000, MAX], &[0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 3, 4, 4, 5, 4]),
|
||||
("ro", 3, &[0, 1, 2, 19, 20, 21, 100, 101, 119, 120, 121, 1001], &[1, 0, 1, 1, 2, 2, 2, 1, 1, 2, 2, 1]),
|
||||
("ru", 3, &[0, 1, 2, 5, 11, 12, 14, 21, 22, 25, 101, 111, 112], &[2, 0, 1, 2, 2, 2, 2, 0, 1, 2, 0, 2, 2]),
|
||||
(
|
||||
"uk",
|
||||
3,
|
||||
&[0, 1, 2, 4, 5, 11, 12, 14, 19, 21, 22, 24, 25, 100, 101, 111, 112, 114, 121, 122, MAX],
|
||||
&[2, 0, 1, 1, 2, 2, 2, 2, 2, 0, 1, 1, 2, 2, 0, 2, 2, 2, 0, 1, 2],
|
||||
),
|
||||
("sr-latn", 3, &[0, 1, 2, 4, 5, 11, 12, 14, 21, 22, 25, 101, 111, 112, 122], &[2, 0, 1, 1, 2, 2, 2, 2, 0, 1, 2, 0, 2, 2, 1]),
|
||||
("bs", 3, &[0, 1, 2, 4, 5, 11, 12, 14, 21, 22, 25, 101, 111, 112, 122], &[2, 0, 1, 1, 2, 2, 2, 2, 0, 1, 2, 0, 2, 2, 1]),
|
||||
("pl", 3, &[0, 1, 2, 4, 5, 12, 14, 21, 22, 25, 112, 122], &[2, 0, 1, 1, 2, 2, 2, 2, 1, 2, 2, 1]),
|
||||
("cs", 3, &[0, 1, 2, 3, 4, 5, 11, 12, 21, 22, 100, MAX], &[2, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]),
|
||||
("fr", 2, &[0, 1, 2, 5, 100, 1_000_000, MAX], &[0, 0, 1, 1, 1, 1, 1]),
|
||||
("pt-br", 2, &[0, 1, 2, 1_000_000], &[0, 0, 1, 1]),
|
||||
("es", 2, &[0, 1, 3, 1_000_000], &[1, 0, 1, 1]),
|
||||
("it", 2, &[0, 1, 3, 1_000_000], &[1, 0, 1, 1]),
|
||||
("hi", 2, &[1, 2, 5, 21], &[0, 1, 1, 1]),
|
||||
("ja", 1, &[0, 1, 5], &[0, 0, 0]),
|
||||
("th", 1, &[0, 1, 5], &[0, 0, 0]),
|
||||
];
|
||||
let one_other = ["sv", "fi", "da", "nb", "de", "nl", "el", "az", "ta", "ur"];
|
||||
let one_other_cases = one_other.map(|code| (code, 2, &[0, 1, 2, 21, 1_000_000][..], &[1, 0, 1, 1, 1][..]));
|
||||
for &(code, forms, counts, expected) in cases.iter().chain(one_other_cases.iter()) {
|
||||
let row: String = (0..forms).map(|i| format!("{{n}} f{i}")).collect::<Vec<_>>().join("|");
|
||||
let lang = fixture_lang(code, Box::leak(format!("@plural\t{{n}} x|{{n}} xs\t{row}\n").into_boxed_str()));
|
||||
for (&n, &index) in counts.iter().zip(expected) {
|
||||
assert_eq!(trn(lang, n, "{n} x", "{n} xs"), format!("{n} f{index}"), "{code}, {n}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Hebrew counts read as PhotoCraft's one|other rule did: craft-i18n's Hebrew rows list
|
||||
/// one|two|other with `two` repeating `other`, so 2 reads like 3.
|
||||
#[test]
|
||||
fn hebrew_counts_read_one_or_other() {
|
||||
let he = fixture_lang("he", "@plural\t{n} layer|{n} layers\tשכבה {n}|{n} שכבות|{n} שכבות\n");
|
||||
for n in [0, 2, 3, 10, 11, 20, 100, 1000, u64::MAX] {
|
||||
assert_eq!(trn(he, n, "{n} layer", "{n} layers"), format!("{n} שכבות"), "{n}");
|
||||
}
|
||||
assert_eq!(trn(he, 1, "{n} layer", "{n} layers"), "שכבה 1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -440,40 +442,18 @@ fn plurals_and_placeholders() {
|
||||
assert_eq!(trn(Lang::EN, 1, "{n} item", "{n} items"), "1 item");
|
||||
assert_eq!(trn(Lang::EN, 0, "{n} item", "{n} items"), "0 items");
|
||||
assert_eq!(trn(Lang::EN, 7, "{n} item", "{n} items"), "7 items");
|
||||
let cs = fixture_lang(plural_cs, "@plural\t{n} item|{n} items\t{n} one|{n} few|{n} other\n");
|
||||
for (n, expected) in [(0, "0 other"), (1, "1 one"), (3, "3 few"), (5, "5 other")] {
|
||||
assert_eq!(trn(cs, n, "{n} item", "{n} items"), expected);
|
||||
}
|
||||
let ja = fixture_lang(plural_none, "@plural\t{n} item|{n} items\t{n} only\n");
|
||||
assert_eq!(trn(Lang::EN, 1234, "{n} item", "{n} items"), "1234 items", "no grouping");
|
||||
let ja = fixture_lang("ja", "@plural\t{n} item|{n} items\t{n} only\n");
|
||||
assert_eq!(trn(ja, 1, "{n} item", "{n} items"), "1 only");
|
||||
assert_eq!(trn(ja, 7, "{n} item", "{n} items"), "7 only");
|
||||
assert_eq!(trn(ja, 7, "{n} file", "{n} files"), "7 files", "a missing row falls back to English");
|
||||
assert_eq!(fmt("{b} before {a}", &[("a", "x"), ("b", "y"), ("c", "z")]), "y before x");
|
||||
assert_eq!(fmt("{missing}", &[]), "{missing}");
|
||||
assert_eq!(placeholders("a {x} b {y} {"), ["x", "y"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn french_resolves_and_pluralises() {
|
||||
let fr = Lang::from_code("fr").expect("fr registered");
|
||||
for tag in ["fr", "fr_FR.UTF-8", "fr-CA", "fr_BE", "fr-CH"] {
|
||||
assert_eq!(lang_from_tag(tag), Some(fr), "{tag}");
|
||||
}
|
||||
let forms: Vec<usize> = [0, 1, 2, 5, 100, u64::MAX].into_iter().map(fr.0.plural).collect();
|
||||
assert_eq!(forms, [0, 0, 1, 1, 1, 1]);
|
||||
}
|
||||
|
||||
/// A language whose catalog is `text`, for testing lookups without depending on a bundled
|
||||
/// catalog's wording.
|
||||
fn fixture_lang(plural: fn(u64) -> usize, text: &str) -> Lang {
|
||||
let catalog = OnceLock::new();
|
||||
let _ = catalog.set(Catalog::parse(text));
|
||||
Lang(Box::leak(Box::new(LangInfo { code: "xx", name: "x", source: b"", plural, complete_menus: false, catalog })))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn id_and_context_rows_win_over_the_plain_label() {
|
||||
let lang = fixture_lang(plural_one_other, "\tAll\tplain all\n@id\tselect.all\tid all\nnavigator\tZoom\tcontext zoom\n\tZoom\tplain zoom\n");
|
||||
let lang = fixture_lang("de", "\tAll\tplain all\n@id\tselect.all\tid all\nnavigator\tZoom\tcontext zoom\n\tZoom\tplain zoom\n");
|
||||
assert_eq!(tr_id(lang, "select.all", "All"), "id all");
|
||||
assert_eq!(tr_id(lang, "edit.other", "All"), "plain all");
|
||||
assert_eq!(tr(lang, "All"), "plain all");
|
||||
@@ -482,88 +462,43 @@ fn id_and_context_rows_win_over_the_plain_label() {
|
||||
assert_eq!(tr_ctx(lang, "navigator", "Unlisted"), "Unlisted");
|
||||
}
|
||||
|
||||
/// An `@id` row that drops its label's `{placeholders}` or trailing `…` is skipped: the label's
|
||||
/// own translation shows, so a menu item never loses the "opens a dialog" mark or a value.
|
||||
#[test]
|
||||
fn polish_plural_rule() {
|
||||
let forms: Vec<usize> = [0, 1, 2, 4, 5, 12, 14, 21, 22, 25, 112, 122].into_iter().map(plural_polish).collect();
|
||||
assert_eq!(forms, [2, 0, 1, 1, 2, 2, 2, 2, 1, 2, 2, 1]);
|
||||
fn id_rows_keep_the_shape_of_their_label() {
|
||||
let lang = fixture_lang("de", "\tStroke…\tKontur…\n@id\tedit.stroke\tKontur\n@id\tlayer.rename\t{name} umbenennen\n");
|
||||
assert_eq!(tr_id(lang, "edit.stroke", "Stroke…"), "Kontur…", "the row without … is skipped");
|
||||
assert_eq!(tr_id(lang, "layer.rename", "Rename {name}"), "{name} umbenennen");
|
||||
assert_eq!(tr_id(lang, "layer.rename", "Rename {layer}"), "Rename {layer}", "a different placeholder");
|
||||
assert!(same_shape("{b} und {a}", "{a} and {b}"), "placeholders may be reordered");
|
||||
assert!(!same_shape("Öffnen {name…", "Open…"), "a placeholder left open");
|
||||
assert!(!same_shape("Öffnen name}…", "Open…"), "a closing brace without its opening one");
|
||||
assert!(!same_shape("{name}} öffnen", "Open {name}"), "a second closing brace");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn czech_plural_rule() {
|
||||
let forms: Vec<usize> = [0, 1, 2, 3, 4, 5, 11, 12, 21, 22, 100, u64::MAX].into_iter().map(plural_cs).collect();
|
||||
assert_eq!(forms, [2, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]);
|
||||
}
|
||||
|
||||
/// The packed catalogs in the binary unpack to exactly the `.tsv` files.
|
||||
#[test]
|
||||
fn packed_catalogs_match_their_files() {
|
||||
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src/i18n");
|
||||
for l in LANGUAGES.iter().skip(1) {
|
||||
let file = std::fs::read_to_string(dir.join(format!("{}.tsv", l.code))).unwrap();
|
||||
assert_eq!(unpack(l.source).unwrap(), file, "{}", l.code);
|
||||
assert!(l.source.len() < file.len() / 2, "{}: stored deflated", l.code);
|
||||
}
|
||||
assert_eq!(LANGUAGES[0].text(), "", "English has no catalog");
|
||||
}
|
||||
|
||||
/// Corrupt catalog data is an error (English is shown), not a panic.
|
||||
#[test]
|
||||
fn corrupt_catalog_data_is_an_error() {
|
||||
assert!(inflate(b"\xff\xff\xff\xff not deflate").is_err());
|
||||
let ja = LANGUAGES.iter().find(|l| l.code == "ja").unwrap();
|
||||
assert!(inflate(&ja.source[..ja.source.len() / 2]).is_err(), "truncated");
|
||||
let info: &'static LangInfo =
|
||||
Box::leak(Box::new(LangInfo { code: "xx", name: "x", source: b"\x00garbage", plural: plural_none, complete_menus: false, catalog: OnceLock::new() }));
|
||||
assert_eq!(info.text(), "");
|
||||
assert_eq!(tr(Lang(info), "Layer"), "Layer", "falls back to English");
|
||||
}
|
||||
|
||||
/// Packed lines unpack to their keys; references to keys that don't exist are an error, not a
|
||||
/// panic.
|
||||
#[test]
|
||||
fn packed_lines_unpack_and_bad_references_are_errors() {
|
||||
let keys = ["\tOpen", "@id\tfile.open", "\tClose"];
|
||||
let packed = "# c\n\x01Ouvrir\n\x02-1\tOuvrir\n\x02+1\tFermer\n\x03\x01x\n";
|
||||
assert_eq!(expand(packed, &keys).unwrap(), "# c\n\tOpen\tOuvrir\n\tOpen\tOuvrir\n\tClose\tFermer\n\x01x\n");
|
||||
for bad in ["\x02-1\tx", "\x02 3\tx", "\x023", "\x029223372036854775807\tx", "\x02-9223372036854775808\tx", "\x01a\n\x01b\n\x01c\n\x01d"] {
|
||||
assert!(expand(bad, &keys).is_err(), "{bad:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Every bundled catalog is well-formed and consistent with its sources.
|
||||
/// The language list is well-formed. Problems in the embedded catalogs are not failed: craft-i18n
|
||||
/// checks its rows, a row PhotoCraft can't use shows in English, and `cargo xtask i18n-report`
|
||||
/// lists what each language lacks.
|
||||
#[test]
|
||||
fn bundled_catalogs_are_consistent() {
|
||||
let mut codes = std::collections::HashSet::new();
|
||||
for l in &LANGUAGES {
|
||||
assert!(l.code == l.code.to_ascii_lowercase() && !l.name.is_empty(), "{}", l.code);
|
||||
let (entries, errors) = parse_entries(&l.text());
|
||||
assert!(errors.is_empty(), "{}: {errors:?}", l.code);
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
for (ctx, src, tr) in &entries {
|
||||
assert!(seen.insert((ctx.clone(), src.clone())), "{}: duplicate {ctx:?} {src:?}", l.code);
|
||||
if ctx == "@plural" {
|
||||
let one_other: Vec<&str> = src.split('|').collect();
|
||||
assert_eq!(one_other.len(), 2, "{}: plural source must be `one|other`: {src:?}", l.code);
|
||||
let forms = (0..=1000).map(l.plural).max().unwrap_or(0) + 1;
|
||||
assert_eq!(tr.split('|').count(), forms, "{}: {forms} plural forms expected in {src:?}", l.code);
|
||||
for form in tr.split('|') {
|
||||
let mut want = placeholders(one_other[1]);
|
||||
let mut got = placeholders(form);
|
||||
want.sort_unstable();
|
||||
got.sort_unstable();
|
||||
assert_eq!(want, got, "{}: placeholders differ in {src:?}", l.code);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let mut want = placeholders(src);
|
||||
let mut got = placeholders(tr);
|
||||
want.sort_unstable();
|
||||
got.sort_unstable();
|
||||
assert_eq!(want, got, "{}: placeholders differ in {src:?}", l.code);
|
||||
if ctx.is_empty() {
|
||||
assert_eq!(src.ends_with('…'), tr.ends_with('…'), "{}: ellipsis mismatch: {src:?}", l.code);
|
||||
}
|
||||
if ctx == "@id" {
|
||||
assert!(crate::menus::is_live(src) || crate::menu_catalog::CATALOG.iter().any(|m| m.3 == src), "{}: unknown command id {src:?}", l.code);
|
||||
assert!(codes.insert(l.code), "duplicate code {}", l.code);
|
||||
assert!(l.code == l.code.to_ascii_lowercase() && !l.code.is_empty(), "{}", l.code);
|
||||
}
|
||||
assert_eq!(LANGUAGES.first().map(|l| l.code), Some("en"), "English first: the source and the fallback");
|
||||
if !needs_catalogs() {
|
||||
return;
|
||||
}
|
||||
let problems = I18N.check_all();
|
||||
if !problems.is_empty() {
|
||||
println!("{} catalog rows are skipped (they show in English):\n{problems:#?}", problems.len());
|
||||
}
|
||||
for (code, _, app) in CRAFT_I18N {
|
||||
for line in app.lines().filter(|l| l.starts_with("@id\t")) {
|
||||
let id = line.split('\t').nth(1).unwrap_or_default();
|
||||
if id != "language.name" && !(crate::menus::is_live(id) || crate::menu_catalog::CATALOG.iter().any(|m| m.3 == id)) {
|
||||
println!("{code}: @id row for a command PhotoCraft doesn't have: {id:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
- **Never crash:** non-test code must not panic: no `unwrap`/`expect`/`panic!`/`unreachable!`/`todo!`/`unimplemented!` and no `unsafe`. Errors go through `Result` and `?`, input-derived indices and sizes are checked, and every crash fix ships with a regression test. See *Never crash* in `AGENTS.md`.
|
||||
- **Commands, not handlers:** new features are engine commands with tests, and the UI calls them (checklist below).
|
||||
- **Layering:** `cargo xtask layers` must pass. Register new crates in `xtask/src/layers.rs`.
|
||||
- **Tests:** required for every change. Format code needs round-trip and malformed-input tests. Pixel code is tested at 8, 16 and 32-bit. If you touch psd, io, codecs, compose, gpu, text or format, also run the real-file corpus tests: `cargo xtask test-corpus` (fetches the pinned corpora, including our Photoshop oracles from https://github.com/storytold/photocraft-corpus, then runs the `corpus`-feature tests; CI always runs them). Never commit corpus files; see `docs/development.md` › Test corpora. Tests never require a string to be translated: a missing translation shows in English, so no test may fail because a catalog lacks a row (`cargo xtask i18n-coverage` lists the gaps instead).
|
||||
- **Tests:** required for every change. Format code needs round-trip and malformed-input tests. Pixel code is tested at 8, 16 and 32-bit. If you touch psd, io, codecs, compose, gpu, text or format, also run the real-file corpus tests: `cargo xtask test-corpus` (fetches the pinned corpora, including our Photoshop oracles from https://github.com/storytold/photocraft-corpus, then runs the `corpus`-feature tests; CI always runs them). Never commit corpus files; see `docs/development.md` › Test corpora. Tests never require a string to be translated: a missing translation shows in English, so no test may fail because a catalog lacks a row (`cargo xtask i18n-report` lists the gaps instead).
|
||||
- **Style:** `cargo fmt`, and `cargo clippy -- -D warnings`. Match surrounding code. Comments explain *why*.
|
||||
- **UI:** use `theme::Tokens` and `widgets::*`. Verify visually (offscreen `snapshot` example or the control channel) before submitting, and attach before/after screenshots to PRs.
|
||||
- **Commits:** small, focused, with a clear subject line.
|
||||
|
||||
@@ -24,7 +24,7 @@ the AI models named in `Co-Authored-By` trailers.
|
||||
|
||||
- The About window is `DialogKind::About` in `crates/ui-egui/src/dialogs.rs` (Help ▸ About PhotoCraft).
|
||||
Its tab is the dialog field `tab` (`about`, `contributors`, `models`), so agents can switch it with
|
||||
`ui.dialog.set`. Labels are translated like the rest of the shell (`tl!` + `crates/ui-egui/src/i18n/*.tsv`).
|
||||
`ui.dialog.set`. Labels are translated like the rest of the shell (`tl!` + craft-i18n's `locales/<code>/photocraft.tsv`).
|
||||
|
||||
## Credit yourself
|
||||
|
||||
|
||||
+25
-9
@@ -134,6 +134,21 @@ CRAFT_FONTS_DIR="$PWD/../craft-fonts" cargo test --workspace # runs the Japa
|
||||
- **Web:** the wasm32 build never embeds craft-fonts, even with `CRAFT_FONTS_DIR` set: measured on 2026-10-06, the UI face alone took the release wasm from 24.19 MB to 28.87 MB, over the 24 MiB gate in `packaging/web/package.sh`. Instead it loads fonts served next to it, on demand: `fonts/manifest.txt` beside `index.html`, in craft-fonts' manifest format (`crates/text/src/served.rs`; hosting: `packaging/web/README.md` › Fonts). `PHOTOCRAFT_WEB_FONTS_DIR="$PWD/../craft-fonts" packaging/web/package.sh` puts craft-fonts there. Served families are in the font menus and are fetched when picked or when a document's text needs them; they aren't in the script fallback list yet, so Japanese text set in a Latin font still needs a Japanese font picked (#1615).
|
||||
- Tests that need the fonts skip with a message when `CRAFT_FONTS` is empty; CI's Linux gate and Windows test legs build with `CRAFT_FONTS_DIR` set and `CRAFT_FONTS_REQUIRED=1`, so they run there. Desktop releases check out craft-fonts at the commit pinned in `.github/workflows/release.yml` (`CRAFT_FONTS_REF`; ci.yml pins the same commit) and ship each font's `OFL.txt` as `OFL-<family>.txt`.
|
||||
|
||||
## Translations (craft-i18n)
|
||||
|
||||
The interface catalogs live in [storytold/craft-i18n](https://github.com/storytold/craft-i18n) (`locales/<code>/common.tsv`, shared by the Crafting Apps, and `photocraft.tsv`), never in this repo. Like craft-fonts it is an **optional build input**, never a Cargo dependency; `craft-i18n.rev` pins the commit CI, releases and the flatpak manifests use:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/storytold/craft-i18n ../craft-i18n
|
||||
git -C ../craft-i18n checkout "$(tr -d '[:space:]' < craft-i18n.rev)"
|
||||
CRAFT_I18N_DIR="$PWD/../craft-i18n" cargo run --release -p photocraft
|
||||
```
|
||||
|
||||
- Use an absolute path: `crates/ui-egui/build.rs` embeds every locale with a `photocraft.tsv` (and its `common.tsv`) as `CRAFT_I18N`, read through the `craft-i18n` crate (`crates/ui-egui/src/i18n.rs`). Unset, `CRAFT_I18N` is empty and the interface is English only; a bad path is a build warning, or an error with `CRAFT_I18N_REQUIRED=1` (CI and release builds set both, through craft-common-actions' `checkout-craft-i18n`).
|
||||
- The web build embeds the same catalogs, raw: they ship inside the gzipped wasm parts (`packaging/web/package.sh`), so only the download grows with them.
|
||||
- Tests that need a translation skip with a note when `CRAFT_I18N` is empty; CI builds with it, so they run there.
|
||||
- A PR here adds English only; translations are added in craft-i18n and reach PhotoCraft when `craft-i18n.rev` moves (a test keeps both flatpak manifests on the same commit). `cargo xtask i18n-report` lists what each language lacks.
|
||||
|
||||
## One instance per user
|
||||
|
||||
On Windows and Linux the first PhotoCraft holds an exclusive lock on `instance.lock` in the config directory and listens on a loopback port named in `instance.json` (with a fresh 256-bit token; the file is 0600 on Unix). Inside a Flatpak it listens on a Unix socket instead, `$XDG_RUNTIME_DIR/app/<app id>/instance.sock` (0600), because Flatpak isolates each sandbox's network namespace, loopback included, unless the app is granted `--share=network`, while that runtime directory is shared by all sandboxes of the app (#1540); the lock, token and protocol are the same. A later launch hands its file arguments there and exits, so files opened from Explorer or a file manager become tabs in the running window (#3708). The primary answers `ok` only once its UI has taken the files; a launch that gets anything else (the primary is starting, hung or closing) keeps retrying the lock for up to 10 s, becoming the primary itself once the old one lets go, and then starts a separate instance, so a file is never acknowledged and lost. When the event loop ends (and before the CPU-compatibility relaunch) the primary refuses new files and frees the lock. It applies only with the per-user settings folder: a portable copy (`PhotoCraftData` beside the executable) or `PHOTOCRAFT_CONFIG_DIR` may be shared between users, so those launches run separately. So do `--new-instance` (or `PHOTOCRAFT_NEW_INSTANCE=1`), every `--control` launch, and launches given a per-process option (`--safe-gpu`, `--present-mode`, `--frame-latency`, `--stroke-trace`, `--in-window-menus`, `--automation-*-root`). A `cargo run` while an installed PhotoCraft is running forwards to it: pass `--new-instance` or set `PHOTOCRAFT_CONFIG_DIR`. macOS gets the same behaviour from LaunchServices (`apple_events.rs`). On native Wayland the running window can't bring itself forward (that takes the launcher's `XDG_ACTIVATION_TOKEN`, and winit 0.30 can't activate an existing window with one), so it asks for attention instead and the taskbar highlights it; X11, XWayland and Windows bring it to the front. Code: `apps/photocraft/src/single_instance.rs`.
|
||||
@@ -394,15 +409,16 @@ intents, black point compensation). It ships CC0 built-in profiles, including a
|
||||
the live command registry (`menus::is_live`) and rewrites [`docs/parity-checklist.md`](parity-checklist.md). The test
|
||||
`parity::tests::parity_does_not_regress` fails if the live count drops below `parity::FLOOR`.
|
||||
|
||||
`cargo xtask i18n-coverage` prints the UI translation coverage for each language in the
|
||||
`crates/ui-egui/src/i18n.rs` registry, in stable language-code order. Its English-key set is
|
||||
derived from UI `tl!` literals, the menu catalog and UI command table, and menu command labels in
|
||||
the engine source. Catalog rows are validated for malformed and duplicate keys; unused legacy
|
||||
translations do not affect the denominator. Unregistered locale TSV files are ignored. After the
|
||||
counts it lists, per language, the source keys the catalog lacks (one line for a language with
|
||||
none). A missing translation shows in English and fails nothing: `cargo xtask ci` runs the report
|
||||
as its last step so the list appears in the log, and only prints a warning if the report itself
|
||||
can't run.
|
||||
`cargo xtask i18n-report` prints the UI translation coverage for each language in the
|
||||
`crates/ui-egui/src/i18n.rs` registry, in stable language-code order, from the craft-i18n checkout
|
||||
`CRAFT_I18N_DIR` names (the one the build embeds; without it the report says it was skipped). Its
|
||||
English-key set is derived from UI `tl!` literals and `trn` forms, the menu catalog and UI command
|
||||
table, and menu command labels in the engine source; each key is looked up as the app does (the
|
||||
`craft-i18n` crate: PhotoCraft's rows over the shared ones). After the counts and the rows kept in
|
||||
English (a translation that is the English itself) it lists, per language, the source keys it lacks
|
||||
(one line for a language with none), then any catalog rows the crate skips. A missing translation
|
||||
shows in English and fails nothing: `cargo xtask ci` runs the report as its last step so the list
|
||||
appears in the log, and only prints a warning if the report itself can't run.
|
||||
|
||||
## Panel command routing
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# Localization parity
|
||||
|
||||
> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-11-06 · **Change:** minor (Georgian interface catalog; previously minor: Azerbaijani UI catalog merged with current languages; native review pending; Bosnian UI catalog; previously minor: Swedish, Finnish, Danish and Norwegian Bokmål UI catalogs; previously minor: Arabic UI catalog) · **Target:** Adobe Photoshop 2026
|
||||
> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-11-08 · **Change:** trivial (the catalogs moved to storytold/craft-i18n and are measured with `cargo xtask i18n-report`; Serbian is `sr-latn`; previously minor: Georgian interface catalog; previously minor: Azerbaijani UI catalog merged with current languages; native review pending; Bosnian UI catalog; previously minor: Swedish, Finnish, Danish and Norwegian Bokmål UI catalogs; previously minor: Arabic UI catalog) · **Target:** Adobe Photoshop 2026
|
||||
|
||||
Per-language status of PhotoCraft's UI. How catalogs work and how to add one:
|
||||
[`localization.md`](localization.md). Language notes: [Korean](localization-ko.md), [Spanish](localization-es.md),
|
||||
[Simplified Chinese](localization-zh-hans.md), [Italian](localization-it.md), [Russian](localization-ru.md), [Georgian](localization-ka.md).
|
||||
|
||||
**How measured.** `cargo xtask i18n-coverage` (`xtask/src/i18n_coverage.rs`) defines the key
|
||||
**How measured.** `cargo xtask i18n-coverage` (now `cargo xtask i18n-report`, `xtask/src/i18n_report.rs`, which reads the craft-i18n catalogs in `CRAFT_I18N_DIR`) defines the key
|
||||
universe: `tl!("…")` literals and `trn(` plurals in `ui-egui` (tests excluded), menu-catalog
|
||||
labels and path segments, `menus.rs` UI commands, and engine `CommandSpec` labels and menu paths:
|
||||
**1,608 English keys** on 2026-10-10. Each catalog (`crates/ui-egui/src/i18n/<code>.tsv`) was
|
||||
@@ -99,6 +99,7 @@ engine localization or native review is complete.
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-08 | trivial | Catalogs moved to storytold/craft-i18n (`locales/<code>/photocraft.tsv`), looked up through the `craft-i18n` crate; Serbian is `sr-latn`; `cargo xtask i18n-report` replaces `i18n-coverage`; coverage unchanged |
|
||||
| 2026-11-06 | minor | Azerbaijani/Turkish UI search, dropdown prefixes and access keys use locale-aware I casing; 4,606 Azerbaijani entries and current menu coverage; native review requested and pending |
|
||||
| 2026-11-05 | minor | Preserved Bosnian while merging current main; 29 registered languages, 17 outside the table; Azerbaijani has 4,606 entries, including 29 current OpenType menu keys and checks for all eight command-ID overrides; native review pending |
|
||||
| 2026-11-01 | minor | Azerbaijani UI catalog, 4,566 entries; regional tags and one/other plurals; PR narrowed to Azerbaijani, 28 registered languages and 16 outside the table; native review pending; validation limits in the language notes; readiness estimates unchanged |
|
||||
|
||||
+40
-28
@@ -1,12 +1,16 @@
|
||||
# UI localisation and live language switching
|
||||
|
||||
PhotoCraft uses the same Rust catalog implementation in the native egui shell and the
|
||||
WebAssembly build. English source strings are lookup keys. UTF-8 TSV catalogs supply plain,
|
||||
contextual, command-ID and plural translations; missing entries fall back to English.
|
||||
WebAssembly build: the `craft-i18n` crate (craft-libs) over the catalogs of
|
||||
[storytold/craft-i18n](https://github.com/storytold/craft-i18n), shared by the Crafting Apps.
|
||||
English source strings are lookup keys. UTF-8 TSV catalogs (`locales/<code>/photocraft.tsv`, over
|
||||
the shared `common.tsv`) supply plain, contextual, command-ID and plural translations; missing
|
||||
entries fall back to English. The build embeds them from the checkout `CRAFT_I18N_DIR` names, at
|
||||
the commit in `craft-i18n.rev`; without it PhotoCraft builds and runs in English only.
|
||||
|
||||
## Supported languages
|
||||
|
||||
| Language | Preference code | Integer plural forms |
|
||||
| Language | Preference code | Integer plural forms (CLDR) |
|
||||
|---|---|---|
|
||||
| English | `en` | one / other |
|
||||
| 简体中文 | `zh-hans` | one form |
|
||||
@@ -25,19 +29,19 @@ contextual, command-ID and plural translations; missing entries fall back to Eng
|
||||
| Polski | `pl` | one / few (2–4, not 12–14) / many |
|
||||
| Ελληνικά | `el` | one / other |
|
||||
| Nederlands | `nl` | one / other |
|
||||
| Magyar | `hu` | one form |
|
||||
| Magyar | `hu` | one / other (both read the same: "3 réteg") |
|
||||
| Tiếng Việt | `vi` | one form |
|
||||
| ไทย | `th` | one form |
|
||||
| தமிழ் | `ta` | one / other |
|
||||
| Srpski | `sr` | one / few / many (teens use many) |
|
||||
| Srpski (latinica) | `sr-latn` | one / few / other (teens use other) |
|
||||
| Bosanski | `bs` | one / few / other (teens use other) |
|
||||
| हिन्दी | `hi` | one / other |
|
||||
| हिन्दी | `hi` | one (0 and 1) / other |
|
||||
| Svenska | `sv` | one / other |
|
||||
| Suomi | `fi` | one / other (partitive after every count but 1) |
|
||||
| Dansk | `da` | one / other |
|
||||
| Norsk bokmål | `nb` | one / other |
|
||||
| ქართული | `ka` | one form (count-neutral: `შრე: {n}`) |
|
||||
| עברית | `he` | one / other |
|
||||
| ქართული | `ka` | one / other (both count-neutral: `შრე: {n}`) |
|
||||
| עברית | `he` | one / two / other (two repeats other) |
|
||||
| اردو | `ur` | one / other |
|
||||
| Română | `ro` | one / few (0, 2–19, 101–119 …) / other (20–100, 120 …) |
|
||||
| Azərbaycanca | `az` | one (1) / other (all other integer counts) |
|
||||
@@ -50,8 +54,8 @@ drafts have edited core terminology; native-speaker review is pending. See
|
||||
|
||||
Languages registered with `complete_menus` cover the current menu labels, `tl!` literals, blend
|
||||
mode names, and generated preference labels. A string a catalog lacks shows in English:
|
||||
`cargo xtask i18n-coverage` lists the missing strings per language, and `cargo xtask ci` prints
|
||||
that list as its last step without failing. Vietnamese (`vi`) is
|
||||
`cargo xtask i18n-report` lists the missing strings per language (with `CRAFT_I18N_DIR` set), and
|
||||
`cargo xtask ci` prints that list as its last step without failing. Vietnamese (`vi`) is
|
||||
selectable, resolves regional tags such as `vi-VN`, and covers all current stable localization
|
||||
keys. `complete_menus` remains false while generated/dynamic long-tail labels are still under
|
||||
review. This does not include every engine error or status message: those remain English, as do
|
||||
@@ -73,8 +77,10 @@ The existing preference store saves the selection for future launches. `auto` fo
|
||||
native system locale; an unsupported code follows the same fallback. Regional tags such as
|
||||
`fr-CA`, `ko-KR`, `vi-VN` and `zh-CN` resolve to the corresponding registered catalog. Traditional and
|
||||
Simplified Chinese remain distinct. Every Portuguese locale (`pt`, `pt-BR`, `pt-PT`) uses the
|
||||
Brazilian Portuguese catalog. The Serbian catalog is written in Latin script (Ekavian); every
|
||||
Serbian locale (`sr-RS`, `sr-Latn-RS`, `sr_RS@latin`, and Cyrillic `sr-Cyrl-RS`) resolves to it.
|
||||
Brazilian Portuguese catalog. The Serbian catalog (`sr-latn`) is written in Latin script
|
||||
(Ekavian); every Serbian locale (`sr`, `sr-RS`, `sr-ME`, `sr-Latn-RS`, `sr_RS@latin`, and Cyrillic
|
||||
`sr-Cyrl-RS`) resolves to it, and a preference saved as `sr` by an earlier version loads as
|
||||
`sr-latn`.
|
||||
The Bosnian catalog is written in Latin script (Ijekavian); every Bosnian locale (`bs-BA`,
|
||||
`bs-Latn-BA`, `bs_BA.UTF-8`, and Cyrillic `bs-Cyrl-BA`) resolves to it.
|
||||
Swedish locales from Sweden and Finland (`sv-SE`, `sv-FI`, `sv_FI.UTF-8`) use the Swedish catalog;
|
||||
@@ -117,9 +123,10 @@ updates the labels in the same rendered frame. Drawing language is local to the
|
||||
a scoped preview restores the previous language even if drawing unwinds. Menu and dialog
|
||||
identity continues to use command IDs, independent of translated labels.
|
||||
|
||||
This is hot switching among the bundled catalogs. Catalog files are embedded with
|
||||
`include_str!`; editing a TSV file requires a rebuild. External catalog watching and
|
||||
file-resource hot reload are not implemented.
|
||||
This is hot switching among the embedded catalogs. `build.rs` embeds the craft-i18n catalogs with
|
||||
`include_str!`; a catalog change reaches PhotoCraft when `craft-i18n.rev` moves to a commit that
|
||||
has it, and needs a rebuild. External catalog watching and file-resource hot reload are not
|
||||
implemented.
|
||||
|
||||
## Right-to-left languages
|
||||
|
||||
@@ -160,23 +167,28 @@ detection remain separate outstanding work. Switching catalogs does not supply m
|
||||
|
||||
## Add or maintain a catalog
|
||||
|
||||
1. Add `<code>.tsv` under `crates/ui-egui/src/i18n`, following the header in `ja.tsv`.
|
||||
2. Register its code, native name and plural rule in `i18n::LANGUAGES`.
|
||||
3. Translate the meaning of the English source keys. Preserve `{name}` placeholders, escaped
|
||||
characters and the trailing `…` on dialog commands. Use `@id` to disambiguate a command
|
||||
label and `@plural` for count-sensitive text. Keep product names such as PhotoCraft.
|
||||
4. Set `complete_menus` once `cargo xtask i18n-coverage` lists nothing missing for the language. Add source and license
|
||||
attribution for translation assets, then run the catalog and shell tests.
|
||||
Translations live in craft-i18n, not here (its `docs/integration.md`). A PhotoCraft PR that adds
|
||||
or changes interface text adds the English only; translators add the other languages to
|
||||
`locales/<code>/photocraft.tsv` in craft-i18n PRs, and they show here once `craft-i18n.rev` moves
|
||||
to a commit that has them. A missing translation never fails a build, a test or a release.
|
||||
|
||||
1. Translate the meaning of the English source keys. Preserve `{name}` placeholders, escaped
|
||||
characters and the trailing `…` on dialog commands (an `@id` row without them is skipped and
|
||||
the label's translation shows). Use `@id` to disambiguate a command label and `@plural` for
|
||||
count-sensitive text, one form per CLDR category. Keep product names such as PhotoCraft.
|
||||
2. A new language: craft-i18n gets `locales/<code>/photocraft.tsv` with its `@id language.name`
|
||||
row, then PhotoCraft registers its code in `i18n::LANGUAGES`.
|
||||
3. Set `complete_menus` once `cargo xtask i18n-report` lists nothing missing for the language.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/storytold/craft-i18n ../craft-i18n
|
||||
git -C ../craft-i18n checkout "$(tr -d '[:space:]' < craft-i18n.rev)"
|
||||
export CRAFT_I18N_DIR="$PWD/../craft-i18n"
|
||||
cargo test -p photocraft-ui-egui --locked
|
||||
cargo clippy -p photocraft-ui-egui --all-targets --locked -- -D warnings
|
||||
cargo xtask i18n-coverage
|
||||
cargo xtask layers
|
||||
cargo xtask wasm
|
||||
cargo xtask i18n-report
|
||||
```
|
||||
|
||||
Render representative dialogs with the offscreen `snapshot` example, including a sequence
|
||||
of language changes in one process. Inspect the PNGs for missing glyphs and truncated labels.
|
||||
Translations are original work or reuse the open PhotoCraft contributions credited in
|
||||
[ATTRIBUTION.md](../ATTRIBUTION.md); no proprietary localisation resources are used.
|
||||
Translators are credited in craft-i18n's `ATTRIBUTION.md`; no proprietary localisation resources
|
||||
are used.
|
||||
+1
-1
@@ -299,7 +299,7 @@ Never-crash attribute on 30 of 30 crate roots.
|
||||
| DIST-220-1 | Help > Check for Updates plus an opt-out periodic release-feed check on all desktops | partial | [#220](https://github.com/storytold/photocraft/issues/220) | 2026-10-22 (#5485): Help > Check for Updates and an opt-out check once per launch (updates_cmds + the desktop HTTPS transport; none inside Flatpak, where flatpak update owns updates). Missing: a periodic recheck while the app stays open |
|
||||
| DIST-220-2 | Windows ARM64 (aarch64-pc-windows-msvc) in the release matrix, signed like x64 | done | [#220](https://github.com/storytold/photocraft/issues/220) | release.yml has { arch: arm64, target: aarch64-pc-windows-msvc } in the Windows matrix, and .github/workflows/windows-arm64.yml packages that MSI, installs it on a Windows 11 ARM64 runner, checks the installed binaries are ARM64 and runs the CLI natively before uninstalling. Signing takes the same path as x64: the secrets are optional and a missing one produces an unsigned artifact and a warning (see DIST-2) |
|
||||
| DIST-220-3 | In-app bug report with reviewable diagnostics that opens a prefilled issue | missing | [#220](https://github.com/storytold/photocraft/issues/220) | No bug report dialog in crates |
|
||||
| DIST-220-4 | Translation coverage per language reported by xtask; RTL layout for Arabic and Hebrew | partial | [#220](https://github.com/storytold/photocraft/issues/220) | `cargo xtask i18n-coverage` reports per-language coverage (#427); RTL languages mirror the shell (`direction.rs`), not yet panel interiors or dialogs; Arabic (`ar`) is the first RTL catalog |
|
||||
| DIST-220-4 | Translation coverage per language reported by xtask; RTL layout for Arabic and Hebrew | partial | [#220](https://github.com/storytold/photocraft/issues/220) | `cargo xtask i18n-report` reports per-language coverage from the craft-i18n catalogs (#427); RTL languages mirror the shell (`direction.rs`), not yet panel interiors or dialogs; Arabic (`ar`) is the first RTL catalog |
|
||||
| DIST-220-5 | Linux AppImage x86_64 + aarch64 ship; Flatpak kept; Flathub later (#173) | partial | [#220](https://github.com/storytold/photocraft/issues/220) | AppImage and Flatpak ship (release.yml:162-216); Flathub not done |
|
||||
|
||||
## Open bugs
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# PhotoCraft vs Adobe Photoshop: target-app parity
|
||||
|
||||
> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-11-02 · **Change:** minor (RGB and CMYK documents preview their spot inks as an overprint, FILE-215-17 narrows to PDF Separation, #10249; tile-sparse Select and Mask outputs and preview coverage, #8822; classical Select › Sky can seed substantial high-confidence components beneath an obstructed top band; learned segmentation remains open; Art History Brush Opacity on the options bar, #10263; no estimate changed; Automation Batch Esc Continue/Stop and read-only input previews now follow the measured cancellation flow; full live tabs remain partial, AUTO-219-5, #4579; Automation recording folds Move-tool nudge runs, records keyboard document switches by opening-order offset and scales point text placement; paragraph boxes remain open, #4514; Automation Batch output naming and UTF-16 logs now follow measured Photoshop behavior; progress and cancel prompt remain partial, AUTO-219-5, #4579; 11 of 183 preferences do nothing: startup reads Graphics Adapter through the typed Performance section, so the scorecard audit sees it; selected colour sets edit drawing, tone and supported filters; geometry remains open; Smooth and Feather command masks cropped to selection bounds plus blur reach; Equalize with a selection asks Selected Area Only or Entire Image Based On Selected Area; cropped selection morphology and command mask conversion performance evidence added; the Camera Raw row names per-camera colour for non-DNG cameras as missing, not the Calibration panel, which landed 2026-10-13; Content-Aware Scale measurements added, #5236; Help › Check for Updates and an opt-out check once per launch, DIST-220-1 partial, #5485; area type, TYPE-218-10 partial, Type scorecard 5 / 5 / 0; compound layer properties export as separate Photoshop Set events, #8304; JPEG Options dialog landed, FILE-215-19 partial; Print › Functions › Bleed through `file.print`; Content-Aware Move live preview for every selection size, TOOL-213-4 done, #6680; retouching evidence: Pattern Stamp and Background Eraser draw live, only the Mixer Brush is left of TOOL-213-7; fill and adjustment layers copy and paste whole, UI-217-23 partial, #2344; shape layers take Density and Feather, TOOL-214-12 done, #5846; on-canvas corner radius widgets, TOOL-214-12; `.atn` import maps 112 events; Free Transform H/V skew fields; stale rows corrected against `main` and the scorecard, estimates unchanged; Photoshop Actions `.atn` load and save; 2026-10-10: Tilt-Shift measurements added; earlier the same day: major, full re-measure against Photoshop 2026 27.11.0; merged `parity-estimate.md` and the roadmap's honest assessment; stale missing-tool rows corrected: Color Replacement and Red Eye are live toolbar tools, Frame landed; percentages unchanged; PSD spot plates in Photoshop's polarity, #7415 split; TIFF spot plates, FILE-215-17's TIFF part, #7415) · **Target:** Adobe Photoshop 2026; Print: Japanese paper sizes — はがき, 往復はがき, JIS B5/B4, A6, L判, 2L判, KG判, 六切, 四切;
|
||||
> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-11-08 · **Change:** trivial (languages are measured with `cargo xtask i18n-report` over the craft-i18n catalogs; previously minor: RGB and CMYK documents preview their spot inks as an overprint, FILE-215-17 narrows to PDF Separation, #10249; tile-sparse Select and Mask outputs and preview coverage, #8822; classical Select › Sky can seed substantial high-confidence components beneath an obstructed top band; learned segmentation remains open; Art History Brush Opacity on the options bar, #10263; no estimate changed; Automation Batch Esc Continue/Stop and read-only input previews now follow the measured cancellation flow; full live tabs remain partial, AUTO-219-5, #4579; Automation recording folds Move-tool nudge runs, records keyboard document switches by opening-order offset and scales point text placement; paragraph boxes remain open, #4514; Automation Batch output naming and UTF-16 logs now follow measured Photoshop behavior; progress and cancel prompt remain partial, AUTO-219-5, #4579; 11 of 183 preferences do nothing: startup reads Graphics Adapter through the typed Performance section, so the scorecard audit sees it; selected colour sets edit drawing, tone and supported filters; geometry remains open; Smooth and Feather command masks cropped to selection bounds plus blur reach; Equalize with a selection asks Selected Area Only or Entire Image Based On Selected Area; cropped selection morphology and command mask conversion performance evidence added; the Camera Raw row names per-camera colour for non-DNG cameras as missing, not the Calibration panel, which landed 2026-10-13; Content-Aware Scale measurements added, #5236; Help › Check for Updates and an opt-out check once per launch, DIST-220-1 partial, #5485; area type, TYPE-218-10 partial, Type scorecard 5 / 5 / 0; compound layer properties export as separate Photoshop Set events, #8304; JPEG Options dialog landed, FILE-215-19 partial; Print › Functions › Bleed through `file.print`; Content-Aware Move live preview for every selection size, TOOL-213-4 done, #6680; retouching evidence: Pattern Stamp and Background Eraser draw live, only the Mixer Brush is left of TOOL-213-7; fill and adjustment layers copy and paste whole, UI-217-23 partial, #2344; shape layers take Density and Feather, TOOL-214-12 done, #5846; on-canvas corner radius widgets, TOOL-214-12; `.atn` import maps 112 events; Free Transform H/V skew fields; stale rows corrected against `main` and the scorecard, estimates unchanged; Photoshop Actions `.atn` load and save; 2026-10-10: Tilt-Shift measurements added; earlier the same day: major, full re-measure against Photoshop 2026 27.11.0; merged `parity-estimate.md` and the roadmap's honest assessment; stale missing-tool rows corrected: Color Replacement and Red Eye are live toolbar tools, Frame landed; percentages unchanged; PSD spot plates in Photoshop's polarity, #7415 split; TIFF spot plates, FILE-215-17's TIFF part, #7415) · **Target:** Adobe Photoshop 2026; Print: Japanese paper sizes — はがき, 往復はがき, JIS B5/B4, A6, L判, 2L判, KG判, 六切, 四切;
|
||||
|
||||
The authoritative answer to "how close is PhotoCraft to Photoshop, and how much work is left". The
|
||||
one-page summary is [`ROADMAP.md`](../ROADMAP.md); the ranked work list is [`gaps.md`](gaps.md);
|
||||
@@ -239,7 +239,7 @@ catalog; checking exports by opening them in Photoshop (the owner's machine has
|
||||
3. Formats: Photoshop's `Info.plist` `CFBundleDocumentTypes` and the PiPL flags of
|
||||
`Contents/PlugIns/Required/File Formats`, against `crates/codecs/src/format.rs` and
|
||||
`crates/io/src/lib.rs`.
|
||||
4. Languages: `cargo xtask i18n-coverage`.
|
||||
4. Languages: `cargo xtask i18n-report` (with `CRAFT_I18N_DIR` set to the pinned craft-i18n checkout).
|
||||
5. Re-grade the estimated rows from the open issues by area and the corpus floors. Move a number
|
||||
only with new evidence, and add a revision-history row.
|
||||
|
||||
|
||||
+13
-11
@@ -198,13 +198,14 @@ fonts use the same size, including fonts loaded after the preference changes.
|
||||
|
||||
## Localisation
|
||||
|
||||
Strings in code stay English and are the default lookup keys. `crates/ui-egui/src/i18n` maps them
|
||||
to display text at render time from one catalog per language (`i18n/<code>.tsv`; the format is
|
||||
documented in the header of `ja.tsv`). Command ids, menu paths used for logic, the control channel,
|
||||
Strings in code stay English and are the default lookup keys. `crates/ui-egui/src/i18n.rs` maps
|
||||
them to display text at render time through the `craft-i18n` crate, from the catalogs of
|
||||
storytold/craft-i18n (`locales/<code>/photocraft.tsv` over the shared `common.tsv`), embedded at
|
||||
build time from the commit in `craft-i18n.rev`. Command ids, menu paths used for logic, the control channel,
|
||||
the CLI and MCP always use the English ids and labels.
|
||||
|
||||
Languages shipped (`complete_menus` marks a catalog that covers every menu string and `tl!` literal;
|
||||
`cargo xtask i18n-coverage` lists what each catalog lacks):
|
||||
`cargo xtask i18n-report` lists what each catalog lacks):
|
||||
|
||||
- English (`en`), the source language.
|
||||
- Japanese (`ja`), complete.
|
||||
@@ -213,7 +214,7 @@ Languages shipped (`complete_menus` marks a catalog that covers every menu strin
|
||||
`zh-MO` and `zh-Hant-*` locales all resolve to it. The resolver distinguishes the two Chinese
|
||||
scripts, so neither catalog is shown to the other script's locales.
|
||||
- Spanish (`es`), complete.
|
||||
- Russian (`ru`), complete, with three plural forms (`one|few|many`, see `plural_russian`).
|
||||
- Russian (`ru`), complete, with three plural forms (`one|few|many`, CLDR).
|
||||
- Korean (`ko`), complete, with one plural form.
|
||||
- French (`fr`), complete, with two plural forms (0 and 1 use the singular).
|
||||
- Czech (`cs`), complete, with three plural forms.
|
||||
@@ -229,17 +230,18 @@ Languages shipped (`complete_menus` marks a catalog that covers every menu strin
|
||||
- Language changes apply without a restart; Preferences previews the chosen language until
|
||||
Apply or OK commits it. Cancel restores the committed language. Regional preference tags
|
||||
resolve through the same locale matcher. See [`localization.md`](localization.md).
|
||||
- To add a language: add `<code>.tsv` and one row in `i18n::LANGUAGES` (code, native name, catalog,
|
||||
plural rule). The dropdown, locale matching and the catalog tests (well-formed, no duplicates,
|
||||
placeholders and ellipses agree, command ids exist) pick it up. Set `complete_menus` once every
|
||||
menu string is translated. A language with more plural forms lists them
|
||||
all in `@plural` entries (Russian: `one|few|many`); the row's plural rule picks the form.
|
||||
- To add a language: craft-i18n gets `locales/<code>/photocraft.tsv` (with its `@id
|
||||
language.name` row), and PhotoCraft one row in `i18n::LANGUAGES`. The dropdown and locale
|
||||
matching pick it up; craft-i18n's checker keeps the rows well-formed (no duplicates, placeholders
|
||||
and ellipses agree, plural form counts). Set `complete_menus` once every menu string is
|
||||
translated. A language with more plural forms lists them all in `@plural` entries, one per CLDR
|
||||
category (Russian: `one|few|many`).
|
||||
- Translations are clean-room: written from the meaning of the English text in ordinary vocabulary,
|
||||
never from another product's localisation resources.
|
||||
|
||||
Localised so far: menus, the command palette, dialogs and panels (literals wrapped in `tl!("…")`;
|
||||
widgets such as `checkbox`, `slider_row`, `dropdown` and the buttons translate their labels
|
||||
themselves). A string with no entry in a catalog shows in English; `cargo xtask i18n-coverage`
|
||||
themselves). A string with no entry in a catalog shows in English; `cargo xtask i18n-report`
|
||||
lists the missing strings per language, and `cargo xtask ci` prints that list without failing.
|
||||
Not translated: status-bar
|
||||
messages and errors (they stay English, also for agents), names that are user data (layers, styles,
|
||||
|
||||
@@ -66,7 +66,7 @@ id = "DIST-220-4"
|
||||
target = "Translation coverage per language reported by xtask; RTL layout for Arabic and Hebrew"
|
||||
status = "partial"
|
||||
issue = 220
|
||||
note = "`cargo xtask i18n-coverage` reports per-language coverage (#427); RTL languages mirror the shell (`direction.rs`), not yet panel interiors or dialogs; Arabic (`ar`) is the first RTL catalog"
|
||||
note = "`cargo xtask i18n-report` reports per-language coverage from the craft-i18n catalogs (#427); RTL languages mirror the shell (`direction.rs`), not yet panel interiors or dialogs; Arabic (`ar`) is the first RTL catalog"
|
||||
|
||||
[[item]]
|
||||
id = "DIST-220-5"
|
||||
|
||||
@@ -14,6 +14,8 @@ serde = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
# perf/budgets.toml and scorecard/*.toml (MIT OR Apache-2.0).
|
||||
toml = "1"
|
||||
# `i18n-report` looks the UI strings up in the craft-i18n catalogs as the app does.
|
||||
craft-i18n = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3"
|
||||
|
||||
@@ -11,42 +11,78 @@ struct Key {
|
||||
#[derive(Debug)]
|
||||
struct Language {
|
||||
code: String,
|
||||
catalog: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// `cargo xtask i18n-report` (the last `cargo xtask ci` step): per registered language, how many
|
||||
/// of PhotoCraft's English UI strings have a translation in the craft-i18n checkout
|
||||
/// `CRAFT_I18N_DIR` names, looked up as the app does (the `craft-i18n` crate: PhotoCraft's rows
|
||||
/// over the shared ones, a region falling back to its language), the strings it lacks, and how
|
||||
/// many rows are kept in English (a translation that is the English text itself). It never fails
|
||||
/// on a missing translation: that string shows in English, and translators fill it in craft-i18n.
|
||||
/// Without `CRAFT_I18N_DIR` it says so and passes.
|
||||
pub fn run(root: &Path) -> Result<(), String> {
|
||||
let i18n_dir = root.join("crates/ui-egui/src/i18n");
|
||||
let registry_path = root.join("crates/ui-egui/src/i18n.rs");
|
||||
let registry = fs::read_to_string(®istry_path).map_err(|e| format!("{}: {e}", registry_path.display()))?;
|
||||
let languages = registered_languages(®istry)?;
|
||||
|
||||
let Some(dir) = std::env::var_os("CRAFT_I18N_DIR").filter(|d| !d.is_empty()) else {
|
||||
println!("UI translation report: skipped, built without craft-i18n (set CRAFT_I18N_DIR to a craft-i18n checkout)");
|
||||
return Ok(());
|
||||
};
|
||||
let english_keys = source_keys(root)?;
|
||||
let mut catalog_texts = BTreeMap::new();
|
||||
for language in &languages {
|
||||
if let Some(path) = &language.catalog {
|
||||
let full_path = i18n_dir.join(path);
|
||||
let text = fs::read_to_string(&full_path).map_err(|e| format!("{}: {e}", full_path.display()))?;
|
||||
catalog_texts.insert(language.code.clone(), (full_path, text));
|
||||
}
|
||||
}
|
||||
let mut translations = BTreeMap::new();
|
||||
for language in &languages {
|
||||
let entries = if language.catalog.is_some() {
|
||||
let (full_path, text) = catalog_texts.get(&language.code).ok_or_else(|| format!("missing source for registered language `{}`", language.code))?;
|
||||
parse_catalog(full_path, text)?
|
||||
} else {
|
||||
BTreeSet::new()
|
||||
};
|
||||
translations.insert(language.code.clone(), entries);
|
||||
}
|
||||
|
||||
if english_keys.is_empty() {
|
||||
return Err("no source-derived English UI translation keys were found".into());
|
||||
}
|
||||
print!("{}", format_report(&languages, &english_keys, &translations));
|
||||
let embedded = embedded(&PathBuf::from(dir).join("locales"))?;
|
||||
let codes: Vec<&str> = languages.iter().map(|l| l.code.as_str()).collect();
|
||||
let (i18n, mut problems) = craft_i18n::I18n::new(embedded, &codes);
|
||||
problems.extend(i18n.check_all());
|
||||
let mut translations = BTreeMap::new();
|
||||
let mut kept = BTreeMap::new();
|
||||
for language in &languages {
|
||||
let Some(lang) = i18n.from_code(&language.code).filter(|_| language.code != "en") else { continue };
|
||||
let found: BTreeSet<Key> = english_keys.iter().filter(|key| translation(&i18n, lang, key).is_some()).cloned().collect();
|
||||
let same = english_keys.iter().filter(|key| key.context.is_empty() && translation(&i18n, lang, key) == Some(key.source.as_str())).count();
|
||||
translations.insert(language.code.clone(), found);
|
||||
kept.insert(language.code.clone(), same);
|
||||
}
|
||||
print!("{}", format_report(&languages, &english_keys, &translations, &kept));
|
||||
if !problems.is_empty() {
|
||||
println!("\n{} catalog rows are skipped (they show in English):", problems.len());
|
||||
for problem in &problems {
|
||||
println!(" {problem}");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The translation of `key` in `lang`, as the app looks it up: a contextual string falls back to
|
||||
/// the plain one, a plural to nothing (its English forms show).
|
||||
fn translation<'a>(i18n: &'a craft_i18n::I18n, lang: craft_i18n::Lang, key: &'a Key) -> Option<&'a str> {
|
||||
match key.context.as_str() {
|
||||
"" | "@plural" => i18n.get(lang, &key.context, &key.source),
|
||||
context => i18n.get(lang, context, &key.source).or_else(|| i18n.get(lang, "", &key.source)),
|
||||
}
|
||||
}
|
||||
|
||||
/// The catalogs of every locale under `dir` with a `photocraft.tsv`, as the app's build.rs embeds
|
||||
/// them: (locale, shared `common.tsv` or "", `photocraft.tsv`). Read once per run, so leaked.
|
||||
fn embedded(dir: &Path) -> Result<&'static craft_i18n::Embedded, String> {
|
||||
let list = fs::read_dir(dir).map_err(|e| format!("{} is not a craft-i18n checkout ({e})", dir.display()))?;
|
||||
let mut out: Vec<(&'static str, &'static str, &'static str)> = Vec::new();
|
||||
for entry in list.flatten() {
|
||||
let path = entry.path();
|
||||
let Some(code) = path.file_name().and_then(|n| n.to_str()).map(str::to_string) else { continue };
|
||||
let Ok(app) = fs::read_to_string(path.join("photocraft.tsv")) else { continue };
|
||||
let shared = fs::read_to_string(path.join("common.tsv")).unwrap_or_default();
|
||||
out.push((Box::leak(code.into_boxed_str()), Box::leak(shared.into_boxed_str()), Box::leak(app.into_boxed_str())));
|
||||
}
|
||||
if out.is_empty() {
|
||||
return Err(format!("{} has no locale with a photocraft.tsv", dir.display()));
|
||||
}
|
||||
out.sort();
|
||||
Ok(Box::leak(out.into_boxed_slice()))
|
||||
}
|
||||
|
||||
fn source_keys(root: &Path) -> Result<BTreeSet<Key>, String> {
|
||||
let ui_sources = source_files(&root.join("crates/ui-egui/src"))?;
|
||||
let engine_sources = source_files(&root.join("crates/engine/src"))?;
|
||||
@@ -63,14 +99,20 @@ fn source_keys(root: &Path) -> Result<BTreeSet<Key>, String> {
|
||||
Ok(keys)
|
||||
}
|
||||
|
||||
fn format_report(languages: &[Language], english_keys: &BTreeSet<Key>, translations: &BTreeMap<String, BTreeSet<Key>>) -> String {
|
||||
let mut report = String::from("UI translation coverage (translated source keys / source keys)\n");
|
||||
report.push_str(&format!("{:<12} {:>12} {:>9}\n", "language", "translated", "coverage"));
|
||||
fn format_report(
|
||||
languages: &[Language],
|
||||
english_keys: &BTreeSet<Key>,
|
||||
translations: &BTreeMap<String, BTreeSet<Key>>,
|
||||
kept: &BTreeMap<String, usize>,
|
||||
) -> String {
|
||||
let mut report = String::from("UI translation coverage (translated source keys / source keys; kept: translated as the English itself)\n");
|
||||
report.push_str(&format!("{:<12} {:>12} {:>9} {:>6}\n", "language", "translated", "coverage", "kept"));
|
||||
for language in languages {
|
||||
let translated =
|
||||
if language.code == "en" { english_keys.len() } else { translations.get(&language.code).map_or(0, |keys| keys.intersection(english_keys).count()) };
|
||||
let coverage = 100.0 * translated as f64 / english_keys.len() as f64;
|
||||
report.push_str(&format!("{:<12} {:>5}/{:<6} {:>8.2}%\n", language.code, translated, english_keys.len(), coverage));
|
||||
let kept = kept.get(&language.code).copied().unwrap_or(0);
|
||||
report.push_str(&format!("{:<12} {:>5}/{:<6} {:>8.2}% {:>6}\n", language.code, translated, english_keys.len(), coverage, kept));
|
||||
}
|
||||
report.push_str("\nMissing translations (shown in English until translated)\n");
|
||||
for language in languages.iter().filter(|language| language.code != "en") {
|
||||
@@ -104,33 +146,18 @@ fn registered_languages(source: &str) -> Result<Vec<Language>, String> {
|
||||
.split("pub static LANGUAGES")
|
||||
.nth(1)
|
||||
.ok_or_else(|| "could not find the LANGUAGES registry".to_string())?
|
||||
.split("impl LangInfo")
|
||||
.split("];")
|
||||
.next()
|
||||
.ok_or_else(|| "could not find the end of the LANGUAGES registry".to_string())?;
|
||||
let mut languages = Vec::new();
|
||||
let mut codes = HashSet::new();
|
||||
for (index, section) in registry.split("LangInfo {").skip(1).enumerate() {
|
||||
let block = section.split("},").next().unwrap_or(section);
|
||||
let block = section.split('}').next().unwrap_or(section);
|
||||
let code = quoted_field(block, "code:").ok_or_else(|| format!("LANGUAGES entry {} has no code", index + 1))?;
|
||||
if !codes.insert(code.clone()) {
|
||||
return Err(format!("duplicate registered language code `{code}`"));
|
||||
}
|
||||
let catalog = if code == "en" {
|
||||
None
|
||||
} else {
|
||||
// `catalog!("xx")` embeds `xx.tsv` (packed by ui-egui's build.rs).
|
||||
let marker = "catalog!(\"";
|
||||
let start = block.find(marker).ok_or_else(|| format!("language `{code}` has no catalog! entry"))? + marker.len();
|
||||
let rest = block.get(start..).ok_or_else(|| format!("language `{code}` has a malformed catalog path"))?;
|
||||
let end = rest.find("\")").ok_or_else(|| format!("language `{code}` has a malformed catalog path"))?;
|
||||
let file = format!("{}.tsv", rest.get(..end).ok_or_else(|| format!("language `{code}` has an invalid catalog path"))?);
|
||||
let path = Path::new(&file);
|
||||
if path.components().count() != 1 || path.extension().and_then(|ext| ext.to_str()) != Some("tsv") {
|
||||
return Err(format!("language `{code}` has unsafe catalog path `{file}`"));
|
||||
}
|
||||
Some(path.to_path_buf())
|
||||
};
|
||||
languages.push(Language { code, catalog });
|
||||
languages.push(Language { code });
|
||||
}
|
||||
if !languages.iter().any(|language| language.code == "en") {
|
||||
return Err("LANGUAGES registry does not contain English (`en`)".into());
|
||||
@@ -477,77 +504,20 @@ fn unescape_rust_string(raw: &str) -> String {
|
||||
out
|
||||
}
|
||||
|
||||
fn parse_catalog(path: &Path, text: &str) -> Result<BTreeSet<Key>, String> {
|
||||
let mut keys = BTreeSet::new();
|
||||
for (index, line) in text.lines().enumerate() {
|
||||
if line.trim().is_empty() || line.starts_with('#') {
|
||||
continue;
|
||||
}
|
||||
let mut columns = line.split('\t');
|
||||
let parsed = match (columns.next(), columns.next(), columns.next(), columns.next()) {
|
||||
(Some(context), Some(source), Some(translation), None) if !source.is_empty() && !translation.is_empty() => {
|
||||
Key { context: unescape_tsv(context), source: unescape_tsv(source) }
|
||||
}
|
||||
_ => return Err(format!("{}:{line_no}: expected `context<TAB>source<TAB>translation`", path.display(), line_no = index + 1)),
|
||||
};
|
||||
if !keys.insert(Key { context: parsed.context.clone(), source: parsed.source.clone() }) {
|
||||
return Err(format!("{}:{line_no}: duplicate key {:?} {:?}", path.display(), parsed.context, parsed.source, line_no = index + 1));
|
||||
}
|
||||
}
|
||||
Ok(keys)
|
||||
}
|
||||
|
||||
fn unescape_tsv(source: &str) -> String {
|
||||
let mut out = String::with_capacity(source.len());
|
||||
let mut chars = source.chars();
|
||||
while let Some(ch) = chars.next() {
|
||||
if ch != '\\' {
|
||||
out.push(ch);
|
||||
continue;
|
||||
}
|
||||
match chars.next() {
|
||||
Some('n') => out.push('\n'),
|
||||
Some('t') => out.push('\t'),
|
||||
Some('\\') => out.push('\\'),
|
||||
Some(other) => {
|
||||
out.push('\\');
|
||||
out.push(other);
|
||||
}
|
||||
None => out.push('\\'),
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn known_keys(values: &[&str]) -> BTreeSet<Key> {
|
||||
values.iter().map(|value| Key { context: String::new(), source: (*value).to_string() }).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unused_legacy_catalog_keys_do_not_affect_coverage() {
|
||||
let catalog = parse_catalog(Path::new("xx.tsv"), "\tOld key\tÜbersetzung\n");
|
||||
assert_eq!(catalog, Ok(known_keys(&["Old key"])));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_duplicate_keys() {
|
||||
let error = parse_catalog(Path::new("xx.tsv"), "\tOpen\tOuvrir\n\tOpen\tOuvert\n").err();
|
||||
assert!(error.is_some_and(|message| message.contains("duplicate key")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn registered_languages_and_report_are_stable() {
|
||||
let registry = r#"
|
||||
pub static LANGUAGES: [LangInfo; 3] = [
|
||||
LangInfo { code: "zh", source: catalog!("zh") },
|
||||
LangInfo { code: "en", source: b"" },
|
||||
LangInfo { code: "fr", source: catalog!("fr") },
|
||||
LangInfo { code: "zh", complete_menus: true },
|
||||
LangInfo { code: "en", complete_menus: false },
|
||||
// A comment with a } brace.
|
||||
LangInfo { code: "fr", complete_menus: true },
|
||||
];
|
||||
impl LangInfo {}
|
||||
impl Lang {}
|
||||
"#;
|
||||
let languages = registered_languages(registry);
|
||||
assert!(languages.is_ok());
|
||||
@@ -561,13 +531,14 @@ mod tests {
|
||||
("fr".to_string(), BTreeSet::from([Key { context: String::new(), source: "Open".into() }])),
|
||||
("zh".to_string(), english_keys.clone()),
|
||||
]);
|
||||
let kept = BTreeMap::from([("fr".to_string(), 0), ("zh".to_string(), 1)]);
|
||||
assert_eq!(
|
||||
format_report(&languages, &english_keys, &translations),
|
||||
"UI translation coverage (translated source keys / source keys)\n\
|
||||
language translated coverage\n\
|
||||
en 3/3 100.00%\n\
|
||||
fr 1/3 33.33%\n\
|
||||
zh 3/3 100.00%\n\
|
||||
format_report(&languages, &english_keys, &translations, &kept),
|
||||
"UI translation coverage (translated source keys / source keys; kept: translated as the English itself)\n\
|
||||
language translated coverage kept\n\
|
||||
en 3/3 100.00% 0\n\
|
||||
fr 1/3 33.33% 0\n\
|
||||
zh 3/3 100.00% 1\n\
|
||||
\n\
|
||||
Missing translations (shown in English until translated)\n\
|
||||
fr: 2 missing\n\
|
||||
+8
-7
@@ -5,7 +5,7 @@
|
||||
|
||||
mod corpus;
|
||||
mod corpus_pins;
|
||||
mod i18n_coverage;
|
||||
mod i18n_report;
|
||||
mod ico;
|
||||
mod layers;
|
||||
mod panel_commands;
|
||||
@@ -32,7 +32,7 @@ commands:
|
||||
test workspace tests (cargo nextest when installed, else cargo test), then doctests
|
||||
ci the CI gate: fmt --check, clippy -D warnings, layers, panel-commands, scorecard --check, tests
|
||||
(nextest --profile ci), panic_hunt, doctests and wasm, with --locked --features heif
|
||||
(stops at first failure), then the i18n-coverage report
|
||||
(stops at first failure), then the i18n-report
|
||||
corpus [--all | --pngsuite | --psd | --psd-tools | --pixls | --atn | --photoshop | --gimp] [--local] [--update-manifest]
|
||||
show where test corpora live and their pins (xtask/src/corpus_pins.rs), or fetch
|
||||
them into corpus/ (pinned commits, sha256-verified; --all = every corpus but pixls,
|
||||
@@ -44,8 +44,9 @@ commands:
|
||||
--local takes corpus/photoshop and corpus/gimp from the photocraft-corpus authoring clone
|
||||
stats [--exact] count tests and lines per crate (--exact: ask the test harness via `-- --list`)
|
||||
parity Photoshop menu parity; rewrites docs/parity-checklist.md
|
||||
i18n-coverage report UI translation coverage and the missing strings per registered language
|
||||
(the last `ci` step; it never fails)
|
||||
i18n-report report UI translation coverage, the missing strings and the rows kept in English per
|
||||
registered language, from the craft-i18n checkout in CRAFT_I18N_DIR (the last `ci`
|
||||
step; it never fails, and says so when CRAFT_I18N_DIR is unset)
|
||||
perf [--quick] [--update-baseline] [--threshold PCT] [--bench NAME]... [--skip-build] [--reuse]
|
||||
run the release benches, merge them by scenario id into target/perf/results.json,
|
||||
check perf/budgets.toml and perf/baseline.json (non-zero on a broken budget or regression)
|
||||
@@ -72,7 +73,7 @@ fn main() -> ExitCode {
|
||||
Some("test-corpus") => corpus::test_cmd(&rest),
|
||||
Some("stats") => stats::run(&root(), rest.contains(&"--exact")),
|
||||
Some("parity") => cmd_parity(),
|
||||
Some("i18n-coverage") => i18n_coverage::run(&root()),
|
||||
Some("i18n-report") => i18n_report::run(&root()),
|
||||
Some("perf") => perf::run(&root(), &rest),
|
||||
Some("scorecard") => scorecard::run(&root(), &rest),
|
||||
Some("version") => version::run(&root(), &rest),
|
||||
@@ -300,8 +301,8 @@ fn cmd_ci() -> Result<(), String> {
|
||||
"i18n",
|
||||
Box::new(|| {
|
||||
// Lists missing translations for the log; a missing string shows in English, so it never fails CI.
|
||||
if let Err(e) = i18n_coverage::run(&root()) {
|
||||
eprintln!("warning: i18n coverage report failed: {e}");
|
||||
if let Err(e) = i18n_report::run(&root()) {
|
||||
eprintln!("warning: i18n report failed: {e}");
|
||||
}
|
||||
Ok(())
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user