translations #2

This commit is contained in:
2023-11-27 01:19:10 +01:00
parent 07c02052fd
commit 6efbfc0e9c
7 changed files with 128 additions and 22 deletions

View File

@@ -1,10 +1,10 @@
use log::error;
use ovlach_data::cv::cv::CV;
use rocket::{get, State, response::status::NotFound, http::Status};
use rocket_dyn_templates::{Template, context};
use rocket::{get, State, response::Redirect, http::Status};
use rocket_dyn_templates::Template;
use serde::Serialize;
use crate::{PresentationConfig, services::cv::fetch_cv_data_from_backend, CVBackendConfig};
use crate::{PresentationConfig, services::cv::fetch_cv_data_from_backend, CVBackendConfig, tools::rocket::RequestLanguage};
#[derive(Serialize, Debug)]
struct RootPage {
@@ -14,14 +14,14 @@ struct RootPage {
lang: String,
}
#[get("/")]
pub async fn index(presentation_config: &State<PresentationConfig>, cv_config: &State<CVBackendConfig>) -> Result<Template, Status> {
#[get("/<language>")]
pub async fn index(presentation_config: &State<PresentationConfig>, cv_config: &State<CVBackendConfig>, language: RequestLanguage) -> Result<Template, Status> {
let context = match fetch_cv_data_from_backend(cv_config.cv_backend_path.clone()).await {
Ok(cv) => RootPage {
static_host: presentation_config.static_route.clone(),
cv,
download_cv_url: "FIXME!".to_string(),
lang: "en".to_string(),
lang: language.language,
},
Err(e) => {
error!("Can't fetch CV data from backend {:?}", e);
@@ -29,7 +29,12 @@ pub async fn index(presentation_config: &State<PresentationConfig>, cv_config: &
}
};
//return Templ;
Ok(Template::render("default", &context))
}
#[get("/")]
pub fn index_without_lang() -> Redirect {
// Default language is czech (TODO: config)
Redirect::to(format!("{}/{}", "", "cs"))
}