♻️ [global] Incorpora identificador de idioma
This commit is contained in:
parent
c7bf549434
commit
e143ee57ac
5 changed files with 29 additions and 30 deletions
|
|
@ -6,8 +6,6 @@ pub use actix_web_static_files::ResourceFiles;
|
||||||
|
|
||||||
mod banner;
|
mod banner;
|
||||||
|
|
||||||
pub mod locale;
|
|
||||||
|
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ impl Application {
|
||||||
LazyStatic::force(&global::TRACING);
|
LazyStatic::force(&global::TRACING);
|
||||||
|
|
||||||
// Valida el identificador de idioma.
|
// Valida el identificador de idioma.
|
||||||
LazyStatic::force(&super::locale::LANGID);
|
LazyStatic::force(&global::LANGID);
|
||||||
|
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
// Conecta con la base de datos.
|
// Conecta con la base de datos.
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
use crate::{global, trace, LazyStatic};
|
|
||||||
|
|
||||||
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: LazyStatic<LanguageIdentifier> =
|
|
||||||
LazyStatic::new(|| match global::SETTINGS.app.language.parse() {
|
|
||||||
Ok(language) => language,
|
|
||||||
Err(_) => {
|
|
||||||
trace::warn!(
|
|
||||||
"{}, {} \"{}\"! {}, {}",
|
|
||||||
"Failed to parse language",
|
|
||||||
"unrecognized Unicode Language Identifier",
|
|
||||||
global::SETTINGS.app.language,
|
|
||||||
"Using \"en-US\"",
|
|
||||||
"check the settings file",
|
|
||||||
);
|
|
||||||
"en-US".parse().unwrap()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
use crate::{pub_config, LazyStatic};
|
use crate::{pub_config, trace, LazyStatic};
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use tracing_appender::non_blocking::WorkerGuard;
|
use tracing_appender::non_blocking::WorkerGuard;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
|
use unic_langid::LanguageIdentifier;
|
||||||
|
|
||||||
// CONFIGURACIÓN ***********************************************************************************
|
// CONFIGURACIÓN ***********************************************************************************
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
@ -189,3 +191,24 @@ pub(crate) static TRACING: LazyStatic<WorkerGuard> = LazyStatic::new(|| {
|
||||||
|
|
||||||
guard
|
guard
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// LOCALIZACIÓN ************************************************************************************
|
||||||
|
|
||||||
|
/// 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: LazyStatic<LanguageIdentifier> =
|
||||||
|
LazyStatic::new(|| match SETTINGS.app.language.parse() {
|
||||||
|
Ok(language) => language,
|
||||||
|
Err(_) => {
|
||||||
|
trace::warn!(
|
||||||
|
"{}, {} \"{}\"! {}, {}",
|
||||||
|
"Failed to parse language",
|
||||||
|
"unrecognized Unicode Language Identifier",
|
||||||
|
SETTINGS.app.language,
|
||||||
|
"Using \"en-US\"",
|
||||||
|
"check the settings file",
|
||||||
|
);
|
||||||
|
"en-US".parse().unwrap()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -102,8 +102,8 @@ pub use fluent_templates::{static_loader as static_locale, Loader as Locale};
|
||||||
/// Permite integrar fácilmente localización en temas, módulos y componentes.
|
/// Permite integrar fácilmente localización en temas, módulos y componentes.
|
||||||
macro_rules! pub_locale {
|
macro_rules! pub_locale {
|
||||||
( $dir_locales:literal $(, $core_locales:literal)? ) => {
|
( $dir_locales:literal $(, $core_locales:literal)? ) => {
|
||||||
|
use $crate::global;
|
||||||
use $crate::locale::*;
|
use $crate::locale::*;
|
||||||
use $crate::app::locale::LANGID;
|
|
||||||
|
|
||||||
static_locale! {
|
static_locale! {
|
||||||
static LOCALES = {
|
static LOCALES = {
|
||||||
|
|
@ -118,7 +118,7 @@ macro_rules! pub_locale {
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn l(key: &str) -> String {
|
fn l(key: &str) -> String {
|
||||||
LOCALES.lookup(&LANGID, key).unwrap_or(key.to_string())
|
LOCALES.lookup(&global::LANGID, key).unwrap_or(key.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
@ -126,7 +126,7 @@ macro_rules! pub_locale {
|
||||||
key: &str,
|
key: &str,
|
||||||
args: &std::collections::HashMap<String, FluentValue>
|
args: &std::collections::HashMap<String, FluentValue>
|
||||||
) -> String {
|
) -> String {
|
||||||
LOCALES.lookup_with_args(&LANGID, key, args).unwrap_or(key.to_string())
|
LOCALES.lookup_with_args(&global::LANGID, key, args).unwrap_or(key.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
@ -135,7 +135,7 @@ macro_rules! pub_locale {
|
||||||
args: &std::collections::HashMap<String, FluentValue>
|
args: &std::collections::HashMap<String, FluentValue>
|
||||||
) -> $crate::html::PreEscaped<String> {
|
) -> $crate::html::PreEscaped<String> {
|
||||||
$crate::html::PreEscaped(
|
$crate::html::PreEscaped(
|
||||||
LOCALES.lookup_with_args(&LANGID, key, args).unwrap_or(key.to_string())
|
LOCALES.lookup_with_args(&global::LANGID, key, args).unwrap_or(key.to_string())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue