Skip to content

Commit

Permalink
fix: autopopulate locals.locale if not set
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Mar 10, 2022
1 parent 0f27e29 commit a4089da
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 191 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
"@babel/preset-env": "^7.16.11",
"@commitlint/cli": "^16.2.1",
"@commitlint/config-conventional": "^16.2.1",
"ava": "^4.0.1",
"ava": "^4.1.0",
"cheerio": "^1.0.0-rc.10",
"codecov": "^3.8.3",
"cross-env": "^7.0.3",
"ejs": "^3.1.6",
"eslint": "^8.9.0",
"eslint": "^8.10.0",
"eslint-config-xo-lass": "^1.0.6",
"eslint-plugin-node": "^11.1.0",
"fixpack": "^4.0.0",
"husky": "^7.0.4",
"lint-staged": "^12.3.4",
"lint-staged": "^12.3.5",
"nodemailer-sendgrid": "^1.0.3",
"nyc": "^15.1.0",
"pug": "^3.0.2",
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,15 @@ class Email {

// support `locals.user.last_locale` (variable based name lastLocaleField)
// (e.g. for <https://lad.js.org>)
const locale = i18n.getLocale();
if (
_.isObject(locals.user) &&
_.isString(locals.user[this.config.lastLocaleField])
)
locals.locale = locals.user[this.config.lastLocaleField];
else if (!_.isString(locals.locale)) locals.locale = locale;

if (_.isString(locals.locale)) i18n.setLocale(locals.locale);
if (locale !== locals.locale) i18n.setLocale(locals.locale);
}

const res = await util.promisify(renderFn)(filePath, locals);
Expand Down
Loading

0 comments on commit a4089da

Please sign in to comment.