Commit 88de0177402d7aacfb3a27acbb67242d60c3cc39
Ensure a locale gets picked
Prevent crash on undefined localecel committed on 1/16/2017, 2:35:00 AM
Parent: da58eab18cff4dbda3c42614aab7bb8cb36cce4f
Files changed
index.js | changed |
index.js | |||
---|---|---|---|
@@ -211,13 +211,12 @@ | |||
211 | 211 … | req._u = url.parse(req.url, true) | |
212 | 212 … | var locale = req._u.query.locale || | |
213 | 213 … | (/locale=([^;]*)/.exec(req.headers.cookie) || [])[1] | |
214 | 214 … | var reqLocales = req.headers['accept-language'] | |
215 | - var locales = String(reqLocales).split(/, */).map(function (item) { | ||
215 … | + var locales = reqLocales ? reqLocales.split(/, */).map(function (item) { | ||
216 | 216 … | return item.split(';')[0] | |
217 | - }) | ||
218 | - if (locales) | ||
219 | - req._locale = locales[0] | ||
217 … | + }) : [] | ||
218 … | + req._locale = locales[0] || locale || this.i18n.fallback | ||
220 | 219 … | ||
221 | 220 … | this.i18n.pickCatalog(reqLocales, locale, function (err, t) { | |
222 | 221 … | if (err) return pull(this.serveError(req, err, 500), serve(req, res)) | |
223 | 222 … | req._t = t |
Built with git-ssb-web