Skip to content

Commit a1dac16

Browse files
authored
feat(i18n): support i18n for predefined templates' body/subject (#62)
1 parent 25ebce7 commit a1dac16

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"is": "^3.2.0",
6666
"lodash": "^4.17.20",
6767
"ms-conf": "^7.0.2",
68-
"ms-mailer-templates": "^1.19.0",
68+
"ms-mailer-templates": "^2.0.0",
6969
"nodemailer": "^6.4.16",
7070
"nodemailer-html-to-text": "^3.1.0",
7171
"nodemailer-mailgun-transport": "^2.0.1",

src/mailer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Mailer extends Microfleet {
6363
const renderedTemplate = is.string(email)
6464
? await Promise.props({
6565
...ctx.nodemailer,
66+
subject: ctx.nodemailer.subject && render.translate(ctx.nodemailer.subject, ctx.template),
6667
html: render(email, ctx.template),
6768
})
6869
: email;

test/suites/ms-mailer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('MS Mailer', function AMQPTransportTestSuite() {
7676
});
7777

7878
it('is able to send email with inlined base64 images', function test() {
79-
return render('cpst-activate', {})
79+
return render('reset', {})
8080
.then(template => Promise.using(smtp.getAMQPConnection(), amqp => amqp
8181
.publishAndWait('mailer.adhoc', {
8282
account: smtp.VALID_PREDEFINED_ACCOUNTS['test-example'],
@@ -96,7 +96,7 @@ describe('MS Mailer', function AMQPTransportTestSuite() {
9696
return Promise.using(smtp.getAMQPConnection(), amqp => amqp
9797
.publishAndWait('mailer.adhoc', {
9898
account: smtp.VALID_PREDEFINED_ACCOUNTS['test-example'],
99-
email: 'cpst-activate',
99+
email: 'reset',
100100
ctx: {
101101
nodemailer: {
102102
to: 'v@makeomatic.ru',
@@ -117,7 +117,7 @@ describe('MS Mailer', function AMQPTransportTestSuite() {
117117
return Promise.using(smtp.getAMQPConnection(), amqp => amqp
118118
.publishAndWait('mailer.predefined', {
119119
account: 'test-example',
120-
email: 'cpst-activate',
120+
email: 'reset',
121121
ctx: {
122122
nodemailer: {
123123
to: 'v+retry@makeomatic.ru',
@@ -138,7 +138,7 @@ describe('MS Mailer', function AMQPTransportTestSuite() {
138138
return Promise.using(smtp.getAMQPConnection(), amqp => amqp
139139
.publishAndWait('mailer.predefined', {
140140
account: 'test-example',
141-
email: 'cpst-activate',
141+
email: 'reset',
142142
ctx: {
143143
nodemailer: {
144144
to: 'v+retry-reject@makeomatic.ru',

yarn.lock

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@
322322
dependencies:
323323
regenerator-runtime "^0.13.4"
324324

325+
"@babel/runtime@^7.12.0":
326+
version "7.13.7"
327+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.13.7.tgz#d494e39d198ee9ca04f4dcb76d25d9d7a1dc961a"
328+
integrity sha512-h+ilqoX998mRVM5FtB5ijRuHUDVt5l3yfoOi2uh18Z/O3hvyaHQ39NpxVkCIG5yFs+mLq/ewFp8Bss6zmWv6ZA==
329+
dependencies:
330+
regenerator-runtime "^0.13.4"
331+
325332
"@babel/runtime@^7.6.3":
326333
version "7.8.4"
327334
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.8.4.tgz#d79f5a2040f7caa24d53e563aad49cbc05581308"
@@ -4123,9 +4130,9 @@ handlebars@^4.4.0:
41234130
uglify-js "^3.1.4"
41244131

41254132
handlebars@^4.7.6:
4126-
version "4.7.6"
4127-
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.6.tgz#d4c05c1baf90e9945f77aa68a7a219aa4a7df74e"
4128-
integrity sha512-1f2BACcBfiwAfStCKZNrUCgqNZkGsAT7UM3kkYtXuLo0KnaVfjKOyf7PRzB6++aK9STyT1Pd2ZCPe3EGOXleXA==
4133+
version "4.7.7"
4134+
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1"
4135+
integrity sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==
41294136
dependencies:
41304137
minimist "^1.2.5"
41314138
neo-async "^2.6.0"
@@ -4381,6 +4388,18 @@ hyperid@^2.0.3:
43814388
uuid "^3.4.0"
43824389
uuid-parse "^1.1.0"
43834390

4391+
i18next-fs-backend@^1.0.8:
4392+
version "1.0.8"
4393+
resolved "https://registry.yarnpkg.com/i18next-fs-backend/-/i18next-fs-backend-1.0.8.tgz#f03d911cac31d76bd6b0aa73fa9c7fc45a199e1d"
4394+
integrity sha512-1TyOJEGBvwqdIu0vZo/pcAxPXe/0vqOX6/hgsgTnNpcGe0PyHJ/87ABDdwdwfKJSxbtM0j6Pue0NKFcx6rOeJg==
4395+
4396+
i18next@^19.8.7:
4397+
version "19.9.0"
4398+
resolved "https://registry.yarnpkg.com/i18next/-/i18next-19.9.0.tgz#0a8cdacac4c8fb384f81f1cfcce823772b37e5d3"
4399+
integrity sha512-5zRG3aFl+e+LsdpVUp0dKkVhYH2iCv+gxyzXP1q2oJUc3BV26fqX87cBE3AHkMOir1X0liOaSoxS/Kg95iEcEQ==
4400+
dependencies:
4401+
"@babel/runtime" "^7.12.0"
4402+
43844403
iconv-lite@0.4.24, iconv-lite@~0.4.13:
43854404
version "0.4.24"
43864405
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
@@ -5886,14 +5905,16 @@ ms-conf@^7.0.2:
58865905
lodash.uniq "^4.5.0"
58875906
nconf "^0.10.0"
58885907

5889-
ms-mailer-templates@^1.19.0:
5890-
version "1.19.2"
5891-
resolved "https://registry.yarnpkg.com/ms-mailer-templates/-/ms-mailer-templates-1.19.2.tgz#56ea88341fca7232e056604aefc954715d5169ff"
5892-
integrity sha512-wEoXuXbhP8nQQIgM3wHX4886rp4q5fv6FToWKDktuPQiDS04HmxG8g8UHdFw86OwA0HKM70SKwKZJdJkYwUQzg==
5908+
ms-mailer-templates@^2.0.0:
5909+
version "2.0.0"
5910+
resolved "https://registry.yarnpkg.com/ms-mailer-templates/-/ms-mailer-templates-2.0.0.tgz#5d5e009df9741ef3fc3088176c0118490db42be1"
5911+
integrity sha512-IXlxSSPYvLgdJqyTe8WecRW+mBw2IE7FS31YHPyz284pBiQvxIlW1vkfYLfNeo/JD9/jD/8+oaxjyekTC8vlEQ==
58935912
dependencies:
58945913
bluebird "^3.7.2"
58955914
common-errors "^1.2.0"
58965915
handlebars "^4.7.6"
5916+
i18next "^19.8.7"
5917+
i18next-fs-backend "^1.0.8"
58975918

58985919
ms@2.0.0:
58995920
version "2.0.0"
@@ -8695,9 +8716,9 @@ typedarray@^0.0.6:
86958716
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
86968717

86978718
uglify-js@^3.1.4:
8698-
version "3.12.1"
8699-
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.12.1.tgz#78307f539f7b9ca5557babb186ea78ad30cc0375"
8700-
integrity sha512-o8lHP20KjIiQe5b/67Rh68xEGRrc2SRsCuuoYclXXoC74AfSRGblU1HKzJWH3HxPZ+Ort85fWHpSX7KwBUC9CQ==
8719+
version "3.12.8"
8720+
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.12.8.tgz#a82e6e53c9be14f7382de3d068ef1e26e7d4aaf8"
8721+
integrity sha512-fvBeuXOsvqjecUtF/l1dwsrrf5y2BCUk9AOJGzGcm6tE7vegku5u/YvqjyDaAGr422PLoLnrxg3EnRvTqsdC1w==
87018722

87028723
uid-number@0.0.6:
87038724
version "0.0.6"

0 commit comments

Comments
 (0)