#[macro_use] extern crate rocket; #[macro_use] extern crate rocket_accept_language; #[macro_use] extern crate json_gettext; use std::error::Error; use json_gettext::{JSONGetTextManager, Key}; use rocket::State; use rocket_accept_language::{unic_langid::subtags::Language, AcceptLanguage}; const LANGUAGE_EN: Language = language!("en"); #[get("/")] fn index(ctx: &State, accept_language: &AcceptLanguage) -> String { let language = accept_language.get_first_language().unwrap_or(LANGUAGE_EN); format!("Ron: {}", get_text!(ctx, Key(language), "hello").unwrap().as_str().unwrap()) } #[rocket::main] async fn main() -> Result<(), Box> { rocket::build() .attach(static_json_gettext_build_for_rocket!( key!("en"); key!("en") => "langs/en_US.json", key!("zh") => "langs/zh_TW.json", )) .mount("/", routes![index]) .launch() .await?; Ok(()) }