Añade traducción de textos con plantillas Fluent
This commit is contained in:
parent
96884cbbc0
commit
0e3300dc90
14 changed files with 149 additions and 53 deletions
51
src/main.rs
51
src/main.rs
|
|
@ -1,53 +1,4 @@
|
|||
use pagetop::config_get;
|
||||
use pagetop::core::module::Module;
|
||||
use pagetop::core::{register_module, server};
|
||||
|
||||
struct Greet;
|
||||
impl Module for Greet {
|
||||
fn name(&self) -> String {
|
||||
"Hello".to_string()
|
||||
}
|
||||
|
||||
fn configure_module(&self, cfg: &mut server::web::ServiceConfig) {
|
||||
cfg.service(
|
||||
server::web::resource("/")
|
||||
.route(server::web::get().to(greet))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async fn greet() -> impl server::Responder {
|
||||
format!("Hello from {}!", config_get!("app.name"))
|
||||
}
|
||||
|
||||
struct GreetWithParam;
|
||||
impl Module for GreetWithParam {
|
||||
fn name(&self) -> String {
|
||||
"Hello World!".to_string()
|
||||
}
|
||||
|
||||
fn configure_module(&self, cfg: &mut server::web::ServiceConfig) {
|
||||
cfg.service(
|
||||
server::web::resource("/{name}")
|
||||
.route(server::web::get().to(greet_with_param))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async fn greet_with_param(req: server::HttpRequest) -> server::HttpResponse {
|
||||
let name: String = req.match_info().get("name").unwrap_or("World").into();
|
||||
server::HttpResponse::Ok()
|
||||
.body(sycamore::render_to_string(|ctx| sycamore::view! { ctx,
|
||||
p { "Hello " (name) "!" }
|
||||
}))
|
||||
}
|
||||
|
||||
fn bootstrap() {
|
||||
register_module(&Greet);
|
||||
register_module(&GreetWithParam);
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
server::run(Some(bootstrap))?.await
|
||||
pagetop::core::server::run(None)?.await
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue