Added the ability for a user to define and set a custom locale
New environment variable CUSTOM_LOCALE allows a user to define a locale per the /public/locales directory (this should be listed in the docs, will create a pull request for that too). If the environment variable is blank or invalid it reverts to previous behaviour of system + default locale. Fully tested the above as follows: CUSTOM_LOCALE = 'nl' < This works correctly, translating to nl. CUSTOM_LOCALE = 'HelloThere' < This reverts to previous behavior CUSTOM_LOCALE = '' < Also reverts #CUSTOM_LOCALE = < Also reverts
This commit is contained in:
parent
9221b86660
commit
671390ca24
2 changed files with 15 additions and 1 deletions
|
@ -273,6 +273,11 @@ const conf = convict({
|
||||||
default: '#003eaa',
|
default: '#003eaa',
|
||||||
env: 'UI_COLOR_ACCENT'
|
env: 'UI_COLOR_ACCENT'
|
||||||
},
|
},
|
||||||
|
custom_locale: {
|
||||||
|
format: String,
|
||||||
|
default: '',
|
||||||
|
env: 'CUSTOM_LOCALE'
|
||||||
|
},
|
||||||
ui_custom_assets: {
|
ui_custom_assets: {
|
||||||
android_chrome_192px: {
|
android_chrome_192px: {
|
||||||
format: String,
|
format: String,
|
||||||
|
|
|
@ -3,9 +3,18 @@ const layout = require('./layout');
|
||||||
const assets = require('../common/assets');
|
const assets = require('../common/assets');
|
||||||
const getTranslator = require('./locale');
|
const getTranslator = require('./locale');
|
||||||
const { getFxaConfig } = require('./fxa');
|
const { getFxaConfig } = require('./fxa');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = async function(req) {
|
module.exports = async function(req) {
|
||||||
const locale = req.language || 'en-US';
|
const locale = (() => {
|
||||||
|
if (config.custom_locale != '' && fs.existsSync(path.join(__dirname,'../public/locales',config.custom_locale))) {
|
||||||
|
return config.custom_locale;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return req.language || 'en-US';
|
||||||
|
}
|
||||||
|
})();
|
||||||
let authConfig = null;
|
let authConfig = null;
|
||||||
let robots = 'none';
|
let robots = 'none';
|
||||||
if (req.route && req.route.path === '/') {
|
if (req.route && req.route.path === '/') {
|
||||||
|
|
Loading…
Reference in a new issue