find lang
This commit is contained in:
parent
e699d3cbac
commit
ca12c5c467
1 changed files with 24 additions and 2 deletions
|
@ -1,8 +1,10 @@
|
|||
use std::{fs, os::unix::fs::MetadataExt, path::Path};
|
||||
|
||||
use actix_web::{
|
||||
http::header::{self, ContentType, TryIntoHeaderValue},
|
||||
http::StatusCode,
|
||||
http::{
|
||||
header::{self, ContentType, HeaderMap, TryIntoHeaderValue},
|
||||
StatusCode,
|
||||
},
|
||||
HttpRequest, HttpResponse, Responder,
|
||||
};
|
||||
use base64::{engine::general_purpose, Engine};
|
||||
|
@ -116,3 +118,23 @@ fn read_img(data: Vec<u8>, mime: &mime::Mime) -> File {
|
|||
pub fn remove_first_letter(s: &str) -> &str {
|
||||
s.chars().next().map(|c| &s[c.len_utf8()..]).unwrap()
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Lang {
|
||||
French,
|
||||
English,
|
||||
}
|
||||
|
||||
/// Get the browser language
|
||||
pub fn lang(headers: &HeaderMap) -> Lang {
|
||||
headers
|
||||
.get("Accept-Language")
|
||||
.and_then(|lang| lang.to_str().ok())
|
||||
.and_then(|lang| {
|
||||
["fr", "fr-FR"]
|
||||
.into_iter()
|
||||
.any(|i| lang.contains(i))
|
||||
.then_some(Lang::French)
|
||||
})
|
||||
.unwrap_or(Lang::English)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue