Skip to content

Commit

Permalink
feat: check fr
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC committed Oct 29, 2024
1 parent 2ba038a commit 61812a2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/locale_file_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub(crate) struct Translations {
pub(crate) es: Option<String>,
/// Chinese - Taiwan
pub(crate) zh_tw: Option<String>,
/// French
pub(crate) fr: Option<String>,
}

impl Translations {
Expand All @@ -25,6 +27,7 @@ impl Translations {
en: None,
es: None,
zh_tw: None,
fr: None,
}
}

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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);

Expand All @@ -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()),
},
),
]),
Expand Down
5 changes: 5 additions & 0 deletions src/rules/key_and_eng_matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ mod tests {
en: None,
es: Some("ff".into()),
zh_tw: Some("bar".into()),
fr: Some("bar".into()),
},
)]),
};
Expand All @@ -330,6 +331,7 @@ mod tests {
en: Some("buz".into()),
es: Some("buz".into()),
zh_tw: Some("buz".into()),
fr: Some("buz".into()),
},
)]),
};
Expand All @@ -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()),
},
)]),
};
Expand All @@ -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()),
},
)]),
};
Expand All @@ -390,6 +394,7 @@ mod tests {
en: Some("Restarting".into()),
es: Some("Restarting".into()),
zh_tw: Some("Restarting".into()),
fr: Some("Restarting".into()),
},
)]),
};
Expand Down
15 changes: 14 additions & 1 deletion src/rules/missing_translations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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(']');

Expand Down Expand Up @@ -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);
Expand All @@ -84,6 +91,7 @@ mod tests {
en: None,
es: None,
zh_tw: Some("c".into()),
fr: Some("c".into()),
},
),
(
Expand All @@ -92,6 +100,7 @@ mod tests {
en: None,
es: Some("c".into()),
zh_tw: None,
fr: None,
},
),
(
Expand All @@ -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()),
},
),
]),
Expand All @@ -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()),
),
],
)]);
Expand All @@ -133,6 +143,7 @@ mod tests {
en: Some("whatever".into()),
es: Some("whatever".into()),
zh_tw: Some("whatever".into()),
fr: Some("whatever".into()),
},
),
(
Expand All @@ -141,6 +152,7 @@ mod tests {
en: Some("wahtever".into()),
es: Some("wahtever".into()),
zh_tw: Some("wahtever".into()),
fr: Some("whatever".into()),
},
),
(
Expand All @@ -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()),
},
),
]),
Expand Down
1 change: 1 addition & 0 deletions src/rules/use_of_keys_do_not_exist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ mod tests {
en: Some("Restarting".into()),
es: Some("Restarting".into()),
zh_tw: Some("Restarting".into()),
fr: Some("Restarting".into()),
},
)]),
};
Expand Down

0 comments on commit 61812a2

Please sign in to comment.