@@ -7,8 +7,8 @@ use crate::{
77 types:: { EntryStatus , Plural , PluralCategory , Resource , Translation } ,
88} ;
99
10- use serde:: Serialize ;
1110use lazy_static:: lazy_static;
11+ use serde:: Serialize ;
1212
1313lazy_static ! {
1414 /// Static mapping from base language subtag → required plural categories (CLDR‑style, cardinals).
@@ -91,21 +91,20 @@ pub struct PluralValidationReport {
9191pub fn required_categories_for ( lang : & LanguageIdentifier ) -> BTreeSet < PluralCategory > {
9292 // Base language subtag only for rule selection
9393 let lang_str = lang. language . as_str ( ) ;
94- CATEGORY_TABLE
95- . get ( lang_str)
96- . cloned ( )
97- . unwrap_or_else ( || {
98- // Conservative default to avoid noisy validation for unknown locales
99- let mut s = BTreeSet :: new ( ) ;
100- s. insert ( PluralCategory :: Other ) ;
101- s
102- } )
94+ CATEGORY_TABLE . get ( lang_str) . cloned ( ) . unwrap_or_else ( || {
95+ // Conservative default to avoid noisy validation for unknown locales
96+ let mut s = BTreeSet :: new ( ) ;
97+ s. insert ( PluralCategory :: Other ) ;
98+ s
99+ } )
103100}
104101
105102/// Helper for string language codes (accepts underscores, normalizes to hyphen).
106103pub fn required_categories_for_str ( lang : & str ) -> BTreeSet < PluralCategory > {
107104 let normalized = lang. replace ( '_' , "-" ) ;
108- let parsed: LanguageIdentifier = normalized. parse ( ) . unwrap_or_else ( |_| "und" . parse ( ) . unwrap ( ) ) ;
105+ let parsed: LanguageIdentifier = normalized
106+ . parse ( )
107+ . unwrap_or_else ( |_| "und" . parse ( ) . unwrap ( ) ) ;
109108 required_categories_for ( & parsed)
110109}
111110
@@ -177,7 +176,9 @@ pub fn validate_resource_plurals(resource: &Resource) -> Result<(), Error> {
177176///
178177/// Returns the number of categories added across the resource.
179178pub fn autofix_fill_missing_from_other_resource ( resource : & mut Resource ) -> usize {
180- let Some ( lang_id) = resource. parse_language_identifier ( ) else { return 0 ; } ;
179+ let Some ( lang_id) = resource. parse_language_identifier ( ) else {
180+ return 0 ;
181+ } ;
181182 let mut added = 0usize ;
182183 for entry in & mut resource. entries {
183184 // Skip entries that shouldn't be translated
@@ -193,8 +194,8 @@ pub fn autofix_fill_missing_from_other_resource(resource: &mut Resource) -> usiz
193194 if let Some ( other_val) = plural. forms . get ( & PluralCategory :: Other ) . cloned ( ) {
194195 for cat in missing {
195196 // Insert only if still missing (avoid race with duplicates)
196- if ! plural. forms . contains_key ( & cat) {
197- plural . forms . insert ( cat , other_val. clone ( ) ) ;
197+ if let std :: collections :: btree_map :: Entry :: Vacant ( e ) = plural. forms . entry ( cat) {
198+ e . insert ( other_val. clone ( ) ) ;
198199 added += 1 ;
199200 }
200201 }
@@ -247,11 +248,13 @@ mod tests {
247248 } ,
248249 entries : vec ! [ Entry {
249250 id: "apples" . into( ) ,
250- value: Translation :: Plural ( Plural :: new(
251- "apples" ,
252- vec![ ( PluralCategory :: Other , "%d apples" . to_string( ) ) ] . into_iter( ) ,
253- )
254- . unwrap( ) ) ,
251+ value: Translation :: Plural (
252+ Plural :: new(
253+ "apples" ,
254+ vec![ ( PluralCategory :: Other , "%d apples" . to_string( ) ) ] . into_iter( ) ,
255+ )
256+ . unwrap( ) ,
257+ ) ,
255258 comment: None ,
256259 status: EntryStatus :: Translated ,
257260 custom: Default :: default ( ) ,
@@ -273,11 +276,13 @@ mod tests {
273276 } ,
274277 entries : vec ! [ Entry {
275278 id: "apples" . into( ) ,
276- value: Translation :: Plural ( Plural :: new(
277- "apples" ,
278- vec![ ( PluralCategory :: Other , "%d apples" . to_string( ) ) ] . into_iter( ) ,
279- )
280- . unwrap( ) ) ,
279+ value: Translation :: Plural (
280+ Plural :: new(
281+ "apples" ,
282+ vec![ ( PluralCategory :: Other , "%d apples" . to_string( ) ) ] . into_iter( ) ,
283+ )
284+ . unwrap( ) ,
285+ ) ,
281286 comment: None ,
282287 status: EntryStatus :: Translated ,
283288 custom: Default :: default ( ) ,
@@ -304,11 +309,13 @@ mod tests {
304309 } ,
305310 entries : vec ! [ Entry {
306311 id: "apples" . into( ) ,
307- value: Translation :: Plural ( Plural :: new(
308- "apples" ,
309- vec![ ( PluralCategory :: Other , "%d apples" . to_string( ) ) ] . into_iter( ) ,
310- )
311- . unwrap( ) ) ,
312+ value: Translation :: Plural (
313+ Plural :: new(
314+ "apples" ,
315+ vec![ ( PluralCategory :: Other , "%d apples" . to_string( ) ) ] . into_iter( ) ,
316+ )
317+ . unwrap( ) ,
318+ ) ,
312319 comment: None ,
313320 status: EntryStatus :: Translated ,
314321 custom: Default :: default ( ) ,
0 commit comments