diff --git a/src/locale_file_parser.rs b/src/locale_file_parser.rs index 1480caa..3054aeb 100644 --- a/src/locale_file_parser.rs +++ b/src/locale_file_parser.rs @@ -16,6 +16,8 @@ pub(crate) struct Translations { pub(crate) es: Option, /// Chinese - Taiwan pub(crate) zh_tw: Option, + /// French + pub(crate) fr: Option, } impl Translations { @@ -25,6 +27,7 @@ impl Translations { en: None, es: None, zh_tw: None, + fr: None, } } @@ -55,8 +58,15 @@ impl Translations { _ => panic!("Error: translation should be string"), }) }; + let fr = { + let opt_en_yaml = translation_mapping.remove("fr"); + opt_en_yaml.map(|opt_yaml| match opt_yaml { + Yaml::String(str) => str, + _ => panic!("Error: translation should be string"), + }) + }; - Self { en, es, zh_tw } + Self { en, es, zh_tw, fr } } _ => panic!("Error: invalid format for translation"), @@ -151,7 +161,8 @@ _version: 2 "with_en": en: "with_en" es: "with_es" - zh_TW: "with_zh_TW""#; + zh_TW: "with_zh_TW" + fr: "with_fr""#; let yaml: Yaml = serde_yaml_ng::from_str(yaml_str).unwrap(); let parsed = LocalizedTexts::new(yaml); @@ -164,6 +175,7 @@ _version: 2 en: Some("with_en".to_string()), es: Some("with_es".to_string()), zh_tw: Some("with_zh_TW".to_string()), + fr: Some("with_fr".to_string()), }, ), ]), diff --git a/src/rules/key_and_eng_matches.rs b/src/rules/key_and_eng_matches.rs index de3e571..4c3f467 100644 --- a/src/rules/key_and_eng_matches.rs +++ b/src/rules/key_and_eng_matches.rs @@ -305,6 +305,7 @@ mod tests { en: None, es: Some("ff".into()), zh_tw: Some("bar".into()), + fr: Some("bar".into()), }, )]), }; @@ -330,6 +331,7 @@ mod tests { en: Some("buz".into()), es: Some("buz".into()), zh_tw: Some("buz".into()), + fr: Some("buz".into()), }, )]), }; @@ -352,6 +354,7 @@ mod tests { en: Some("Restarting {app}".into()), es: Some("Restarting {app}".into()), zh_tw: Some("Restarting {app}".into()), + fr: Some("Restarting {app}".into()), }, )]), }; @@ -374,6 +377,7 @@ mod tests { en: Some("Restarting %{app}".into()), es: Some("Restarting %{app}".into()), zh_tw: Some("Restarting %{app}".into()), + fr: Some("Restarting %{app}".into()), }, )]), }; @@ -390,6 +394,7 @@ mod tests { en: Some("Restarting".into()), es: Some("Restarting".into()), zh_tw: Some("Restarting".into()), + fr: Some("Restarting".into()), }, )]), }; diff --git a/src/rules/missing_translations.rs b/src/rules/missing_translations.rs index 22dddd0..993967f 100644 --- a/src/rules/missing_translations.rs +++ b/src/rules/missing_translations.rs @@ -13,6 +13,7 @@ bitflags! { const En = 0b_0000_0001; const Es = 0b_0000_0010; const ZhTW = 0b_0000_0100; + const Fr = 0b_0000_1000; } } @@ -31,6 +32,9 @@ impl MissingLanguages { if lang == MissingLanguages::ZhTW { str.push_str(", zh_TW"); } + if lang == MissingLanguages::Fr { + str.push_str(", fr"); + } } str.push(']'); @@ -60,6 +64,9 @@ impl Rule for MissingTranslations { if translations.zh_tw.is_none() { missing_langs.insert(MissingLanguages::ZhTW); } + if translations.fr.is_none() { + missing_langs.insert(MissingLanguages::Fr); + } if !missing_langs.is_empty() { Self::report_error(key.clone(), Some(missing_langs.error_msg()), errors); @@ -84,6 +91,7 @@ mod tests { en: None, es: None, zh_tw: Some("c".into()), + fr: Some("c".into()), }, ), ( @@ -92,6 +100,7 @@ mod tests { en: None, es: Some("c".into()), zh_tw: None, + fr: None, }, ), ( @@ -100,6 +109,7 @@ mod tests { en: Some("Restarting %{ba}".into()), es: Some("Restarting %{ba}".into()), zh_tw: Some("Restarting %{ba}".into()), + fr: Some("Restarting %{ba}".into()), }, ), ]), @@ -116,7 +126,7 @@ mod tests { ), ( "Restarting {topgrade}".to_string(), - Some("Missing translations for [en, zh_TW]".into()), + Some("Missing translations for [en, zh_TW, fr]".into()), ), ], )]); @@ -133,6 +143,7 @@ mod tests { en: Some("whatever".into()), es: Some("whatever".into()), zh_tw: Some("whatever".into()), + fr: Some("whatever".into()), }, ), ( @@ -141,6 +152,7 @@ mod tests { en: Some("wahtever".into()), es: Some("wahtever".into()), zh_tw: Some("wahtever".into()), + fr: Some("whatever".into()), }, ), ( @@ -149,6 +161,7 @@ mod tests { en: Some("Restarting %{ba}".into()), es: Some("Restarting %{ba}".into()), zh_tw: Some("Restarting %{ba}".into()), + fr: Some("whatever".into()), }, ), ]), diff --git a/src/rules/use_of_keys_do_not_exist.rs b/src/rules/use_of_keys_do_not_exist.rs index 8dbe1fd..6e43f0d 100644 --- a/src/rules/use_of_keys_do_not_exist.rs +++ b/src/rules/use_of_keys_do_not_exist.rs @@ -71,6 +71,7 @@ mod tests { en: Some("Restarting".into()), es: Some("Restarting".into()), zh_tw: Some("Restarting".into()), + fr: Some("Restarting".into()), }, )]), };