From 7a334e5306d64b65f70a00f44129b42d485f81ba Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Tue, 3 Nov 2026 21:46:07 +0000 Subject: [PATCH] =?UTF-8?q?proof:=20a=20variant=20after=20the=20default=20?= =?UTF-8?q?script=20and=20a=20region=20is=20looked=20up=20without=20the=20?= =?UTF-8?q?region=20too=20(sr-Cyrl-RS-1994=20=E2=86=92=20sr-1994)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FypgCYmv6UJmY2QcuhfXco --- crates/proof/src/pack_lang.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/proof/src/pack_lang.rs b/crates/proof/src/pack_lang.rs index 93ec1eb4..30206661 100644 --- a/crates/proof/src/pack_lang.rs +++ b/crates/proof/src/pack_lang.rs @@ -219,8 +219,15 @@ pub(crate) fn names(locale: PackLocale) -> Vec { // The language's default script: its script-less names are in that script too. Some(s) if parts.get(s).is_some_and(|p| Some(*p) == default) => { let without = crate::lang::without_index(&cased, s); + let region = crate::lang::region_index(&without); for n in (1..=without.len()).rev() { - push(without.get(..n).unwrap_or_default()); + let prefix = without.get(..n).unwrap_or_default(); + push(prefix); + if let Some(r) = region + && r + 1 < n + { + push(&crate::lang::without_index(prefix, r)); + } } } Some(_) => {} @@ -443,6 +450,11 @@ mod tests { ); // With a script the same variant passes the length limit (15 bytes), and is cut by it. assert_eq!(l("sr-Cyrl-RS-ijekavsk").as_str(), "sr-cyrl-rs"); + // A variant that fits with the default script is looked up without the region too, script-less as well. + let n = names(l("sr-Cyrl-RS-1994")); + assert!(n.contains(&"sr_Cyrl_1994".to_string()), "{n:?}"); + assert!(n.contains(&"sr_1994".to_string()), "{n:?}"); + assert!(n.iter().position(|x| x == "sr_1994") < n.iter().position(|x| x == "sr_RS"), "{n:?}"); assert_eq!(hyphenation_locales(l("ca-ES-valencia")), ["ca-es-valencia", "ca-valencia", "ca-es", "ca"]); assert_eq!(hyphenation_locales(l("fr-CA")), ["fr-ca", "fr"]); assert_eq!(hyphenation_locales(l("sr-Latn")), ["sr-latn"]);