Add __ locale to render lib and gulpfile rendering

indiachan-spamvector
Thomas Lynch 1 year ago
parent 679d095d98
commit 5e7cc919c2
  1. 7
      gulpfile.js
  2. 3
      lib/build/render.js
  3. 10
      lib/middleware/locale/locale.js
  4. 1
      views/pages/catalog.pug

@ -405,7 +405,8 @@ function deletehtml() {
}
async function custompages() {
const formatSize = require(__dirname+'/lib/converter/formatsize.js');
const formatSize = require(__dirname+'/lib/converter/formatsize.js')
, i18n = require(__dirname+'/lib/locale/locale.js');
return gulp.src([
`${paths.pug.src}/custompages/*.pug`,
`${paths.pug.src}/pages/404.pug`,
@ -432,6 +433,7 @@ async function custompages() {
hcaptchaSiteKey: hcaptcha.siteKey,
globalAnnouncement: config.get.globalAnnouncement,
captchaOptions: config.get.captchaOptions,
__: i18n.__,
commit,
version,
}
@ -440,7 +442,8 @@ async function custompages() {
}
async function scripts() {
const { themes, codeThemes } = require(__dirname+'/lib/misc/themes.js');
const { themes, codeThemes } = require(__dirname+'/lib/misc/themes.js')
, i18n = require(__dirname+'/lib/locale/locale.js');
try {
// compile some locals/variables needed from configs in fe scripts

@ -12,6 +12,7 @@ const { outputFile } = require('fs-extra')
, { version } = require(__dirname+'/../../package.json')
, templateDirectory = path.join(__dirname+'/../../views/pages/')
, { Permissions } = require(__dirname+'/../permission/permissions.js')
, i18n = require(__dirname+'/../locale/locale.js')
, config = require(__dirname+'/../../lib/misc/config.js');
let { archiveLinksURL, lockWait, globalLimits, boardDefaults, cacheTemplates,
@ -38,6 +39,7 @@ const updateLocals = () => {
hcaptchaSiteKey: hcaptcha.siteKey,
captchaOptions,
globalAnnouncement,
__: i18n.__,
};
};
@ -49,6 +51,7 @@ module.exports = async (htmlName=null, templateName=null, options=null, json=nul
//generate html if applicable
let html = null;
if (templateName !== null) {
//TODO: setLocale based on board or global locale
html = pug.renderFile(`${templateDirectory}${templateName}`, {
...options,
...renderLocals,

@ -8,16 +8,12 @@ module.exports = (req, res, next) => {
// global settings locale
let { locale } = config.get;
/* TODO
// board settings locale
if (board in res.locals/params) {
locale = board.settings.locale;
if (res.locals.board) {
locale = res.locals.board.settings.locale;
}
*/
//TESTING
const locale = Math.random() < 0.5 ? 'en' : 'pt';
console.log('setting locale', locale);
locale='en'
i18n.setLocale(res.locals, locale);
next();

@ -9,7 +9,6 @@ block head
title /#{board._id}/ - Catalog
block content
h1 locale test: #{__("test")}
+boardheader(modview ? 'Mod Catalog' : 'Catalog')
br
include ../includes/postform.pug

Loading…
Cancel
Save