Translation (WIP)
This commit is contained in:
parent
9b0fcec5e2
commit
e9873c1943
29 changed files with 586 additions and 285 deletions
|
|
@ -10,7 +10,7 @@ use axum::{
|
|||
use crate::{
|
||||
data::{db, model},
|
||||
html_templates::*,
|
||||
ron_utils,
|
||||
ron_utils, translation,
|
||||
};
|
||||
|
||||
pub mod fragments;
|
||||
|
|
@ -19,7 +19,11 @@ pub mod ron;
|
|||
pub mod user;
|
||||
|
||||
// Will embed RON error in HTML page.
|
||||
pub async fn ron_error_to_html(req: Request, next: Next) -> Result<Response> {
|
||||
pub async fn ron_error_to_html(
|
||||
Extension(tr): Extension<translation::Tr>,
|
||||
req: Request,
|
||||
next: Next,
|
||||
) -> Result<Response> {
|
||||
let response = next.run(req).await;
|
||||
|
||||
if let Some(content_type) = response.headers().get(header::CONTENT_TYPE) {
|
||||
|
|
@ -32,6 +36,7 @@ pub async fn ron_error_to_html(req: Request, next: Next) -> Result<Response> {
|
|||
user: None,
|
||||
message,
|
||||
as_code: true,
|
||||
tr,
|
||||
}
|
||||
.into_response());
|
||||
}
|
||||
|
|
@ -46,6 +51,7 @@ pub async fn ron_error_to_html(req: Request, next: Next) -> Result<Response> {
|
|||
pub async fn home_page(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(tr): Extension<translation::Tr>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
let recipes = Recipes {
|
||||
published: connection.get_all_published_recipe_titles().await?,
|
||||
|
|
@ -59,15 +65,18 @@ pub async fn home_page(
|
|||
current_id: None,
|
||||
};
|
||||
|
||||
Ok(HomeTemplate { user, recipes })
|
||||
Ok(HomeTemplate { user, recipes, tr })
|
||||
}
|
||||
|
||||
///// 404 /////
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn not_found(Extension(user): Extension<Option<model::User>>) -> impl IntoResponse {
|
||||
pub async fn not_found(
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(tr): Extension<translation::Tr>,
|
||||
) -> impl IntoResponse {
|
||||
(
|
||||
StatusCode::NOT_FOUND,
|
||||
MessageTemplate::new_with_user("404: Not found", user),
|
||||
MessageTemplate::new_with_user("404: Not found", tr, user),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue