You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-07 17:03:01 +03:00
templates: translate a lot more stuff
This commit is contained in:
@@ -109,6 +109,21 @@ pub struct WithLanguage<T> {
|
||||
inner: T,
|
||||
}
|
||||
|
||||
impl<T> WithLanguage<T> {
|
||||
/// Get the language of this context
|
||||
pub fn language(&self) -> &str {
|
||||
&self.lang
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> std::ops::Deref for WithLanguage<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TemplateContext> TemplateContext for WithLanguage<T> {
|
||||
fn sample(now: chrono::DateTime<Utc>, rng: &mut impl Rng) -> Vec<Self>
|
||||
where
|
||||
@@ -984,6 +999,7 @@ pub struct ErrorContext {
|
||||
code: Option<&'static str>,
|
||||
description: Option<String>,
|
||||
details: Option<String>,
|
||||
lang: Option<String>,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ErrorContext {
|
||||
@@ -1047,6 +1063,13 @@ impl ErrorContext {
|
||||
self
|
||||
}
|
||||
|
||||
/// Add the language to the context
|
||||
#[must_use]
|
||||
pub fn with_language(mut self, lang: &DataLocale) -> Self {
|
||||
self.lang = Some(lang.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// Get the error code, if any
|
||||
#[must_use]
|
||||
pub fn code(&self) -> Option<&'static str> {
|
||||
|
@@ -29,7 +29,7 @@ use std::{collections::HashSet, sync::Arc};
|
||||
use anyhow::Context as _;
|
||||
use arc_swap::ArcSwap;
|
||||
use camino::{Utf8Path, Utf8PathBuf};
|
||||
use mas_i18n::{Translator};
|
||||
use mas_i18n::Translator;
|
||||
use mas_router::UrlBuilder;
|
||||
use mas_spa::ViteManifest;
|
||||
use rand::Rng;
|
||||
@@ -346,13 +346,13 @@ register_templates! {
|
||||
pub fn render_error(ErrorContext) { "pages/error.html" }
|
||||
|
||||
/// Render the email verification email (plain text variant)
|
||||
pub fn render_email_verification_txt(EmailVerificationContext) { "emails/verification.txt" }
|
||||
pub fn render_email_verification_txt(WithLanguage<EmailVerificationContext>) { "emails/verification.txt" }
|
||||
|
||||
/// Render the email verification email (HTML text variant)
|
||||
pub fn render_email_verification_html(EmailVerificationContext) { "emails/verification.html" }
|
||||
pub fn render_email_verification_html(WithLanguage<EmailVerificationContext>) { "emails/verification.html" }
|
||||
|
||||
/// Render the email verification subject
|
||||
pub fn render_email_verification_subject(EmailVerificationContext) { "emails/verification.subject" }
|
||||
pub fn render_email_verification_subject(WithLanguage<EmailVerificationContext>) { "emails/verification.subject" }
|
||||
|
||||
/// Render the upstream link mismatch message
|
||||
pub fn render_upstream_oauth2_link_mismatch(WithLanguage<WithCsrf<WithSession<UpstreamExistingLinkContext>>>) { "pages/upstream_oauth2/link_mismatch.html" }
|
||||
|
Reference in New Issue
Block a user