// 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 { 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"); } } }