diff --git a/crates/proof/README.md b/crates/proof/README.md index b4b4b5ba8..4cc4b2ca4 100644 --- a/crates/proof/README.md +++ b/crates/proof/README.md @@ -89,19 +89,22 @@ pub fn load_errors() -> Vec<(String, String)>; // + (locale or folder, pub fn embedded_locales() -> &'static [&'static str]; // + locales with embedded upstream data, not our supplements ("en-us", "en-gb", "en-ca", "en-au", "pl", "pt", "it", "de" by default; the four English ones with CRAFT_PROOF_EMBED=en) // craft_proof (crate root) -pub enum ProofLang { …, Pack(PackLocale), Other } // + Pack: any language without tools of its own (nl, fr, sr-Latn…) +pub enum ProofLang { …, Pack(PackLocale), Other } // + Pack: a language without a dedicated built-in variant (nl, fr, sr-Latn…) pub struct PackLocale; // + Copy; PackLocale::new(tag) -> Option, .as_str() "nl-nl", .primary() "nl", Display impl ProofLang { pub fn pack_locale(self) -> Option; } // + pub fn pack_dictionary_file(lang: ProofLang) -> Option; // + the .dic a Pack language reads now; None = unchecked ``` -`ProofLang::from_tag` now gives `Pack(locale)` for every valid language tag it has no tools for +`ProofLang::from_tag` now gives `Pack(locale)` for every valid language tag without a dedicated built-in variant (`nl-NL` → `Pack("nl-nl")`, `fr-FR`, `ja-JP`, `sr-Latn`…); `Other` is left for `x-none`, `und`, `zxx`, `mul`, `mis`, `i-…` and malformed tags. A `Pack` language is spell-checked and given suggestions from its Hunspell dictionary (dictionaries folder → installed pack → system Hunspell) -through the shared affix engine with default tuning, and hyphenated from its pack's -`hyphenation.pat`; it has no grammar rules and the generic English spelling message. Without a -dictionary or pack it behaves exactly as `Other` did (no marks, English hyphenation fallback). +through the shared affix engine with default tuning (French tuning for `fr` packs), and +hyphenated from its pack's `hyphenation.pat`. Most pack languages use no dedicated grammar +rules; regional variants can reuse a built-in language's rules. French packs use the French +spelling message and the conservative French grammar and typography described above. Without a dictionary or pack, +spelling has no marks and hyphenation falls back to English; French grammar and typography +still apply independently of a spelling dictionary. `has_dictionary(tag)` / `ProofLang::is_proofed()` say whether a `Pack` language has a dictionary now (read on first use, cached). Loaded `Pack` dictionaries share a 256 MB budget (estimated from their files); the least recently used goes first, but never one used in the paragraph being checked, and languages with no dictionary take no room. Downstream `match`es on `ProofLang` need a `Pack(_)` arm; `code()` stays `&'static str` and is `""` for it, as for `Other`: anything that keys, saves or reports a language (settings, caches, JSON/MCP output) uses `tag()`, which is `code()` for the built-ins and the locale (`nl`, `fr-fr`) for a pack language. diff --git a/crates/proof/src/fr/mod.rs b/crates/proof/src/fr/mod.rs index 541fcac0d..c67c3ffc0 100644 --- a/crates/proof/src/fr/mod.rs +++ b/crates/proof/src/fr/mod.rs @@ -44,6 +44,7 @@ pub(crate) fn check(d: &AffixDict, word: &str, opts: &Options) -> bool { if known(d, w) { return true; } + let original = w; let w = w.replace('’', "'"); if known(d, &w) { return true; @@ -56,7 +57,7 @@ pub(crate) fn check(d: &AffixDict, word: &str, opts: &Options) -> bool { { return true; } - w.contains('-') && w.split('-').all(|p| !p.is_empty() && (p.chars().count() <= 1 || known(d, p))) + original.contains('-') && original.split('-').all(|p| !p.is_empty() && (p.chars().count() <= 1 || known(d, p) || known(d, &p.replace('’', "'")))) } fn known(d: &AffixDict, word: &str) -> bool { @@ -148,6 +149,17 @@ mod tests { assert!(!is_correct_with(&d, "maison\u{338}"), "a trailing mark is part of the word"); } + #[test] + fn curly_apostrophes_in_compounds_keep_exact_dictionary_parts() { + let d = AffixDict::from_hunspell("SET UTF-8\n", "4\naujourd’hui\nécole\ncafé\nl'école\n", &[]).unwrap(); + for word in ["aujourd’hui-école", "aujourd’hui-e\u{301}cole", "café-aujourd’hui", "l’école-aujourd’hui"] { + assert!(is_correct_with(&d, word), "{word}"); + } + for word in ["aujourd’hui-écolle", "aujourd’hui--école", "aujourd'hui-école"] { + assert!(!is_correct_with(&d, word), "{word}"); + } + } + #[test] fn explicit_curly_apostrophe_without_iconv() { let d = AffixDict::from_hunspell("SET UTF-8\n", "1\naujourd’hui\n", &[]).unwrap(); diff --git a/crates/proof/tests/affix_compatibility.rs b/crates/proof/tests/affix_compatibility.rs index 6d09e5f90..c18d9fd03 100644 --- a/crates/proof/tests/affix_compatibility.rs +++ b/crates/proof/tests/affix_compatibility.rs @@ -87,6 +87,8 @@ fn legacy_compact_data_is_refused_without_reinterpreting_homonyms() { assert_eq!(hex.len() % 2, 0); let bytes: Vec<_> = hex.as_bytes().as_chunks::<2>().0.iter().map(|pair| u8::from_str_radix(std::str::from_utf8(pair).unwrap(), 16).unwrap()).collect(); + let raw = miniz_oxide::inflate::decompress_to_vec(&bytes).unwrap(); + assert!(raw.starts_with(b"WCAFF1\n"), "fixture must contain WCAFF1 data: {}", case.name); assert!(AffixDict::from_bytes(&bytes).is_err(), "WCAFF1 must be regenerated as WCAFF2: {}", case.name); } }