Procházet zdrojové kódy

i18n-ize meteor email templates

floatinghotpot před 9 roky
rodič
revize
892d1a2d45
3 změnil soubory, kde provedl 23 přidání a 0 odebrání
  1. 7 0
      config/accounts.js
  2. 6 0
      i18n/en.i18n.json
  3. 10 0
      models/users.js

+ 7 - 0
config/accounts.js

@@ -51,4 +51,11 @@ if (Meteor.isServer) {
   if (process.env.MAIL_FROM) {
     Accounts.emailTemplates.from = process.env.MAIL_FROM;
   }
+
+  ['resetPassword-subject', 'resetPassword-text', 'verifyEmail-subject', 'verifyEmail-text', 'enrollAccount-subject', 'enrollAccount-text'].forEach((str) => {
+    const words = str.split('-');
+    Accounts.emailTemplates[words[0]][words[1]] = (user, url) => {
+      return TAPi18n.__(`email-${str}`, { user: user.getName(), url }, user.getLanguage());
+    };
+  });
 }

+ 6 - 0
i18n/en.i18n.json

@@ -124,6 +124,12 @@
     "editLabelPopup-title": "Change Label",
     "editProfilePopup-title": "Edit Profile",
     "email": "Email",
+    "email-enrollAccount-subject": "An account created for you on __url__",
+    "email-enrollAccount-text": "Hello __user__,\n\nTo start using the service, simply click the link below.\n\n__url__\n\nThanks.\n",
+    "email-resetPassword-subject": "Reset your password on __url__",
+    "email-resetPassword-text": "Hello __user__,\n\nTo reset your password, simply click the link below.\n\n__url__\n\nThanks.\n",
+    "email-verifyEmail-subject": "Verify your email address on __url__",
+    "email-verifyEmail-text": "Hello __user__,\n\nTo verify your account email, simply click the link below.\n\n__url__\n\nThanks.\n",
     "error-board-notAMember": "You need to be a member of this board to do that",
     "error-json-malformed": "Your text is not valid JSON",
     "error-json-schema": "Your JSON data does not include the proper information in the correct format",

+ 10 - 0
models/users.js

@@ -68,6 +68,16 @@ Users.helpers({
       return this.username[0].toUpperCase();
     }
   },
+
+  getName() {
+    const profile = this.profile || {};
+    return profile.fullname || this.username;
+  },
+
+  getLanguage() {
+    const profile = this.profile || {};
+    return profile.language || 'en';
+  },
 });
 
 Users.mutations({