diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs index 1c5b0e3e1b..8099711ff5 100644 --- a/crates/ui-egui/src/i18n.rs +++ b/crates/ui-egui/src/i18n.rs @@ -694,9 +694,15 @@ fn message_at(lang: Lang, s: &str, depth: usize) -> String { let count = caps.iter().find(|(k, _)| *k == "n").and_then(|(_, v)| v.parse::().ok()); let form = count.map_or(forms.len().saturating_sub(1), |n| (lang.0.plural)(n).min(forms.len().saturating_sub(1))); let Some(template) = forms.get(form) else { return s.to_string() }; - let quoted = |v: &str| [('"', '"'), ('“', '”'), ('\'', '\''), ('`', '`')].iter().any(|(a, b)| s.contains(&format!("{a}{v}{b}"))); + // A value is quoted when quotes surround it at its own place in `s`. The same text quoted at + // another place in `s` (a property named like the reason given for it) does not count. + let quoted = |v: &str| { + let at = (v.as_ptr() as usize).checked_sub(s.as_ptr() as usize); + let Some((before, after)) = at.and_then(|at| Some((s.get(..at)?, s.get(at + v.len()..)?))) else { return false }; + [('"', '"'), ('“', '”'), ('\'', '\''), ('`', '`')].iter().any(|(a, b)| before.ends_with(*a) && after.starts_with(*b)) + }; let nested = |v: &str| { - if depth <= 1 || quoted(v) { + if depth <= 1 || v.is_empty() || quoted(v) { v.to_string() } else if v.starts_with(['{', '[']) { exact_translation(lang.catalog(), v).unwrap_or_else(|| v.to_string()) diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index cfa07747f1..812333143e 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -5130,19 +5130,6 @@ imageTrace Outline Körvonal @msg $.evalFile requires a file path A $.evalFile fájlútvonalat igényel @msg $.evalFile: the timeout must be a finite number of milliseconds, 0 or more $.evalFile: az időkorlátnak véges számú ezredmásodpercnek kell lennie, 0 vagy több @msg $.evalFile: takes a file path and a timeout $.evalFile: egy fájlútvonalat és egy időkorlátot vár -@msg assignment to a constant binding értékadás konstans kötésnek -@msg invalid array length érvénytelen tömbhossz -@msg array literal too long a tömbliterál túl hosszú -@msg the value is not a function az érték nem függvény -@msg apply was called on a value that is not a function az apply olyan értéken lett meghívva, amely nem függvény -@msg the argument list is not an object az argumentumlista nem objektum -@msg too many arguments túl sok argumentum -@msg the value is not a constructor az érték nem konstruktor -@msg cannot convert the object to a primitive value az objektum nem alakítható primitív értékké -@msg cannot convert undefined or null to an object az undefined és a null nem alakítható objektummá -@msg the right side of 'in' is not an object az 'in' jobb oldala nem objektum -@msg the right side of 'instanceof' is not a function az 'instanceof' jobb oldala nem függvény -@msg the function's prototype is not an object a függvény prototípusa nem objektum @msg Error: {e} Error: {e} @msg TypeError: {e} TypeError: {e} @msg ReferenceError: {e} ReferenceError: {e} diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 38281b99e4..5426b39315 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -5135,19 +5135,6 @@ swatch Bright Violet ビビッドバイオレット @msg $.evalFile requires a file path $.evalFile にはファイルパスが必要です @msg $.evalFile: the timeout must be a finite number of milliseconds, 0 or more $.evalFile: タイムアウトは 0 以上の有限のミリ秒数にしてください @msg $.evalFile: takes a file path and a timeout $.evalFile: ファイルパスとタイムアウトを指定します -@msg assignment to a constant binding 定数バインディングへの代入です -@msg invalid array length 配列の長さが無効です -@msg array literal too long 配列リテラルが長すぎます -@msg the value is not a function 値は関数ではありません -@msg apply was called on a value that is not a function 関数ではない値に対して apply が呼び出されました -@msg the argument list is not an object 引数リストはオブジェクトではありません -@msg too many arguments 引数が多すぎます -@msg the value is not a constructor 値はコンストラクターではありません -@msg cannot convert the object to a primitive value オブジェクトをプリミティブ値に変換できません -@msg cannot convert undefined or null to an object undefined または null をオブジェクトに変換できません -@msg the right side of 'in' is not an object 'in' の右辺がオブジェクトではありません -@msg the right side of 'instanceof' is not a function 'instanceof' の右辺が関数ではありません -@msg the function's prototype is not an object 関数のプロトタイプがオブジェクトではありません @msg Error: {e} Error: {e} @msg TypeError: {e} TypeError: {e} @msg ReferenceError: {e} ReferenceError: {e} diff --git a/crates/ui-egui/src/i18n/tests.rs b/crates/ui-egui/src/i18n/tests.rs index 228ebece6e..c86626e998 100644 --- a/crates/ui-egui/src/i18n/tests.rs +++ b/crates/ui-egui/src/i18n/tests.rs @@ -3368,6 +3368,12 @@ fn script_interpreter_core_errors_are_translated() { "cannot assign to property 'a': it is read-only", vec!["'a'"], ), + // A property named like the reason: the name stays as written, and the reason is translated. + ( + "'use strict'; var o = {}; Object.defineProperty(o, 'it is read-only', {value: 1}); o['it is read-only'] = 2", + "cannot assign to property 'it is read-only': it is read-only", + vec!["'it is read-only'"], + ), ( "'use strict'; var o = {}; Object.defineProperty(o, 'g', {get: function () { return 1; }}); o.g = 2", "cannot assign to property 'g': it has only a getter",