#147 move locales out of .env

This commit is contained in:
Avris 2020-12-21 20:59:18 +01:00
parent d30140b2c6
commit 31db6bcb68
4 changed files with 13 additions and 6 deletions

View File

@ -6,7 +6,7 @@ const config = loadSuml('config');
const translations = loadSuml('translations');
const locale = config.locale;
const locales = buildLocaleList();
const locales = buildLocaleList(locale);
const title = translations.title;
const description = translations.description;
const banner = process.env.BASE_URL + '/api/banner/zaimki.png';

View File

@ -24,7 +24,7 @@ app.use(session({
app.use(async function (req, res, next) {
req.config = global.config;
req.locales = buildLocaleList();
req.locales = buildLocaleList(global.config.locale);
req.rawUser = authenticate(req);
req.user = req.rawUser && req.rawUser.authenticated ? req.rawUser : null;
req.admin = req.user && req.user.roles === 'admin';

View File

@ -1,6 +1,7 @@
import md5 from 'js-md5';
import { Base64 } from 'js-base64';
import _ from 'lodash';
import locales from './locales';
export const buildDict = (fn, ...args) => {
const dict = {};
@ -137,11 +138,12 @@ export const isTroll = (body) => {
return ['cipeusz', 'feminazi', 'bruksela', 'zboczeń'].some(t => body.indexOf(t) > -1);
}
export const buildLocaleList = () => {
export const buildLocaleList = (current) => {
return buildDict(function* () {
for (let locale of process.env.LOCALES.split('|')) {
const [code, name, url] = locale.split(',');
yield [code, {name, url}];
for (let [code, name, url, published] of locales) {
if (published || current === code) {
yield [code, {name, url}];
}
}
})
}

5
src/locales.js Normal file
View File

@ -0,0 +1,5 @@
export default [
['es', 'Español', 'https://es.pronouns.page', false],
['en', 'English', 'https://en.pronouns.page', true],
['pl', 'Polski', 'https://zaimki.pl', true],
];