lint: i18n.js

Partial, still 3 more to do that are slightly higher hanging that can get done.
pull/4842/head
John McLear 2021-02-21 20:06:10 +00:00 committed by Richard Hansen
parent 586af5e16e
commit b1614f0592
1 changed files with 5 additions and 5 deletions

View File

@ -84,18 +84,18 @@ const getAllLocales = () => {
// e.g. { es: {nativeName: "español", direction: "ltr"}, ... } // e.g. { es: {nativeName: "español", direction: "ltr"}, ... }
const getAvailableLangs = (locales) => { const getAvailableLangs = (locales) => {
const result = {}; const result = {};
_.each(_.keys(locales), (langcode) => { for (const langcode of Object.keys(locales)) {
result[langcode] = languages.getLanguageInfo(langcode); result[langcode] = languages.getLanguageInfo(langcode);
}); }
return result; return result;
}; };
// returns locale index that will be served in /locales.json // returns locale index that will be served in /locales.json
const generateLocaleIndex = (locales) => { const generateLocaleIndex = (locales) => {
const result = _.clone(locales); // keep English strings const result = _.clone(locales); // keep English strings
_.each(_.keys(locales), (langcode) => { for (const langcode of Object.keys(locales)) {
if (langcode !== 'en') result[langcode] = `locales/${langcode}.json`; if (langcode !== 'en') result[langcode] = `locales/${langcode}.json`;
}); }
return JSON.stringify(result); return JSON.stringify(result);
}; };
@ -109,7 +109,7 @@ exports.expressCreateServer = (n, args, cb) => {
args.app.get('/locales/:locale', (req, res) => { args.app.get('/locales/:locale', (req, res) => {
// works with /locale/en and /locale/en.json requests // works with /locale/en and /locale/en.json requests
const locale = req.params.locale.split('.')[0]; const locale = req.params.locale.split('.')[0];
if (exports.availableLangs.hasOwnProperty(locale)) { if (Object.prototype.hasOwnProperty.call(exports.availableLangs, locale)) {
res.setHeader('Cache-Control', `public, max-age=${settings.maxAge}`); res.setHeader('Cache-Control', `public, max-age=${settings.maxAge}`);
res.setHeader('Content-Type', 'application/json; charset=utf-8'); res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.send(`{"${locale}":${JSON.stringify(locales[locale])}}`); res.send(`{"${locale}":${JSON.stringify(locales[locale])}}`);