2021-03-26 00:40:41 +01:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
2023-01-18 12:39:55 +01:00
|
|
|
//! Check the .ftl files at build time to ensure we don't get runtime load
|
|
|
|
//! failures.
|
2021-03-26 00:40:41 +01:00
|
|
|
|
2023-01-18 12:39:55 +01:00
|
|
|
use fluent::FluentBundle;
|
|
|
|
use fluent::FluentResource;
|
2021-03-26 00:40:41 +01:00
|
|
|
use unic_langid::LanguageIdentifier;
|
|
|
|
|
2022-12-16 12:40:27 +01:00
|
|
|
use super::gather::TranslationsByLang;
|
|
|
|
|
2021-03-26 00:40:41 +01:00
|
|
|
pub fn check(lang_map: &TranslationsByLang) {
|
|
|
|
for (lang, files_map) in lang_map {
|
|
|
|
for (fname, content) in files_map {
|
|
|
|
check_content(lang, fname, content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_content(lang: &str, fname: &str, content: &str) {
|
|
|
|
let lang_id: LanguageIdentifier = "en-US".parse().unwrap();
|
|
|
|
let resource = FluentResource::try_new(content.into()).unwrap_or_else(|e| {
|
|
|
|
panic!("{}\nUnable to parse {}/{}: {:?}", content, lang, fname, e);
|
|
|
|
});
|
|
|
|
|
2021-03-27 04:24:11 +01:00
|
|
|
let mut bundle: FluentBundle<FluentResource> = FluentBundle::new(vec![lang_id]);
|
2021-03-26 00:40:41 +01:00
|
|
|
bundle.add_resource(resource).unwrap_or_else(|e| {
|
|
|
|
panic!(
|
|
|
|
"{}\nUnable to bundle - duplicate key? {}/{}: {:?}",
|
|
|
|
content, lang, fname, e
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|