diff --git a/src/controller/meta_handler.rs b/src/controller/meta_handler.rs index 886a7d99..2a7650f0 100644 --- a/src/controller/meta_handler.rs +++ b/src/controller/meta_handler.rs @@ -1,4 +1,4 @@ -use std::sync::LazyLock; +use std::{collections::HashMap, sync::LazyLock}; use super::{db_utils::u32_to_ivec, fmt::md2html, Claim, SiteConfig}; use crate::{error::AppError, DB}; @@ -14,6 +14,13 @@ use http::{HeaderName, StatusCode}; use rinja_axum::{into_response, Template}; use tracing::error; +static I18N: LazyLock> = LazyLock::new(|| { + let mut i18n = HashMap::new(); + i18n.insert("sign_in", "Sign in"); + i18n.insert("sign_up", "Sign up"); + i18n +}); + #[derive(Template)] #[template(path = "error.html", escape = "none")] struct PageError<'a> { @@ -176,6 +183,7 @@ pub(super) struct PageData<'a> { pub(super) site_description: String, pub(super) claim: Option, pub(super) has_unread: bool, + pub(super) i18n: HashMap<&'a str, &'a str>, } impl<'a> PageData<'a> { @@ -186,12 +194,14 @@ impl<'a> PageData<'a> { has_unread: bool, ) -> Self { let site_description = md2html(&site_config.description); + let i18n = I18N.clone(); Self { title, site_name: &site_config.site_name, site_description, claim, has_unread, + i18n, } } } diff --git a/src/controller/user.rs b/src/controller/user.rs index 1b91ce83..a27c858b 100644 --- a/src/controller/user.rs +++ b/src/controller/user.rs @@ -36,7 +36,7 @@ use ring::{ use rinja_axum::{into_response, Template}; use serde::Deserialize; use sled::Db; -use std::{cmp::Ordering, fmt::Display, num::NonZeroU32, time::Duration}; +use std::{cmp::Ordering, collections::HashMap, fmt::Display, num::NonZeroU32, time::Duration}; use tokio::time::sleep; /// Page data: `user.html` @@ -913,6 +913,10 @@ pub(crate) async fn signup() -> Result { DB.open_tree("captcha")? .insert(&captcha_id, &*captcha.chars_as_string())?; + let mut i18n = HashMap::new(); + i18n.insert("sign_in", "Sign in"); + i18n.insert("sign_up", "Sign up"); + let page_signup = PageSignup { page_data, captcha_id, diff --git a/templates/signup.html b/templates/signup.html index 066dbd09..f5212843 100644 --- a/templates/signup.html +++ b/templates/signup.html @@ -12,7 +12,7 @@
-

Sign up

+

{{ page_data.i18n.get("sign_up").unwrap() }}