Actualiza la inicialización de traza+localización
This commit is contained in:
parent
cac4c2f102
commit
67952f6840
7 changed files with 12 additions and 12 deletions
|
|
@ -1,23 +0,0 @@
|
|||
use crate::{Lazy, trace};
|
||||
use crate::config::SETTINGS;
|
||||
|
||||
use unic_langid::LanguageIdentifier;
|
||||
|
||||
/// Almacena el Identificador de Idioma Unicode ([Unicode Language Identifier]
|
||||
/// (https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier)) de
|
||||
/// la aplicación, obtenido de `SETTINGS.app.language`.
|
||||
pub static LANGID: Lazy<LanguageIdentifier> = Lazy::new(|| {
|
||||
match SETTINGS.app.language.parse() {
|
||||
Ok(language) => language,
|
||||
Err(_) => {
|
||||
trace::warn!(
|
||||
"Failed to parse language \"{}\". {}. {}. {}.",
|
||||
SETTINGS.app.language,
|
||||
"Unicode Language Identifier not recognized",
|
||||
"Using \"en-US\"",
|
||||
"Check the settings file",
|
||||
);
|
||||
"en-US".parse().unwrap()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
pub use fluent_templates::{static_loader as static_locale, Loader as Locale};
|
||||
pub use fluent_templates;
|
||||
pub use fluent_templates::fluent_bundle::FluentValue;
|
||||
|
||||
mod locale;
|
||||
pub use locale::LANGID;
|
||||
|
||||
#[macro_export]
|
||||
/// Permite integrar fácilmente localización en temas, módulos y componentes.
|
||||
macro_rules! localize {
|
||||
( $DEF_LANGID:literal, $locales:literal $(, $core_locales:literal)? ) => {
|
||||
use $crate::locale::*;
|
||||
|
||||
static_locale! {
|
||||
static LOCALES = {
|
||||
locales: $locales,
|
||||
$( core_locales: $core_locales, )?
|
||||
fallback_language: $DEF_LANGID,
|
||||
|
||||
// Elimina las marcas Unicode que delimitan los argumentos.
|
||||
customise: |bundle| bundle.set_use_isolating(false),
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn l(key: &str) -> String {
|
||||
LOCALES.lookup(&LANGID, key)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn t(
|
||||
key: &str,
|
||||
args: &std::collections::HashMap<String, FluentValue>
|
||||
) -> String {
|
||||
LOCALES.lookup_with_args(&LANGID, key, args)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn e(
|
||||
key: &str,
|
||||
args: &std::collections::HashMap<String, FluentValue>
|
||||
) -> crate::core::theme::PreEscaped<String> {
|
||||
crate::core::theme::PreEscaped(
|
||||
LOCALES.lookup_with_args(&LANGID, key, args)
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue