i18n on the web
This commit is contained in:
@@ -13,6 +13,10 @@ pub(crate) const SESSION_COOKIE: &str = "analytics_token";
|
||||
/// `ui/base.html` renders `ui/navbar.html` unconditionally.
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct Nav {
|
||||
// Used by templates as they are migrated to Fluent. It is intentionally
|
||||
// present before the first template string is converted.
|
||||
#[allow(dead_code)]
|
||||
pub locale: crate::i18n::Locale,
|
||||
pub authenticated: bool,
|
||||
pub role: String,
|
||||
pub can_admin: bool,
|
||||
@@ -29,6 +33,7 @@ impl Nav {
|
||||
/// entries.
|
||||
pub(crate) fn new(headers: &HeaderMap, active: &'static str) -> Self {
|
||||
Self {
|
||||
locale: crate::i18n::Locale::from_headers(headers),
|
||||
authenticated: crate::cookie_value(headers, SESSION_COOKIE).is_some(),
|
||||
role: String::new(),
|
||||
can_admin: false,
|
||||
@@ -40,6 +45,16 @@ impl Nav {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn language(&self) -> &'static str {
|
||||
self.locale.code()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn tr(&self, key: &str) -> String {
|
||||
self.locale.lookup(key)
|
||||
}
|
||||
|
||||
pub(crate) fn with_authorization(
|
||||
mut self,
|
||||
authorization: &crate::auth::AuthorizationSnapshot,
|
||||
@@ -64,6 +79,7 @@ impl Nav {
|
||||
impl Default for Nav {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
locale: crate::i18n::Locale::default(),
|
||||
authenticated: false,
|
||||
role: String::new(),
|
||||
can_admin: false,
|
||||
|
||||
Reference in New Issue
Block a user