Skip to content
Clone
main
204 lines 7.2 KB Rust
//! Server-side message catalogue.
//!
//! Kept as plain `match` arms rather than a macro: the set is small, the
//! compiler then guarantees every locale is handled, and there is no build step
//! for translators to run. Every function takes the resolved [`UiLocale`], so
//! callers never consult a process-global — one request can send mail to two
//! recipients in two languages.
use crate::locale::UiLocale;
/// Look up a mail subject/heading pair. `purpose` selects the verification-mail
/// wording, matching `EmailVerificationPurpose`'s variants.
pub fn verify_subject(locale: UiLocale, purpose: VerifyPurpose) -> &'static str {
match (locale, purpose) {
(UiLocale::ZhCn, VerifyPurpose::Signup) => "验证你的账号",
(UiLocale::ZhCn, VerifyPurpose::PasswordReset) => "重置你的密码",
(UiLocale::ZhCn, VerifyPurpose::AddEmail) => "添加你的邮箱",
(UiLocale::ZhCn, VerifyPurpose::Reclaim) => "找回你的账号",
(UiLocale::En, VerifyPurpose::Signup) => "Verify your account",
(UiLocale::En, VerifyPurpose::PasswordReset) => "Reset your password",
(UiLocale::En, VerifyPurpose::AddEmail) => "Add your email",
(UiLocale::En, VerifyPurpose::Reclaim) => "Recover your account",
}
}
/// 私信与群组私信:OS 推送标题只说明"是谁给你发了消息",作者名由推送
/// worker 拼在前面;这两类不写站内收件箱,未读由聊天自己的未读计数承担。
pub fn notification_direct_message_title(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "给你发来一条私信",
UiLocale::En => "sent you a direct message",
}
}
pub fn notification_group_dm_title(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "在群组私信中发了一条消息",
UiLocale::En => "sent a message in your group chat",
}
}
pub fn notification_reply_title(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "有人回复了你的消息",
UiLocale::En => "Someone replied to your message",
}
}
/// Mail/notification subjects that mirror the issue and mention notices.
pub fn mention_email_subject(locale: UiLocale, room: &str) -> String {
match locale {
UiLocale::ZhCn => format!("你在 #{room} 中被提及"),
UiLocale::En => format!("You were mentioned in #{room}"),
}
}
pub fn view_channel(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "查看频道",
UiLocale::En => "View channel",
}
}
pub fn view_issue(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "查看工单",
UiLocale::En => "View issue",
}
}
/// HTML result pages served directly by the backend.
pub fn email_verified_title(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "邮箱已验证",
UiLocale::En => "Email verified",
}
}
pub fn email_verified_body(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "你的邮箱已验证,可以继续操作了。",
UiLocale::En => "Your email has been verified. You can now continue.",
}
}
pub fn verification_failed_title(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "验证失败",
UiLocale::En => "Verification failed",
}
}
pub fn verification_failed_body(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "验证链接无效或已过期,请重新发起验证。",
UiLocale::En => "The verification link is invalid or expired. Please start again.",
}
}
pub fn agreement_version(locale: UiLocale, version: &str) -> String {
match locale {
UiLocale::ZhCn => format!("版本 {version}"),
UiLocale::En => format!("Version {version}"),
}
}
pub fn agreement_footer(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "继续使用即表示你同意本文档。",
UiLocale::En => "By continuing you agree to this document.",
}
}
pub fn agreement_not_found_title(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "未找到",
UiLocale::En => "Not found",
}
}
pub fn agreement_not_found_body(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "请求的协议文档不存在。",
UiLocale::En => "The requested agreement document does not exist.",
}
}
/// Language of a verification-code mail, derived from the purpose enum so the
/// mail crate stays independent of the auth crate's types.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VerifyPurpose {
Signup,
PasswordReset,
AddEmail,
Reclaim,
}
pub fn notification_reminder_title(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "消息提醒",
UiLocale::En => "Message reminder",
}
}
pub fn notification_join_request_submitted_title(locale: UiLocale, space: &str) -> String {
match locale {
UiLocale::ZhCn => format!("{space} 有一条新的加入申请"),
UiLocale::En => format!("New join request for {space}"),
}
}
pub fn notification_join_request_approved_title(locale: UiLocale, space: &str) -> String {
match locale {
UiLocale::ZhCn => format!("你加入 {space} 的申请已通过"),
UiLocale::En => format!("Your request to join {space} was approved"),
}
}
pub fn notification_join_request_rejected_title(locale: UiLocale, space: &str) -> String {
match locale {
UiLocale::ZhCn => format!("你加入 {space} 的申请未通过"),
UiLocale::En => format!("Your request to join {space} was declined"),
}
}
pub fn notification_channel_invite_title(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "你被邀请加入一个频道",
UiLocale::En => "You were invited to a channel",
}
}
pub fn notification_mention_message_title(locale: UiLocale) -> &'static str {
match locale {
UiLocale::ZhCn => "消息中提到了你",
UiLocale::En => "You were mentioned in a message",
}
}
/// Resolve the fallback locale from configuration in one place.
pub fn config_fallback(default_locale: &str) -> UiLocale {
UiLocale::parse(default_locale).unwrap_or(UiLocale::En)
}
/// Issue-related mail subjects. The issue number and title are caller data, so
/// these compose rather than look up a static string.
pub fn issue_mention_subject(locale: UiLocale, number: i32, title: &str) -> String {
match locale {
UiLocale::ZhCn => format!("你在工单 #{number} 中被提及:{title}"),
UiLocale::En => format!("You were mentioned in issue #{number}: {title}"),
}
}
pub fn issue_reply_subject(locale: UiLocale, number: i32, title: &str) -> String {
match locale {
UiLocale::ZhCn => format!("工单 #{number} 有新回复:{title}"),
UiLocale::En => format!("New reply on issue #{number}: {title}"),
}
}
pub fn issue_assigned_subject(locale: UiLocale, number: i32, title: &str) -> String {
match locale {
UiLocale::ZhCn => format!("工单 #{number} 指派给你:{title}"),
UiLocale::En => format!("You were assigned to issue #{number}: {title}"),
}
}