pagetop-website/tools/doccheck/tests/localization.rs
Manuel Cillero 345bd26974 📝 Document route access and custom authentication
Adapt the guides to the current PageTop API: Routes with the access of
each route, Layers, StaticFiles and the administration panel in the
core, with pagetop-admin reduced to the settings forms.

Add the "Connect your own authentication" guide, the mail test page and
the admin_path setting, and explain route access in the architecture
page.

Mount the books with their access through pagetop-mdbook.
2026-11-07 17:24:26 +01:00

41 lines
1.5 KiB
Rust

// Runtime check of the localization chapter: translations, arguments and plurals in both languages.
use pagetop::prelude::*;
include_locales!(LOCALES_APP);
struct App;
#[async_trait]
impl Extension for App {
fn configure_router(&self, routes: Routes) -> Routes {
routes.public_route("/", web::get(home))
}
}
async fn home(request: HttpRequest) -> Result<Markup, ErrorPage> {
Page::new(request)
.with_child(Html::with(|cx| {
let welcome = Lc::t("welcome", &LOCALES_APP).with_arg("name", "Ana");
let many = Lc::t("notices", &LOCALES_APP).with_number("total", 3);
let one = Lc::t("notices", &LOCALES_APP).with_number("total", 1);
html! { p { (welcome.using(cx)) } p { (many.using(cx)) } p { (one.using(cx)) } }
}))
.render()
.await
}
#[pagetop::test]
async fn translates_with_arguments_and_plurals() {
let app = web::test::init_router(Application::prepare(&App).await.test());
for (lang, expected) in [
("es", ["Te damos la bienvenida, Ana.", "Tienes 3 avisos", "Tienes un aviso"]),
("en", ["Welcome, Ana.", "You have 3 notices", "You have one notice"]),
] {
let request = web::test::TestRequest::get().uri(format!("/?lang={lang}")).to_request();
let response = web::test::send_request(&app, request).await;
let body = web::test::read_body_text(response).await;
for text in expected {
assert!(body.contains(text), "{lang}: {text:?} not found in the page");
}
}
}