Translation support + french.
This commit is contained in:
parent
e9873c1943
commit
f059d3c61f
16 changed files with 380 additions and 169 deletions
|
|
@ -89,6 +89,7 @@ async fn main() {
|
|||
let ron_api_routes = Router::new()
|
||||
// Disabled: update user profile is now made with a post data ('edit_user_post').
|
||||
// .route("/user/update", put(services::ron::update_user))
|
||||
.route("/set_lang", put(services::ron::set_lang))
|
||||
.route("/recipe/set_title", put(services::ron::set_recipe_title))
|
||||
.route(
|
||||
"/recipe/set_description",
|
||||
|
|
@ -231,26 +232,26 @@ async fn translation(
|
|||
user.lang
|
||||
} else {
|
||||
let available_codes = Tr::available_codes();
|
||||
let jar = CookieJar::from_headers(req.headers());
|
||||
match jar.get(consts::COOKIE_LANG_NAME) {
|
||||
Some(lang) if available_codes.contains(&lang.value()) => lang.value().to_string(),
|
||||
_ => {
|
||||
let accept_language = req
|
||||
.headers()
|
||||
.get(axum::http::header::ACCEPT_LANGUAGE)
|
||||
.map(|v| v.to_str().unwrap_or_default())
|
||||
.unwrap_or_default()
|
||||
.split(',')
|
||||
.map(|l| l.split('-').next().unwrap_or_default())
|
||||
.find_or_first(|l| available_codes.contains(l));
|
||||
|
||||
// TODO: Check cookies before http headers.
|
||||
|
||||
let accept_language = req
|
||||
.headers()
|
||||
.get(axum::http::header::ACCEPT_LANGUAGE)
|
||||
.map(|v| v.to_str().unwrap_or_default())
|
||||
.unwrap_or_default()
|
||||
.split(',')
|
||||
.map(|l| l.split('-').next().unwrap_or_default())
|
||||
.find_or_first(|l| available_codes.contains(l));
|
||||
|
||||
// TODO: Save to cookies.
|
||||
|
||||
accept_language.unwrap_or("en").to_string()
|
||||
accept_language.unwrap_or("en").to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let tr = Tr::new(&language);
|
||||
|
||||
// let jar = CookieJar::from_headers(req.headers());
|
||||
req.extensions_mut().insert(tr);
|
||||
Ok(next.run(req).await)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue