Skip to main content

sofie_engine/
english.rs

1include!(concat!(env!("OUT_DIR"), "/english.rs"));
2
3/// An engine text in English, or the key itself where `lang/en.toml` lacks it, as a missing
4/// translation is written.
5#[must_use]
6pub fn english(key: &str) -> &str {
7    ENGLISH
8        .binary_search_by(|(listed, _)| listed.cmp(&key))
9        .map_or(key, |index| ENGLISH[index].1)
10}
11
12#[cfg(test)]
13mod tests {
14    use super::*;
15
16    #[test]
17    fn reads_the_source_language_file_and_writes_a_missing_key_as_itself() {
18        assert_eq!(
19            english("notice.correct_fields"),
20            "Please correct the {count} highlighted fields."
21        );
22        assert_eq!(
23            english("validation.money.invalid"),
24            "must be an amount such as 149.90"
25        );
26        assert_eq!(english("notice.nothing"), "notice.nothing");
27    }
28}