pub struct Languages { /* private fields */ }Expand description
Every registered language, and whether missing languages and keys are errors.
PHP: the static state of Locale.
Implementations§
Source§impl Languages
impl Languages
Sourcepub fn new() -> Self
pub fn new() -> Self
No languages, with exceptions on.
PHP: exceptions are on by default, as in PHP.
Sourcepub fn exceptions(&self) -> bool
pub fn exceptions(&self) -> bool
Whether an unknown language or a missing key or file is an error.
PHP: Locale::$exceptions.
Sourcepub fn set_exceptions(&mut self, on: bool)
pub fn set_exceptions(&mut self, on: bool)
Turns errors for unknown languages and missing keys or files on or off.
PHP: Locale::$exceptions = $on.
Sourcepub fn names(&self) -> impl Iterator<Item = &str>
pub fn names(&self) -> impl Iterator<Item = &str>
The names of the registered languages, in registration order.
PHP: Locale::getLanguages().
Sourcepub fn insert(&mut self, name: impl Into<String>, translations: Translations)
pub fn insert(&mut self, name: impl Into<String>, translations: Translations)
Registers or replaces a language; a replaced one keeps its position.
PHP: Locale::setLanguageFromArray($name, $translations).
Sourcepub fn load(
&mut self,
name: impl Into<String>,
path: &Path,
) -> Result<(), Error>
pub fn load( &mut self, name: impl Into<String>, path: &Path, ) -> Result<(), Error>
Registers a language from a JSON translation file.
With exceptions on, a path that does not exist fails with
Translation file not found.. Otherwise an unreadable file registers
a language that holds no translations, as does content that is not a
JSON object or list (see Languages::insert_json).
PHP: Locale::setLanguageFromJSON($name, $path).
Sourcepub fn insert_json(
&mut self,
name: impl Into<String>,
json: &[u8],
) -> Result<(), Error>
pub fn insert_json( &mut self, name: impl Into<String>, json: &[u8], ) -> Result<(), Error>
Registers a language from JSON text: the decoding half of
Languages::load.
A JSON object of strings, as every translation file is, is kept as its text and decoded on the language’s first lookup, once per distinct text: names registered from the same file share it. Anything else is decoded now, so its errors are returned here as before.
Invalid JSON and scalars register a language that holds no
translations, so lookups in it fail with Error::Type. An object or
list must hold strings only (Error::Unsupported otherwise); a list
is keyed by position.
PHP: reads json the way json_decode($json, true) does.