♻️ (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
|
|
@ -32,7 +32,7 @@ async fn with_aria_label_overrides_the_default() {
|
|||
.with_current_page(1)
|
||||
.with_items_per_page(10)
|
||||
.with_total_items(50)
|
||||
.with_aria_label(L10n::n("Users pagination"));
|
||||
.with_aria_label(Lc::n("Users pagination"));
|
||||
|
||||
let html = pager.render(&mut Context::default()).await.into_string();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,16 +8,16 @@ async fn setup() {
|
|||
async fn literal_text() {
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::n("© 2025 PageTop");
|
||||
assert_eq!(l10n.get(), Some("© 2025 PageTop".to_string()));
|
||||
let lc = Lc::n("© 2025 PageTop");
|
||||
assert_eq!(lc.get(), Some("© 2025 PageTop".to_string()));
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn translation_without_args() {
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::l("test_hello_world");
|
||||
let translation = l10n.lookup(&Locale::resolve("es-ES"));
|
||||
let lc = Lc::l("test_hello_world");
|
||||
let translation = lc.lookup(&Locale::resolve("es-ES"));
|
||||
assert_eq!(translation, Some("¡Hola mundo!".to_string()));
|
||||
}
|
||||
|
||||
|
|
@ -25,8 +25,8 @@ async fn translation_without_args() {
|
|||
async fn translation_with_args() {
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::l("test_hello_user").with_arg("userName", "Manuel");
|
||||
let translation = l10n.lookup(&Locale::resolve("es-ES"));
|
||||
let lc = Lc::l("test_hello_user").with_arg("userName", "Manuel");
|
||||
let translation = lc.lookup(&Locale::resolve("es-ES"));
|
||||
assert_eq!(translation, Some("¡Hola, Manuel!".to_string()));
|
||||
}
|
||||
|
||||
|
|
@ -34,12 +34,12 @@ async fn translation_with_args() {
|
|||
async fn translation_with_plural_and_select() {
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::l("test_shared_photos").with_args(vec![
|
||||
let lc = Lc::l("test_shared_photos").with_args(vec![
|
||||
("userName", "Roberto"),
|
||||
("photoCount", "3"),
|
||||
("userGender", "male"),
|
||||
]);
|
||||
let translation = l10n.lookup(&Locale::resolve("es-ES")).unwrap();
|
||||
let translation = lc.lookup(&Locale::resolve("es-ES")).unwrap();
|
||||
assert!(translation.contains("añadido 3 nuevas fotos de él"));
|
||||
}
|
||||
|
||||
|
|
@ -47,8 +47,8 @@ async fn translation_with_plural_and_select() {
|
|||
async fn check_fallback_language() {
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::l("test_hello_world");
|
||||
let translation = l10n.lookup(&Locale::resolve("xx-YY")); // Retrocede a "en-US".
|
||||
let lc = Lc::l("test_hello_world");
|
||||
let translation = lc.lookup(&Locale::resolve("xx-YY")); // Retrocede a "en-US".
|
||||
assert_eq!(translation, Some("Hello world!".to_string()));
|
||||
}
|
||||
|
||||
|
|
@ -56,32 +56,32 @@ async fn check_fallback_language() {
|
|||
async fn check_unknown_key() {
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::l("non-existent-key");
|
||||
let translation = l10n.lookup(&Locale::resolve("en-US"));
|
||||
let lc = Lc::l("non-existent-key");
|
||||
let translation = lc.lookup(&Locale::resolve("en-US"));
|
||||
assert_eq!(translation, None);
|
||||
}
|
||||
|
||||
// `using()` renders literal text (`L10n::n()`) as HTML-escaped `Markup`, because it may come from
|
||||
// `using()` renders literal text (`Lc::n()`) as HTML-escaped `Markup`, because it may come from
|
||||
// runtime data (e.g. a menu title or a role label) rather than developer-authored content.
|
||||
#[pagetop::test]
|
||||
async fn literal_text_is_escaped_when_rendered_as_markup() {
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::n("<script>alert(1)</script>");
|
||||
let markup = l10n.using(&Locale::default());
|
||||
let lc = Lc::n("<script>alert(1)</script>");
|
||||
let markup = lc.using(&Locale::default());
|
||||
assert_eq!(
|
||||
markup.into_string(),
|
||||
"<script>alert(1)</script>"
|
||||
);
|
||||
}
|
||||
|
||||
// Translation keys (`L10n::l()`/`L10n::t()`) are developer-authored `.ftl` content that may embed
|
||||
// Translation keys (`Lc::l()`/`Lc::t()`) are developer-authored `.ftl` content that may embed
|
||||
// HTML on purpose (e.g. `<strong>`), so `using()` must keep rendering them unescaped.
|
||||
#[pagetop::test]
|
||||
async fn translated_text_is_not_escaped_when_rendered_as_markup() {
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::l("test_hello_world");
|
||||
let markup = l10n.using(&Locale::resolve("en-US"));
|
||||
let lc = Lc::l("test_hello_world");
|
||||
let markup = lc.using(&Locale::resolve("en-US"));
|
||||
assert_eq!(markup.into_string(), "Hello world!");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue