Skip to main content

check

Function check 

Source
pub fn check(sources: &[(&str, &str)]) -> Vec<Problem>
Expand description

Checks locale files for syntax errors and keys missing from non-default locales.

Reads (code, file contents) pairs the way Catalog::load does: first the syntax of each file (Problem::Invalid), then every key of the default (first) locale in every other one (Problem::Missing), with the plural forms each language needs (Russian needs one, few, many and other; Japanese only other). A plural key present as plain text counts as present. When the default file is invalid, only syntax problems are reported. Nothing is logged; ocre i18n missing prints the result and fails when it is not empty.

§Examples

use ocre::i18n::{Problem, check};

let problems = check(&[
    ("en", "en:\n  title: Posts\n  count:\n    one: \"%{count} post\"\n    other: \"%{count} posts\"\n"),
    ("fr", "fr:\n  count:\n    one: \"%{count} article\"\n    other: \"%{count} articles\"\n"),
]);
assert_eq!(problems, [Problem::Missing { locale: "fr".into(), key: "title".into() }]);

// Russian needs more plural forms than English.
let problems = check(&[
    ("en", "en:\n  count:\n    one: \"%{count} post\"\n    other: \"%{count} posts\"\n"),
    ("ru", "ru:\n  count:\n    one: \"%{count} пост\"\n    other: \"%{count} поста\"\n"),
]);
let lines: Vec<String> = problems.iter().map(ToString::to_string).collect();
assert_eq!(lines, ["locales/ru.yml: missing count.few", "locales/ru.yml: missing count.many"]);