From 5e7cc919c2566be2960293952b94b8649db5171b Mon Sep 17 00:00:00 2001 From: Thomas Lynch Date: Sun, 15 Jan 2023 16:51:15 +1100 Subject: [PATCH] Add __ locale to render lib and gulpfile rendering --- gulpfile.js | 7 +++++-- lib/build/render.js | 3 +++ lib/middleware/locale/locale.js | 10 +++------- views/pages/catalog.pug | 1 - 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 98145cc1..40bd8c8a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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 diff --git a/lib/build/render.js b/lib/build/render.js index 8a2eaa7a..0be0dd80 100644 --- a/lib/build/render.js +++ b/lib/build/render.js @@ -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, diff --git a/lib/middleware/locale/locale.js b/lib/middleware/locale/locale.js index c7335fec..4fd6d54c 100644 --- a/lib/middleware/locale/locale.js +++ b/lib/middleware/locale/locale.js @@ -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(); diff --git a/views/pages/catalog.pug b/views/pages/catalog.pug index 50b799dc..aaf39632 100644 --- a/views/pages/catalog.pug +++ b/views/pages/catalog.pug @@ -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