diff --git a/dist/email-templates/manage.htm.hbs b/dist/email-templates/manage.htm.hbs index 27913df..11bd068 100644 --- a/dist/email-templates/manage.htm.hbs +++ b/dist/email-templates/manage.htm.hbs @@ -1,5 +1,5 @@ - + {{ text "Manage your key on {{domain}}" rerender }} @@ -17,7 +17,7 @@

{{uri}}

- {{ text "You can find more info at {{ domain }}/about." rerender }} + {{ text "You can find more info at {{ domain }}/about." rerender }}

{{ text "Greetings from the keys.openpgp.org team" rerender }} diff --git a/dist/email-templates/manage.txt.hbs b/dist/email-templates/manage.txt.hbs index 33f0262..fb43a96 100644 --- a/dist/email-templates/manage.txt.hbs +++ b/dist/email-templates/manage.txt.hbs @@ -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" }} diff --git a/dist/email-templates/verify.htm.hbs b/dist/email-templates/verify.htm.hbs index e59f211..bb6b876 100644 --- a/dist/email-templates/verify.htm.hbs +++ b/dist/email-templates/verify.htm.hbs @@ -1,26 +1,23 @@ - + - Verify {{userid}} for your key on {{domain}} + {{ text "Verify {{userid}} for your key on {{domain}}" rerender }}

- 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 request 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 click the link below: + {{ text "To let others find this key from your email address \"{{userid}}\", please click the link below:" rerender }}

{{uri}}

- You can find more info at {{domain}}/about. + {{ text "You can find more info at {{domain}}/about." rerender }}

- Greetings from the keys.openpgp.org team + {{ text "Greetings from the keys.openpgp.org team" rerender }} diff --git a/dist/email-templates/verify.txt.hbs b/dist/email-templates/verify.txt.hbs index 901a37d..77ee863 100644 --- a/dist/email-templates/verify.txt.hbs +++ b/dist/email-templates/verify.txt.hbs @@ -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" }} diff --git a/dist/email-templates/welcome.htm.hbs b/dist/email-templates/welcome.htm.hbs index 9aa3dc6..c18776d 100644 --- a/dist/email-templates/welcome.htm.hbs +++ b/dist/email-templates/welcome.htm.hbs @@ -1,27 +1,24 @@ - + - Your key upload on {{domain}} + {{ text "Your key upload on {{domain}}" rerender }}

- 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 there, 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 identity information. If you want to allow others to find this key by e-mail address, please follow this link:" }}

{{uri}}

- You can find more info at {{domain}}/about. + {{ text "You can find more info at {{domain}}/about." rerender }}

- Greetings from the keys.openpgp.org team + {{ text "Greetings from the keys.openpgp.org team" rerender }} diff --git a/dist/email-templates/welcome.txt.hbs b/dist/email-templates/welcome.txt.hbs index c9d0ca1..d574a20 100644 --- a/dist/email-templates/welcome.txt.hbs +++ b/dist/email-templates/welcome.txt.hbs @@ -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" }} diff --git a/dist/templates/500.html.hbs b/dist/templates/500.html.hbs index 1078c61..c55f9f1 100644 --- a/dist/templates/500.html.hbs +++ b/dist/templates/500.html.hbs @@ -3,5 +3,5 @@

{{ text "Looks like something went wrong :(" }}

-

{{ text "Error: {{ internal_error }}" }}

+

{{ text "Error message: {{ internal_error }}" rerender }}

{{/layout}} diff --git a/dist/templates/upload/upload-ok.html.hbs b/dist/templates/upload/upload-ok.html.hbs index 511f81f..7ab52b0 100644 --- a/dist/templates/upload/upload-ok.html.hbs +++ b/dist/templates/upload/upload-ok.html.hbs @@ -68,13 +68,11 @@ {{#if count_revoked}} {{#if count_revoked_one}}

- {{ text "This key contains one revoked identity, which is not published." }} - {{ text "(Why?)" }} + {{ text "This key contains one revoked identity, which is not published. (Why?)" rerender }}

{{else}}

- {{ text "This key contains {{ count_revoked }} revoked identities, which are not published." rerender }} - {{ text "(Why?)" }} + {{ text "This key contains {{ count_revoked }} revoked identities, which are not published. (Why?)" rerender }}

{{/if}} {{/if}} diff --git a/src/gettext_strings.rs b/src/gettext_strings.rs index 6f4c50f..fe6edd2 100644 --- a/src/gettext_strings.rs +++ b/src/gettext_strings.rs @@ -53,4 +53,60 @@ fn _dummy() { t!("Note: 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, ."); + + t!("Manage your key on {{domain}}"); + + t!("Hi,"); + t!("this is an automated message from {{ domain }}."); + t!("If you didn't request this message, please ignore it."); + t!("OpenPGP key: {{ primary_fp }}"); + t!("To manage and delete listed addresses on this key, please follow the link below:"); + t!("You can find more info at {{ domain }}/about."); + t!("Greetings from the keys.openpgp.org 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 {{domain}}. If you didn't request this message, please ignore it."); + t!("OpenPGP key: {{primary_fp}}"); + t!("To let others find this key from your email address \"{{userid}}\", please click the link below:"); + t!("You can find more info at {{domain}}/about."); + t!("Greetings from the keys.openpgp.org 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 {{domain}}. If you didn't upload your key 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 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 {{domain}}/about."); + t!("Greetings from the keys.openpgp.org 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"); } diff --git a/src/mail.rs b/src/mail.rs index 40af465..cdfcda7 100644 --- a/src/mail.rs +++ b/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 { 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"); diff --git a/src/main.rs b/src/main.rs index 962ce23..3b7a791 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; diff --git a/src/web/mod.rs b/src/web/mod.rs index 59f3ce1..8214930 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -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)]