♻️ (locale): Renombra L10n a Lc
Simplifica el nombre del tipo de localización. Actualiza todas las referencias en el crate principal, extensiones, ejemplos y tests.
This commit is contained in:
parent
3198b74399
commit
be10dd28a1
65 changed files with 612 additions and 621 deletions
|
|
@ -206,9 +206,9 @@ impl<C: Component> Embed<C> {
|
|||
///
|
||||
/// ```rust,no_run
|
||||
/// # use pagetop::prelude::*;
|
||||
/// let mut embed = Embed::with(Block::new().with_title(L10n::n("Title")));
|
||||
/// let mut embed = Embed::with(Block::new().with_title(Lc::n("Title")));
|
||||
/// if let Some(component) = embed.get_mut() {
|
||||
/// component.alter_title(L10n::n("New Title"));
|
||||
/// component.alter_title(Lc::n("New Title"));
|
||||
/// }
|
||||
/// ```
|
||||
pub fn get_mut(&mut self) -> Option<&mut C>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::core::theme::{ChildrenInRegions, CoreRegions, CoreTemplates};
|
|||
use crate::core::theme::{RegionRef, TemplateRef, ThemeRef};
|
||||
use crate::html::{Assets, Favicon, JavaScript, Preload, StyleSheet};
|
||||
use crate::html::{Markup, Props, PropsOp, RoutePath, html};
|
||||
use crate::locale::L10n;
|
||||
use crate::locale::Lc;
|
||||
use crate::locale::{LangId, LanguageIdentifier, RequestLocale};
|
||||
use crate::web::HttpRequest;
|
||||
use crate::{builder_fn, util};
|
||||
|
|
@ -509,9 +509,9 @@ impl Context {
|
|||
/// ```rust,no_run
|
||||
/// # use pagetop::prelude::*;
|
||||
/// # let mut cx = Context::default();
|
||||
/// cx.push_message(MessageLevel::Warning, L10n::n("Session is not valid"));
|
||||
/// cx.push_message(MessageLevel::Warning, Lc::n("Session is not valid"));
|
||||
/// ```
|
||||
pub fn push_message(&mut self, level: MessageLevel, text: L10n) {
|
||||
pub fn push_message(&mut self, level: MessageLevel, text: Lc) {
|
||||
self.messages.push(StatusMessage::new(level, text));
|
||||
}
|
||||
|
||||
|
|
@ -532,13 +532,13 @@ impl Context {
|
|||
/// global de idioma de la aplicación, la cabecera `Accept-Language` y/o el idioma de respaldo.
|
||||
///
|
||||
/// Todo ello según la negociación indicada en [`global::SETTINGS.app.lang_negotiation`]. Esto
|
||||
/// permite que el [`Context`] se use como fuente de idioma coherente en [`L10n::lookup()`] o
|
||||
/// [`L10n::using()`].
|
||||
/// permite que el [`Context`] se use como fuente de idioma coherente en [`Lc::lookup()`] o
|
||||
/// [`Lc::using()`].
|
||||
///
|
||||
/// [`Context`]: crate::core::component::Context
|
||||
/// [`global::SETTINGS.app.lang_negotiation`]: crate::global::App::lang_negotiation
|
||||
/// [`L10n::lookup()`]: crate::locale::L10n::lookup
|
||||
/// [`L10n::using()`]: crate::locale::L10n::using
|
||||
/// [`Lc::lookup()`]: crate::locale::Lc::lookup
|
||||
/// [`Lc::using()`]: crate::locale::Lc::using
|
||||
impl LangId for Context {
|
||||
#[inline]
|
||||
fn langid(&self) -> &'static LanguageIdentifier {
|
||||
|
|
|
|||
|
|
@ -111,28 +111,33 @@ pub trait Component: AnyInfo + ComponentClone + ComponentRender + Send + Sync {
|
|||
/// Genera el marcado HTML del componente cuando ningún tema lo sobrescribe.
|
||||
///
|
||||
/// Este es el cuarto paso del [ciclo de renderizado](ComponentRender) tras llamar al
|
||||
/// [`setup()`](Self::setup) del componente y despachar la acción
|
||||
/// [`BeforeRender`](crate::base::action::component::BeforeRender) que atiende los cambios de
|
||||
/// [`setup()`] del componente y despachar la acción [`BeforeRender`] que atiende los cambios de
|
||||
/// otras extensiones antes de renderizar. Se invoca sólo si ningún tema en la cadena devuelve
|
||||
/// `Some` en [`Theme::handle_component()`](crate::core::theme::Theme::handle_component) para
|
||||
/// este componente.
|
||||
/// `Some` en [`Theme::handle_component()`] para este componente.
|
||||
///
|
||||
/// Es `async`, a diferencia de [`setup()`](Self::setup), para permitir a los componentes
|
||||
/// realizar aquí sus llamadas asíncronas, como consultas a base de datos, peticiones a
|
||||
/// servicios externos, o cualquier operación de E/S, que necesiten para preparar su contenido.
|
||||
/// Es `async`, a diferencia de [`setup()`], para permitir a los componentes realizar aquí sus
|
||||
/// llamadas asíncronas, como consultas a base de datos, peticiones a servicios externos, o
|
||||
/// cualquier operación de E/S, que necesiten para preparar su contenido.
|
||||
///
|
||||
/// Se recomienda obtener los datos del componente a través de sus propios métodos para que los
|
||||
/// temas puedan implementar `handle_component()` sin depender de los detalles internos.
|
||||
///
|
||||
/// Los campos que representen contenido no deben almacenar [`Markup`] ya generado, sino que
|
||||
/// guardarán el dato en bruto, por ejemplo [`L10n`](crate::locale::L10n) para textos
|
||||
/// traducibles, o un componente anidado como [`Html`](crate::base::component::Html), o
|
||||
/// cualquier otro `Component`, normalmente a través de [`Embed`](crate::core::component::Embed)
|
||||
/// o [`Child`](crate::core::component::Child); y será este método quien lo convierta en HTML en
|
||||
/// el momento del renderizado, no quien construye la instancia.
|
||||
/// guardarán el dato en bruto, por ejemplo [`Lc`] para textos traducibles, o un componente
|
||||
/// anidado como [`Html`], o cualquier otro `Component`, normalmente a través de [`Embed`] o
|
||||
/// [`Child`]; y será este método quien lo convierta en HTML en el momento del renderizado, no
|
||||
/// quien construye la instancia.
|
||||
///
|
||||
/// Por defecto, devuelve un [`Markup`] vacío (`Ok(html! {})`). En caso de error, devuelve un
|
||||
/// [`ComponentError`] que puede incluir un marcado alternativo (*fallback*).
|
||||
///
|
||||
/// [`setup()`]: Self::setup
|
||||
/// [`BeforeRender`]: crate::base::action::component::BeforeRender
|
||||
/// [`Theme::handle_component()`]: crate::core::theme::Theme::handle_component
|
||||
/// [`Lc`]: crate::locale::Lc
|
||||
/// [`Html`]: crate::base::component::Html
|
||||
/// [`Embed`]: crate::core::component::Embed
|
||||
/// [`Child`]: crate::core::component::Child
|
||||
#[allow(unused_variables)]
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
Ok(html! {})
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::locale::L10n;
|
||||
use crate::locale::Lc;
|
||||
use crate::{AutoDefault, Getters};
|
||||
|
||||
/// Nivel de severidad de un [`StatusMessage`].
|
||||
|
|
@ -20,30 +20,30 @@ pub enum MessageLevel {
|
|||
/// puede generarse en cualquier punto del procesamiento de una petición web (handlers, renderizado,
|
||||
/// lógica de negocio, etc.).
|
||||
///
|
||||
/// El texto se almacena como [`L10n`] para resolverse con el idioma del contexto en el momento de
|
||||
/// la visualización.
|
||||
/// El texto se almacena como [`Lc`] para resolverse con el idioma del contexto en el momento de la
|
||||
/// visualización.
|
||||
///
|
||||
/// # Ejemplo
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use pagetop::prelude::*;
|
||||
/// // Mensaje informativo con clave traducible.
|
||||
/// let info = StatusMessage::new(MessageLevel::Info, L10n::l("saved-successfully"));
|
||||
/// let info = StatusMessage::new(MessageLevel::Info, Lc::l("saved-successfully"));
|
||||
///
|
||||
/// // Aviso con texto literal sin traducción.
|
||||
/// let warn = StatusMessage::new(MessageLevel::Warning, L10n::n("Incomplete form."));
|
||||
/// let warn = StatusMessage::new(MessageLevel::Warning, Lc::n("Incomplete form."));
|
||||
/// ```
|
||||
#[derive(Debug, Getters)]
|
||||
pub struct StatusMessage {
|
||||
/// Nivel de severidad del mensaje.
|
||||
level: MessageLevel,
|
||||
/// Texto del mensaje.
|
||||
text: L10n,
|
||||
text: Lc,
|
||||
}
|
||||
|
||||
impl StatusMessage {
|
||||
/// Crea un nuevo mensaje de usuario con el nivel y texto indicados.
|
||||
pub fn new(level: MessageLevel, text: L10n) -> Self {
|
||||
pub fn new(level: MessageLevel, text: Lc) -> Self {
|
||||
StatusMessage { level, text }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::async_trait;
|
|||
use crate::core::AnyInfo;
|
||||
use crate::core::action::ActionBox;
|
||||
use crate::core::theme::ThemeRef;
|
||||
use crate::locale::L10n;
|
||||
use crate::locale::Lc;
|
||||
use crate::web::Router;
|
||||
|
||||
/// Interfaz común que debe implementar cualquier extensión de PageTop.
|
||||
|
|
@ -17,12 +17,12 @@ use crate::web::Router;
|
|||
///
|
||||
/// #[async_trait]
|
||||
/// impl Extension for MyExtension {
|
||||
/// fn name(&self) -> L10n {
|
||||
/// L10n::n("My Extension")
|
||||
/// fn name(&self) -> Lc {
|
||||
/// Lc::n("My Extension")
|
||||
/// }
|
||||
///
|
||||
/// fn description(&self) -> L10n {
|
||||
/// L10n::n("Does something useful")
|
||||
/// fn description(&self) -> Lc {
|
||||
/// Lc::n("Does something useful")
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
|
|
@ -32,15 +32,15 @@ pub trait Extension: AnyInfo + Send + Sync {
|
|||
///
|
||||
/// Predeterminado por el [`short_name()`](AnyInfo::short_name) del tipo asociado a la
|
||||
/// extensión.
|
||||
fn name(&self) -> L10n {
|
||||
L10n::n(self.short_name())
|
||||
fn name(&self) -> Lc {
|
||||
Lc::n(self.short_name())
|
||||
}
|
||||
|
||||
/// Descripción corta de la extensión como *texto localizado* para paneles, listados, etc.
|
||||
///
|
||||
/// Por defecto devuelve un valor vacío (`L10n::default()`).
|
||||
fn description(&self) -> L10n {
|
||||
L10n::default()
|
||||
/// Por defecto devuelve un valor vacío (`Lc::default()`).
|
||||
fn description(&self) -> Lc {
|
||||
Lc::default()
|
||||
}
|
||||
|
||||
/// Devuelve una referencia a esta misma extensión cuando actúa como un tema.
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@
|
|||
|
||||
use crate::AutoDefault;
|
||||
use crate::core::AnyInfo;
|
||||
use crate::locale::L10n;
|
||||
use crate::locale::Lc;
|
||||
|
||||
// **< RegionName >*********************************************************************************
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ pub trait RegionName: Send + Sync + AnyInfo {
|
|||
///
|
||||
/// En la implementación predeterminada de [`Region`](crate::base::component::layout::Region),
|
||||
/// este valor se usa como `aria-label` del contenedor de la región.
|
||||
fn label(&self) -> L10n;
|
||||
fn label(&self) -> Lc;
|
||||
}
|
||||
|
||||
/// Referencia estática a una región.
|
||||
|
|
@ -221,12 +221,12 @@ impl RegionName for CoreRegions {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn label(&self) -> L10n {
|
||||
fn label(&self) -> Lc {
|
||||
match self {
|
||||
Self::Header => L10n::l("region_header"),
|
||||
Self::Aside => L10n::l("region_aside"),
|
||||
Self::Content => L10n::l("region_content"),
|
||||
Self::Footer => L10n::l("region_footer"),
|
||||
Self::Header => Lc::l("region_header"),
|
||||
Self::Aside => Lc::l("region_aside"),
|
||||
Self::Content => Lc::l("region_content"),
|
||||
Self::Footer => Lc::l("region_footer"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -249,7 +249,7 @@ pub trait TemplateName: Send + Sync + AnyInfo {
|
|||
fn name(&self) -> &'static str;
|
||||
|
||||
/// Devuelve un *texto localizado* como etiqueta descriptiva de la plantilla.
|
||||
fn label(&self) -> L10n;
|
||||
fn label(&self) -> Lc;
|
||||
}
|
||||
|
||||
/// Referencia estática a una plantilla.
|
||||
|
|
@ -282,10 +282,10 @@ impl TemplateName for CoreTemplates {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn label(&self) -> L10n {
|
||||
fn label(&self) -> Lc {
|
||||
match self {
|
||||
Self::Standard => L10n::l("template-standard"),
|
||||
Self::Admin => L10n::l("template-admin"),
|
||||
Self::Standard => Lc::l("template-standard"),
|
||||
Self::Admin => Lc::l("template-admin"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::core::extension::Extension;
|
|||
use crate::core::theme::CoreRegions;
|
||||
use crate::global;
|
||||
use crate::html::{Markup, html};
|
||||
use crate::locale::L10n;
|
||||
use crate::locale::Lc;
|
||||
use crate::response::Page;
|
||||
use crate::web::http::StatusCode;
|
||||
|
||||
|
|
@ -32,12 +32,12 @@ use crate::web::http::StatusCode;
|
|||
///
|
||||
/// #[async_trait]
|
||||
/// impl Extension for MyTheme {
|
||||
/// fn name(&self) -> L10n {
|
||||
/// L10n::n("My theme")
|
||||
/// fn name(&self) -> Lc {
|
||||
/// Lc::n("My theme")
|
||||
/// }
|
||||
///
|
||||
/// fn description(&self) -> L10n {
|
||||
/// L10n::n("A personal theme")
|
||||
/// fn description(&self) -> Lc {
|
||||
/// Lc::n("A personal theme")
|
||||
/// }
|
||||
///
|
||||
/// fn theme(&self) -> Option<ThemeRef> {
|
||||
|
|
@ -234,14 +234,14 @@ pub trait Theme: Extension + Send + Sync {
|
|||
if let Some(parent) = self.parent() {
|
||||
return parent.error_403(page);
|
||||
}
|
||||
page.alter_title(L10n::l("error403_title")).alter_child_in(
|
||||
page.alter_title(Lc::l("error403_title")).alter_child_in(
|
||||
&CoreRegions::Content,
|
||||
ChildOp::Prepend(
|
||||
Html::with(move |cx| {
|
||||
html! {
|
||||
div {
|
||||
h1 { (L10n::l("error403_alert").using(cx)) }
|
||||
p { (L10n::l("error403_help").using(cx)) }
|
||||
h1 { (Lc::l("error403_alert").using(cx)) }
|
||||
p { (Lc::l("error403_help").using(cx)) }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -260,14 +260,14 @@ pub trait Theme: Extension + Send + Sync {
|
|||
if let Some(parent) = self.parent() {
|
||||
return parent.error_404(page);
|
||||
}
|
||||
page.alter_title(L10n::l("error404_title")).alter_child_in(
|
||||
page.alter_title(Lc::l("error404_title")).alter_child_in(
|
||||
&CoreRegions::Content,
|
||||
ChildOp::Prepend(
|
||||
Html::with(move |cx| {
|
||||
html! {
|
||||
div {
|
||||
h1 { (L10n::l("error404_alert").using(cx)) }
|
||||
p { (L10n::l("error404_help").using(cx)) }
|
||||
h1 { (Lc::l("error404_alert").using(cx)) }
|
||||
p { (Lc::l("error404_help").using(cx)) }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -304,7 +304,7 @@ pub trait Theme: Extension + Send + Sync {
|
|||
/// [`ErrorPage::ServiceUnavailable`]: crate::response::ErrorPage::ServiceUnavailable
|
||||
/// [`ErrorPage::GatewayTimeout`]: crate::response::ErrorPage::GatewayTimeout
|
||||
/// [`CoreTemplates::Standard`]: crate::core::theme::CoreTemplates::Standard
|
||||
fn error_fatal(&self, page: &mut Page, code: StatusCode, title: L10n, alert: L10n, help: L10n) {
|
||||
fn error_fatal(&self, page: &mut Page, code: StatusCode, title: Lc, alert: Lc, help: Lc) {
|
||||
if let Some(parent) = self.parent() {
|
||||
return parent.error_fatal(page, code, title, alert, help);
|
||||
}
|
||||
|
|
@ -312,8 +312,8 @@ pub trait Theme: Extension + Send + Sync {
|
|||
&CoreRegions::Content,
|
||||
ChildOp::Prepend(
|
||||
Intro::new()
|
||||
.with_title(L10n::l("error_code").with_arg("code", code.to_string()))
|
||||
.with_slogan(L10n::n(code.to_string()))
|
||||
.with_title(Lc::l("error_code").with_arg("code", code.to_string()))
|
||||
.with_slogan(Lc::n(code.to_string()))
|
||||
.with_button(None)
|
||||
.with_opening(IntroOpening::Custom)
|
||||
.with_child(Html::with(move |cx| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue