forked from forwardemail/email-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request forwardemail#172 from albertosouza/master
Add suport to sub folders for localization
- Loading branch information
Showing
18 changed files
with
313 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,6 +234,55 @@ Promise.all(templates) | |
}) | ||
``` | ||
#### Localized template | ||
Localized template folder: | ||
``` | ||
templates/ | ||
templates/newsletter/ | ||
// defalt locale templates are stored in root folder and by default is en-us: | ||
templates/newsletter/html.{{ext}} | ||
templates/newsletter/style.{{ext}} | ||
// for add pt-br locale: | ||
templates/newsletter/pt-br/html.{{ext}} | ||
templates/newsletter/pt-br/style.{{ext}} | ||
``` | ||
To render the pt-br localized version for folder structure above, pass locale name in `.render` method | ||
```javascript | ||
var EmailTemplate = require('email-templates').EmailTemplate | ||
var path = require('path') | ||
var templateDir = path.join(__dirname, 'templates', 'newsletter') | ||
var newsletter = new EmailTemplate(templateDir) | ||
var user = {name: 'Joe', pasta: 'spaghetti'} | ||
newsletter.render(user, function (err, result) { | ||
// result.html | ||
// result.text | ||
}) | ||
var async = require('async') | ||
var users = [ | ||
{name: 'John', pasta: 'Rigatoni'}, | ||
{name: 'Luca', pasta: 'Tortellini'} | ||
] | ||
async.each(users, function (user, next) { | ||
// render the pt-br localized template: | ||
newsletter.render(user, 'pt-br' function (err, result) { | ||
if (err) return next(err) | ||
// result.html | ||
// result.text | ||
// result.subject | ||
}) | ||
}, function (err) { | ||
// | ||
}) | ||
``` | ||
### More | ||
Please check the [examples directory](https://github.com/niftylettuce/node-email-templates/tree/master/examples) | ||
|
@@ -246,6 +295,7 @@ Please check the [examples directory](https://github.com/niftylettuce/node-email | |
* Jason Sims <[email protected]> | ||
* Miguel Mota <[email protected]> | ||
* Jeduan Cornejo <[email protected]> | ||
* Alberto Souza <[email protected]> | ||
> Full list of contributors can be found on the [GitHub Contributor Graph][gh-graph] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var path = require('path') | ||
var EmailTemplate = require('../..').EmailTemplate | ||
var _ = require('lodash') | ||
var Handlebars = require('handlebars') | ||
|
||
var templateDir = path.resolve(__dirname, '..', 'templates', 'newsletter-hbs-i18n') | ||
|
||
Handlebars.registerHelper('capitalize', function capitalize (context) { | ||
return context.toUpperCase() | ||
}) | ||
|
||
Handlebars.registerPartial('name', | ||
'{{ capitalize name.first }} {{ capitalize name.last }}' | ||
) | ||
|
||
var template = new EmailTemplate(templateDir) | ||
var locals = { | ||
email: '[email protected]', | ||
name: {first: 'Mamma', last: 'Mia'} | ||
} | ||
|
||
template.render(locals, 'pt-br') | ||
.then(function (results) { | ||
console.log('In pt-br:\n', results) | ||
}) | ||
|
||
template.render(locals) | ||
.then(function (results) { | ||
console.log('In default en-us:\n', results) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hi there {{> name}}</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Oi {{> name}} in pt-br!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@import '../../common'; | ||
|
||
body { | ||
background-color: #ddd; | ||
color: white; | ||
} | ||
|
||
h1 { | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Oi {{> name}} in pt-br!. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@import '../common'; | ||
|
||
body { | ||
background-color: #ddd; | ||
color: white; | ||
} | ||
|
||
h1 { | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hi there {{> name}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hi there <%= name.first %> <%= name.last %></h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Oi <%= name.first %> <%= name.last %></h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@import '../common'; | ||
|
||
body { | ||
background-color: #ddd; | ||
color: white; | ||
} | ||
|
||
h1 { | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Oi <%= name.first %> <%= name.last %>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@import '../common'; | ||
|
||
body { | ||
background-color: #ddd; | ||
color: white; | ||
} | ||
|
||
h1 { | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hi there <%= name.first %> <%= name.last %>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,10 @@ | |
{ | ||
"name": "Jeduan Cornejo", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Alberto Souza", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"keywords": [ | ||
|
@@ -38,6 +42,7 @@ | |
"email-templates", | ||
"juice", | ||
"inline", | ||
"i18n", | ||
"css" | ||
], | ||
"homepage": "https://github.com/niftylettuce/node-email-templates", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.