i18n: prepare mail templates for localization, too
This commit is contained in:
parent
0fced131c5
commit
c36161650b
|
@ -1,5 +1,5 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="{{lang}}">
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>{{ text "Manage your key on {{domain}}" rerender }}</title>
|
||||
|
@ -17,7 +17,7 @@
|
|||
<p>
|
||||
<a href="{{uri}}">{{uri}}</a>
|
||||
<p>
|
||||
{{ text "You can find more info at <a href="{{ base_uri }}/about">{{ domain }}/about</a>." rerender }}
|
||||
{{ text "You can find more info at <a href=\"{{ base_uri }}/about\">{{ domain }}/about</a>." rerender }}
|
||||
<p>
|
||||
{{ text "Greetings from the <a rel=\"nofollow\" href=\"{{ base_uri }}\" style=\"text-decoration:none; color: #333\"><tt>keys.openpgp.org</tt></a> team" rerender }}
|
||||
</body>
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
{{ text "Hi," }}
|
||||
|
||||
{{ text "this is an automated message from {{domain}}. If you didn't" rerender }}
|
||||
{{ text "request this message, please ignore it." }}
|
||||
{{ text "this is an automated message from {{domain}}. If you didn't\nrequest this message, please ignore it." rerender }}
|
||||
|
||||
{{ text "OpenPGP key: {{ primary_fp }}" rerender }}
|
||||
{{ text "OpenPGP key: {{primary_fp}}" rerender }}
|
||||
|
||||
{{ text "To manage and delete listed addresses on this key, please follow" }}
|
||||
{{ text "the link below:" }}
|
||||
{{ text "To manage and delete listed addresses on this key, please follow\nthe link below:" }}
|
||||
|
||||
{{ uri }}
|
||||
|
||||
{{ text "You can find more info at {{ base_uri }}/about" }}
|
||||
{{ text "You can find more info at {{base_uri}}/about" rerender }}
|
||||
|
||||
{{ text "Greetings from the keys.openpgp.org team" }}
|
||||
|
||||
|
|
|
@ -1,26 +1,23 @@
|
|||
<!doctype html>
|
||||
<html lang=en>
|
||||
<html lang="{{lang}}">
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>Verify {{userid}} for your key on {{domain}}</title>
|
||||
<title>{{ text "Verify {{userid}} for your key on {{domain}}" rerender }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Hi,
|
||||
{{ text "Hi," }}
|
||||
<p>
|
||||
this is an automated message from <a rel="nofollow" href="{{base_uri}}" style="text-decoration:none; color: #333"><tt>{{domain}}</tt></a>. If you didn't
|
||||
request this message, please ignore it.
|
||||
{{ text "this is an automated message from <a rel=\"nofollow\" href=\"{{base_uri}}\" style=\"text-decoration:none; color: #333\"><tt>{{domain}}</tt></a>. If you didn't request this message, please ignore it." rerender }}
|
||||
<p>
|
||||
OpenPGP key: <tt>{{primary_fp}}</tt>
|
||||
{{ text "OpenPGP key: <tt>{{primary_fp}}</tt>" rerender }}
|
||||
<p>
|
||||
To let others find this key from your email address
|
||||
"<a rel="nofollow" href="#" style="text-decoration:none; color: #333">{{userid}}</a>",
|
||||
please click the link below:
|
||||
{{ text "To let others find this key from your email address \"<a rel=\"nofollow\" href=\"#\" style=\"text-decoration:none; color: #333\">{{userid}}</a>\", please click the link below:" rerender }}
|
||||
<p>
|
||||
<a href="{{uri}}">{{uri}}</a>
|
||||
<p>
|
||||
You can find more info at <a href="{{base_uri}}/about">{{domain}}/about</a>.
|
||||
{{ text "You can find more info at <a href=\"{{base_uri}}/about\">{{domain}}/about</a>." rerender }}
|
||||
<p>
|
||||
Greetings from the <a rel="nofollow" href="{{base_uri}}" style="text-decoration:none; color: #333"><tt>keys.openpgp.org</tt></a> team
|
||||
{{ text "Greetings from the <a rel=\"nofollow\" href=\"{{base_uri}}\" style=\"text-decoration:none; color: #333\"><tt>keys.openpgp.org</tt></a> team" rerender }}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
Hi,
|
||||
{{ text "Hi," }}
|
||||
|
||||
this is an automated message from {{domain}}. If you didn't
|
||||
request this message, please ignore it.
|
||||
{{ text "this is an automated message from {{domain}}. If you didn't\nrequest this message, please ignore it." rerender }}
|
||||
|
||||
OpenPGP key: {{primary_fp}}
|
||||
{{ text "OpenPGP key: {{primary_fp}}" rerender }}
|
||||
|
||||
To let others find this key from your email address "{{userid}}",
|
||||
please follow the link below:
|
||||
{{ text "To let others find this key from your email address \"{{userid}}\",\nplease follow the link below:" rerender }}
|
||||
|
||||
{{uri}}
|
||||
|
||||
You can find more info at {{base_uri}}/about
|
||||
{{ text "You can find more info at {{base_uri}}/about" rerender }}
|
||||
|
||||
Greetings from the keys.openpgp.org team
|
||||
{{ text "Greetings from the keys.openpgp.org team" }}
|
||||
|
|
|
@ -1,27 +1,24 @@
|
|||
<!doctype html>
|
||||
<html lang=en>
|
||||
<html lang="{{lang}}">
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>Your key upload on {{domain}}</title>
|
||||
<title>{{ text "Your key upload on {{domain}}" rerender }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Hi,
|
||||
{{ text "Hi," }}
|
||||
<p>
|
||||
this is an automated message from <a rel="nofollow" href="{{base_uri}}" style="text-decoration:none; color: #333"><tt>{{domain}}</tt></a>. If you didn't
|
||||
upload your key there, please ignore this message.
|
||||
{{ text "this is an automated message from <a rel=\"nofollow\" href=\"{{base_uri}}\" style=\"text-decoration:none; color: #333\"><tt>{{domain}}</tt></a>. If you didn't upload your key there, please ignore this message." rerender }}
|
||||
<p>
|
||||
OpenPGP key: <tt>{{primary_fp}}</tt>
|
||||
{{ text "OpenPGP key: <tt>{{primary_fp}}</tt>" rerender }}
|
||||
<p>
|
||||
This key was just uploaded for the first time, and is now published without
|
||||
identity information. If you want to allow others to find this key by e-mail
|
||||
address, please follow this link:
|
||||
{{ text "This key was just uploaded for the first time, and is now published without identity information. If you want to allow others to find this key by e-mail address, please follow this link:" }}
|
||||
<p>
|
||||
<a href="{{uri}}">{{uri}}</a>
|
||||
<p>
|
||||
You can find more info at <a href="{{base_uri}}/about">{{domain}}/about</a>.
|
||||
{{ text "You can find more info at <a href=\"{{base_uri}}/about\">{{domain}}/about</a>." rerender }}
|
||||
<p>
|
||||
Greetings from the <a rel="nofollow" href="{{base_uri}}" style="text-decoration:none; color: #333"><tt>keys.openpgp.org</tt></a> team
|
||||
{{ text "Greetings from the <a rel=\"nofollow\" href=\"{{base_uri}}\" style=\"text-decoration:none; color: #333\"><tt>keys.openpgp.org</tt></a> team" rerender }}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
Hi,
|
||||
{{ text "Hi," }}
|
||||
|
||||
this is an automated message from {{domain}}. If you didn't upload your key
|
||||
there, please ignore this message.
|
||||
{{ text "this is an automated message from {{domain}}. If you didn't upload your key\nthere, please ignore this message." rerender }}
|
||||
|
||||
OpenPGP key: {{primary_fp}}
|
||||
{{ text "OpenPGP key: {{primary_fp}}" rerender }}
|
||||
|
||||
This key was just uploaded for the first time, and is now published without
|
||||
identity information. If you want to allow others to find this key by e-mail
|
||||
address, please follow this link:
|
||||
{{ text "This key was just uploaded for the first time, and is now published without\nidentity information. If you want to allow others to find this key by e-mail\naddress, please follow this link:" }}
|
||||
|
||||
{{uri}}
|
||||
|
||||
You can find more info at {{base_uri}}/about
|
||||
{{ text "You can find more info at {{base_uri}}/about" rerender }}
|
||||
|
||||
Greetings from the keys.openpgp.org team
|
||||
{{ text "Greetings from the keys.openpgp.org team" }}
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
|
||||
<p>{{ text "Looks like something went wrong :(" }}</p>
|
||||
|
||||
<p>{{ text "<strong>Error:</strong> {{ internal_error }}" }}</p>
|
||||
<p>{{ text "Error message: {{ internal_error }}" rerender }}</p>
|
||||
{{/layout}}
|
||||
|
|
|
@ -68,13 +68,11 @@
|
|||
{{#if count_revoked}}
|
||||
{{#if count_revoked_one}}
|
||||
<p style="padding-top: 1em;">
|
||||
{{ text "This key contains one revoked identity, which is not published." }}
|
||||
{{ text "(<a href=\"/about/faq#revoked-uids\" target=\"_blank\">Why?</a>)" }}
|
||||
{{ text "This key contains one revoked identity, which is not published. (<a href=\"/about/faq#revoked-uids\" target=\"_blank\">Why?</a>)" rerender }}
|
||||
</p>
|
||||
{{else}}
|
||||
<p style="padding-top: 1em;">
|
||||
{{ text "This key contains {{ count_revoked }} revoked identities, which are not published." rerender }}
|
||||
{{ text "(<a href=\"/about/faq#revoked-uids\" target=\"_blank\">Why?</a>)" }}
|
||||
{{ text "This key contains {{ count_revoked }} revoked identities, which are not published. (<a href=\"/about/faq#revoked-uids\" target=\"_blank\">Why?</a>)" rerender }}
|
||||
</p>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
|
|
@ -53,4 +53,60 @@ fn _dummy() {
|
|||
t!("<strong>Note:</strong> To make keys searchable by address, you must upload them individually.");
|
||||
t!("Verifying your email address…");
|
||||
t!("If the process doesn't complete after a few seconds, <input type=\"submit\" class=\"textbutton\" value=\"click here\" />.");
|
||||
|
||||
t!("Manage your key on {{domain}}");
|
||||
|
||||
t!("Hi,");
|
||||
t!("this is an automated message from <a rel=\"nofollow\" href=\"{{ base_uri }}\" style=\"text-decoration:none; color: #333\"><tt>{{ domain }}</tt></a>.");
|
||||
t!("If you didn't request this message, please ignore it.");
|
||||
t!("OpenPGP key: <tt>{{ primary_fp }}</tt>");
|
||||
t!("To manage and delete listed addresses on this key, please follow the link below:");
|
||||
t!("You can find more info at <a href=\"{{ base_uri }}/about\">{{ domain }}/about</a>.");
|
||||
t!("Greetings from the <a rel=\"nofollow\" href=\"{{ base_uri }}\" style=\"text-decoration:none; color: #333\"><tt>keys.openpgp.org</tt></a> team");
|
||||
|
||||
t!("Hi,");
|
||||
t!("this is an automated message from {{domain}}. If you didn't");
|
||||
t!("request this message, please ignore it.");
|
||||
t!("OpenPGP key: {{primary_fp}}");
|
||||
t!("To manage and delete listed addresses on this key, please follow");
|
||||
t!("the link below:");
|
||||
t!("You can find more info at {{base_uri}}/about");
|
||||
t!("Greetings from the keys.openpgp.org team");
|
||||
|
||||
t!("Verify {{userid}} for your key on {{domain}}");
|
||||
|
||||
t!("Hi,");
|
||||
t!("this is an automated message from <a rel=\"nofollow\" href=\"{{base_uri}}\" style=\"text-decoration:none; color: #333\"><tt>{{domain}}</tt></a>. If you didn't request this message, please ignore it.");
|
||||
t!("OpenPGP key: <tt>{{primary_fp}}</tt>");
|
||||
t!("To let others find this key from your email address \"<a rel=\"nofollow\" href=\"#\" style=\"text-decoration:none; color: #333\">{{userid}}</a>\", please click the link below:");
|
||||
t!("You can find more info at <a href=\"{{base_uri}}/about\">{{domain}}/about</a>.");
|
||||
t!("Greetings from the <a rel=\"nofollow\" href=\"{{base_uri}}\" style=\"text-decoration:none; color: #333\"><tt>keys.openpgp.org</tt></a> team");
|
||||
|
||||
t!("Hi,");
|
||||
t!("this is an automated message from {{domain}}. If you didn't");
|
||||
t!("request this message, please ignore it.");
|
||||
t!("OpenPGP key: {{primary_fp}}");
|
||||
t!("To let others find this key from your email address \"{{userid}}\",");
|
||||
t!("please follow the link below:");
|
||||
t!("You can find more info at {{base_uri}}/about");
|
||||
t!("Greetings from the keys.openpgp.org team");
|
||||
|
||||
t!("Your key upload on {{domain}}");
|
||||
|
||||
t!("Hi,");
|
||||
t!("this is an automated message from <a rel=\"nofollow\" href=\"{{base_uri}}\" style=\"text-decoration:none; color: #333\"><tt>{{domain}}</tt></a>. If you didn't upload your key there, please ignore this message.");
|
||||
t!("OpenPGP key: <tt>{{primary_fp}}</tt>");
|
||||
t!("This key was just uploaded for the first time, and is now published without identity information. If you want to allow others to find this key by e-mail address, please follow this link:");
|
||||
t!("You can find more info at <a href=\"{{base_uri}}/about\">{{domain}}/about</a>.");
|
||||
t!("Greetings from the <a rel=\"nofollow\" href=\"{{base_uri}}\" style=\"text-decoration:none; color: #333\"><tt>keys.openpgp.org</tt></a> team");
|
||||
|
||||
t!("Hi,");
|
||||
t!("this is an automated message from {{domain}}. If you didn't upload your key");
|
||||
t!("there, please ignore this message.");
|
||||
t!("OpenPGP key: {{primary_fp}}");
|
||||
t!("This key was just uploaded for the first time, and is now published without");
|
||||
t!("identity information. If you want to allow others to find this key by e-mail");
|
||||
t!("address, please follow this link:");
|
||||
t!("You can find more info at {{base_uri}}/about");
|
||||
t!("Greetings from the keys.openpgp.org team");
|
||||
}
|
||||
|
|
20
src/mail.rs
20
src/mail.rs
|
@ -10,14 +10,18 @@ use uuid::Uuid;
|
|||
use crate::counters;
|
||||
|
||||
use rocket_i18n::I18n;
|
||||
use gettext_macros::include_i18n;
|
||||
use gettext_macros::i18n;
|
||||
|
||||
use crate::i18n::I18NHelper;
|
||||
|
||||
use crate::database::types::Email;
|
||||
use crate::Result;
|
||||
|
||||
mod context {
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct Verification {
|
||||
pub lang: String,
|
||||
pub primary_fp: String,
|
||||
pub uri: String,
|
||||
pub userid: String,
|
||||
|
@ -27,6 +31,7 @@ mod context {
|
|||
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct Manage {
|
||||
pub lang: String,
|
||||
pub primary_fp: String,
|
||||
pub uri: String,
|
||||
pub base_uri: String,
|
||||
|
@ -35,6 +40,7 @@ mod context {
|
|||
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct Welcome {
|
||||
pub lang: String,
|
||||
pub primary_fp: String,
|
||||
pub uri: String,
|
||||
pub base_uri: String,
|
||||
|
@ -84,6 +90,7 @@ impl Service {
|
|||
token: &str
|
||||
) -> Result<()> {
|
||||
let ctx = context::Verification {
|
||||
lang: i18n.lang.to_string(),
|
||||
primary_fp: tpk_name,
|
||||
uri: format!("{}/verify/{}", base_uri, token),
|
||||
userid: userid.to_string(),
|
||||
|
@ -111,6 +118,7 @@ impl Service {
|
|||
link_path: &str,
|
||||
) -> Result<()> {
|
||||
let ctx = context::Manage {
|
||||
lang: i18n.lang.to_string(),
|
||||
primary_fp: tpk_name,
|
||||
uri: format!("{}{}", base_uri, link_path),
|
||||
base_uri: base_uri.to_owned(),
|
||||
|
@ -137,6 +145,7 @@ impl Service {
|
|||
token: &str
|
||||
) -> Result<()> {
|
||||
let ctx = context::Welcome {
|
||||
lang: i18n.lang.to_string(),
|
||||
primary_fp: tpk_name,
|
||||
uri: format!("{}/upload/{}", base_uri, token),
|
||||
base_uri: base_uri.to_owned(),
|
||||
|
@ -154,7 +163,12 @@ impl Service {
|
|||
)
|
||||
}
|
||||
|
||||
fn render_template(&self, template: &str, locale: &str, ctx: impl Serialize + Clone) -> Result<(String, String)> {
|
||||
fn render_template(
|
||||
&self,
|
||||
template: &str,
|
||||
locale: &str,
|
||||
ctx: impl Serialize + Clone
|
||||
) -> Result<(String, String)> {
|
||||
let html = self.templates.render(&format!("{}/{}.htm", locale, template), &ctx)
|
||||
.or_else(|_| self.templates.render(&format!("{}.htm", template), &ctx))
|
||||
.map_err(|_| failure::err_msg("Email template failed to render"))?;
|
||||
|
@ -210,6 +224,10 @@ impl Service {
|
|||
fn load_handlebars(template_dir: PathBuf) -> Result<Handlebars> {
|
||||
let mut handlebars = Handlebars::new();
|
||||
|
||||
let i18ns = include_i18n!();
|
||||
let i18n_helper = I18NHelper::new(i18ns);
|
||||
handlebars.register_helper("text", Box::new(i18n_helper));
|
||||
|
||||
let mut glob_path = template_dir.join("**").join("*");
|
||||
glob_path.set_extension("hbs");
|
||||
let glob_path = glob_path.to_str().expect("valid glob path string");
|
||||
|
|
|
@ -42,7 +42,7 @@ extern crate hagrid_database as database;
|
|||
|
||||
use gettext_macros::init_i18n;
|
||||
|
||||
init_i18n!("hagrid", en, de);
|
||||
init_i18n!("hagrid", en);
|
||||
|
||||
mod mail;
|
||||
mod anonymize_utils;
|
||||
|
|
|
@ -134,6 +134,7 @@ impl MyResponse {
|
|||
internal_error: e.to_string(),
|
||||
version: env!("VERGEN_SEMVER").to_string(),
|
||||
commit: env!("VERGEN_SHA_SHORT").to_string(),
|
||||
lang: "en".to_string(),
|
||||
};
|
||||
MyResponse::ServerError(Template::render("500", ctx))
|
||||
}
|
||||
|
@ -171,6 +172,7 @@ mod templates {
|
|||
pub internal_error: String,
|
||||
pub commit: String,
|
||||
pub version: String,
|
||||
pub lang: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
|
Loading…
Reference in New Issue