fa625d7ad8
* Run cargo +nightly fmt * Latest prost-build includes clippy workaround * Tweak Rust protobuf imports - Avoid use of stringify!(), as JetBrains editors get confused by it - Stop merging all protobuf symbols into a single namespace * Remove some unnecessary qualifications Found via IntelliJ lint * Migrate some asserts to assert_eq/ne * Remove mention of node_modules exclusion This no longer seems to be necessary after migrating away from Bazel, and excluding it means TS/Svelte files can't be edited properly.
33 lines
1.1 KiB
Rust
33 lines
1.1 KiB
Rust
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
//! Check the .ftl files at build time to ensure we don't get runtime load failures.
|
|
|
|
use fluent::{FluentBundle, FluentResource};
|
|
use unic_langid::LanguageIdentifier;
|
|
|
|
use super::gather::TranslationsByLang;
|
|
|
|
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);
|
|
});
|
|
|
|
let mut bundle: FluentBundle<FluentResource> = FluentBundle::new(vec![lang_id]);
|
|
bundle.add_resource(resource).unwrap_or_else(|e| {
|
|
panic!(
|
|
"{}\nUnable to bundle - duplicate key? {}/{}: {:?}",
|
|
content, lang, fname, e
|
|
);
|
|
});
|
|
}
|