rust
Elnu 1 year ago
parent 3abc45cd4f
commit 857832e052

@ -8,4 +8,4 @@ pub mod user {
pub const USER_DISCRIMINATOR_COOKIE: &str = "user_discriminator"; pub const USER_DISCRIMINATOR_COOKIE: &str = "user_discriminator";
pub const USER_AVATAR_COOKIE: &str = "user_avatar"; pub const USER_AVATAR_COOKIE: &str = "user_avatar";
} }
pub const LANG_COOKIE: &str = "lang"; pub const LANG_COOKIE: &str = "lang";

@ -56,14 +56,11 @@ pub fn load_catalogs() -> Result<(Catalogs, Vec<LangCode>), LoadCatalogsError> {
} }
let langs = catalogs let langs = catalogs
.iter() .iter()
.map(|(code, catalog)| .map(|(code, catalog)| LangCode {
LangCode { code: code.clone(),
code: code.clone(), name: catalog.gettext("lang").to_owned(),
name: catalog })
.gettext("lang") .collect();
.to_owned(),
}
).collect();
Ok((catalogs, langs)) Ok((catalogs, langs))
} }
@ -108,4 +105,4 @@ pub fn langs_filter(
langs: &Vec<LangCode>, langs: &Vec<LangCode>,
) -> tera::Result<Value> { ) -> tera::Result<Value> {
Ok(serde_json::to_value(langs).unwrap()) Ok(serde_json::to_value(langs).unwrap())
} }

@ -2,7 +2,7 @@
extern crate rocket; extern crate rocket;
use poise::serenity_prelude::Http; use poise::serenity_prelude::Http;
use rocket::{fs::{relative, FileServer}}; use rocket::fs::{relative, FileServer};
use rocket_dyn_templates::{tera, Template}; use rocket_dyn_templates::{tera, Template};
use sass_rocket_fairing::SassFairing; use sass_rocket_fairing::SassFairing;
use std::{collections::HashMap, env}; use std::{collections::HashMap, env};
@ -58,7 +58,7 @@ async fn rocket() -> _ {
"langs", "langs",
move |value: &Value, args: &HashMap<String, Value>| { move |value: &Value, args: &HashMap<String, Value>| {
langs_filter(value, args, &langs) langs_filter(value, args, &langs)
} },
) )
})) }))
.attach(SassFairing::default()) .attach(SassFairing::default())

@ -3,7 +3,12 @@ use std::ops::Deref;
use rocket::{http::CookieJar, State}; use rocket::{http::CookieJar, State};
use rocket_dyn_templates::{context, Template}; use rocket_dyn_templates::{context, Template};
use crate::{models::{Challenge, Settings, User}, cookies::LANG_COOKIE, i18n::DEFAULT as DEFAULT_LANG, utils::AcceptLanguage}; use crate::{
cookies::LANG_COOKIE,
i18n::DEFAULT as DEFAULT_LANG,
models::{Challenge, Settings, User},
utils::AcceptLanguage,
};
#[get("/<challenge>")] #[get("/<challenge>")]
pub async fn get_challenge( pub async fn get_challenge(

@ -27,4 +27,4 @@ macro_rules! header {
header!(Referer, "Referer"); header!(Referer, "Referer");
header!(AcceptLanguage, "Accept-Language", Vec<String>, |header| { header!(AcceptLanguage, "Accept-Language", Vec<String>, |header| {
accept_language::parse(header) accept_language::parse(header)
}); });

Loading…
Cancel
Save