diff --git a/i18n/en.toml b/i18n/en.toml new file mode 100644 index 00000000..cc6070d0 --- /dev/null +++ b/i18n/en.toml @@ -0,0 +1,3 @@ +sign_in = "Sign In" +sign_out = "Sign Out" +sign_up = "Sign Up" \ No newline at end of file diff --git a/src/controller/meta_handler.rs b/src/controller/meta_handler.rs index 2a7650f0..3dca3bbb 100644 --- a/src/controller/meta_handler.rs +++ b/src/controller/meta_handler.rs @@ -14,10 +14,11 @@ use http::{HeaderName, StatusCode}; use rinja_axum::{into_response, Template}; use tracing::error; -static I18N: LazyLock> = LazyLock::new(|| { +static I18N: LazyLock>> = LazyLock::new(|| { let mut i18n = HashMap::new(); - i18n.insert("sign_in", "Sign in"); - i18n.insert("sign_up", "Sign up"); + let en = include_str!("../../i18n/en.toml"); + let en = basic_toml::from_str::>(en).unwrap(); + i18n.insert("en", en); i18n }); @@ -183,7 +184,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>, + pub(super) i18n: HashMap, } impl<'a> PageData<'a> { @@ -194,7 +195,7 @@ impl<'a> PageData<'a> { has_unread: bool, ) -> Self { let site_description = md2html(&site_config.description); - let i18n = I18N.clone(); + let i18n = I18N.get("en").unwrap().to_owned(); Self { title, site_name: &site_config.site_name, diff --git a/src/controller/user.rs b/src/controller/user.rs index a27c858b..1b91ce83 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, collections::HashMap, fmt::Display, num::NonZeroU32, time::Duration}; +use std::{cmp::Ordering, fmt::Display, num::NonZeroU32, time::Duration}; use tokio::time::sleep; /// Page data: `user.html` @@ -913,10 +913,6 @@ 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,