♻️ Refactoriza manejo de idiomas para localización
This commit is contained in:
parent
126b31a7ed
commit
ac0889cb8c
7 changed files with 218 additions and 135 deletions
|
@ -1,5 +1,5 @@
|
|||
use crate::html::Markup;
|
||||
use crate::locale::{L10n, LanguageIdentifier};
|
||||
use crate::locale::{L10n, LangId};
|
||||
use crate::{builder_fn, AutoDefault};
|
||||
|
||||
/// Cadena para traducir al renderizar ([`locale`](crate::locale)).
|
||||
|
@ -16,18 +16,18 @@ use crate::{builder_fn, AutoDefault};
|
|||
///
|
||||
/// // Español disponible.
|
||||
/// assert_eq!(
|
||||
/// hello.using(LangMatch::langid_or_default("es-ES")),
|
||||
/// hello.using(&LangMatch::resolve("es-ES")),
|
||||
/// Some(String::from("¡Hola mundo!"))
|
||||
/// );
|
||||
///
|
||||
/// // Japonés no disponible, traduce al idioma de respaldo ("en-US").
|
||||
/// assert_eq!(
|
||||
/// hello.using(LangMatch::langid_or_fallback("ja-JP")),
|
||||
/// hello.using(&LangMatch::resolve("ja-JP")),
|
||||
/// Some(String::from("Hello world!"))
|
||||
/// );
|
||||
///
|
||||
/// // Para incrustar en HTML escapado:
|
||||
/// let markup = hello.escaped(LangMatch::langid_or_default("es-ES"));
|
||||
/// let markup = hello.to_markup(&LangMatch::resolve("es-ES"));
|
||||
/// assert_eq!(markup.into_string(), "¡Hola mundo!");
|
||||
/// ```
|
||||
#[derive(AutoDefault, Clone, Debug)]
|
||||
|
@ -50,16 +50,16 @@ impl OptionTranslated {
|
|||
|
||||
// OptionTranslated GETTERS ********************************************************************
|
||||
|
||||
/// Devuelve la traducción para `langid`, si existe.
|
||||
pub fn using(&self, langid: &LanguageIdentifier) -> Option<String> {
|
||||
self.0.using(langid)
|
||||
/// Devuelve la traducción para `language`, si existe.
|
||||
pub fn using(&self, language: &impl LangId) -> Option<String> {
|
||||
self.0.using(language)
|
||||
}
|
||||
|
||||
/// Devuelve la traducción *escapada* como [`Markup`] para `langid`, si existe.
|
||||
/// Devuelve la traducción *escapada* como [`Markup`] para `language`, si existe.
|
||||
///
|
||||
/// Útil para incrustar el texto directamente en plantillas HTML sin riesgo de inyección de
|
||||
/// contenido.
|
||||
pub fn escaped(&self, langid: &LanguageIdentifier) -> Markup {
|
||||
self.0.escaped(langid)
|
||||
pub fn to_markup(&self, language: &impl LangId) -> Markup {
|
||||
self.0.to_markup(language)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue