🚧 Ajustes menores en rutas y localización
- Añade `Route::try_resolve()` y `RoutePath::is_empty()` para omitir atributos HTML opcionales cuando la ruta resultante está vacía. - Renombra `Locale::configured_langid()` a `try_langid()` (convención `try_*` para Option). - Reordena include_locales! y otros cambios menores.
This commit is contained in:
parent
8573aca29e
commit
b9d9cdf601
6 changed files with 22 additions and 7 deletions
|
|
@ -170,7 +170,7 @@ impl Locale {
|
|||
/// Devuelve el identificador de idioma configurado explícitamente, si es válido.
|
||||
///
|
||||
/// Si no se ha configurado un idioma por defecto o el valor no es válido, devuelve `None`.
|
||||
pub fn configured_langid() -> Option<&'static LanguageIdentifier> {
|
||||
pub fn try_langid() -> Option<&'static LanguageIdentifier> {
|
||||
*CONFIG_LANGID
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ use crate::{AutoDefault, CowStr, include_locales};
|
|||
|
||||
use super::{LangId, Locale};
|
||||
|
||||
include_locales!(LOCALES_PAGETOP);
|
||||
|
||||
use fluent_templates::Loader;
|
||||
use fluent_templates::StaticLoader as Locales;
|
||||
|
||||
|
|
@ -10,8 +12,6 @@ use std::collections::HashMap;
|
|||
|
||||
use std::fmt;
|
||||
|
||||
include_locales!(LOCALES_PAGETOP);
|
||||
|
||||
/// Operación de localización a realizar.
|
||||
///
|
||||
/// * `None` - No se aplica ninguna localización.
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ impl RequestLocale {
|
|||
/// - [`LangNegotiation::Full`](crate::global::LangNegotiation::Full) determina el idioma en
|
||||
/// este orden:
|
||||
/// 1. Parámetro de *query* `?lang=...`, si existe y corresponde a un idioma soportado.
|
||||
/// 2. [`Locale::configured_langid()`], si la aplicación tiene un idioma por defecto válido.
|
||||
/// 2. [`Locale::try_langid()`], si la aplicación tiene un idioma por defecto válido.
|
||||
/// 3. Cabecera `Accept-Language`, si puede resolverse con [`Locale::resolve()`].
|
||||
/// 4. Idioma de respaldo.
|
||||
///
|
||||
/// - [`LangNegotiation::NoQuery`](crate::global::LangNegotiation::NoQuery) descarta el uso del
|
||||
/// parámetro `?lang=...` y determina el idioma en este orden:
|
||||
/// 1. [`Locale::configured_langid()`], si la aplicación tiene un idioma por defecto válido.
|
||||
/// 1. [`Locale::try_langid()`], si la aplicación tiene un idioma por defecto válido.
|
||||
/// 2. Cabecera `Accept-Language`, si puede resolverse con [`Locale::resolve()`].
|
||||
/// 3. Idioma de respaldo.
|
||||
///
|
||||
|
|
@ -56,7 +56,7 @@ impl RequestLocale {
|
|||
Locale::default_langid()
|
||||
}
|
||||
global::LangNegotiation::Full | global::LangNegotiation::NoQuery => {
|
||||
if let Some(default) = Locale::configured_langid() {
|
||||
if let Some(default) = Locale::try_langid() {
|
||||
default
|
||||
} else {
|
||||
// Sin idioma por defecto, se evalúa la cabecera `Accept-Language`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue