Skip to content

Commit

Permalink
i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub committed Oct 14, 2024
1 parent 1e72548 commit 5ec4900
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
3 changes: 3 additions & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sign_in = "Sign In"
sign_out = "Sign Out"
sign_up = "Sign Up"
11 changes: 6 additions & 5 deletions src/controller/meta_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ use http::{HeaderName, StatusCode};
use rinja_axum::{into_response, Template};
use tracing::error;

static I18N: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
static I18N: LazyLock<HashMap<&str, HashMap<String, String>>> = 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::<HashMap<String, String>>(en).unwrap();
i18n.insert("en", en);
i18n
});

Expand Down Expand Up @@ -183,7 +184,7 @@ pub(super) struct PageData<'a> {
pub(super) site_description: String,
pub(super) claim: Option<Claim>,
pub(super) has_unread: bool,
pub(super) i18n: HashMap<&'a str, &'a str>,
pub(super) i18n: HashMap<String, String>,
}

impl<'a> PageData<'a> {
Expand All @@ -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,
Expand Down
6 changes: 1 addition & 5 deletions src/controller/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -913,10 +913,6 @@ pub(crate) async fn signup() -> Result<impl IntoResponse, AppError> {
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,
Expand Down

0 comments on commit 5ec4900

Please sign in to comment.