Change setting locale in render locals in build locals, remove test header

merge-requests/341/head
Thomas Lynch 1 year ago
parent 5e3b935664
commit 224b141920
  1. 49
      gulpfile.js
  2. 16
      lib/build/render.js
  3. 1
      locales/en.json
  4. 3
      locales/pt.json
  5. 3
      server.js
  6. 3
      views/includes/head.pug
  7. 1
      views/layout.pug

@ -406,7 +406,29 @@ function deletehtml() {
async function custompages() {
const formatSize = require(__dirname+'/lib/converter/formatsize.js')
, i18n = require(__dirname+'/lib/locale/locale.js');
, i18n = require(__dirname+'/lib/locale/locale.js')
, locals = {
Permissions,
early404Fraction: config.get.early404Fraction,
early404Replies: config.get.early404Replies,
meta: config.get.meta,
archiveLinksURL: config.get.archiveLinksURL,
reverseImageLinksURL: config.get.reverseImageLinksURL,
enableWebring: config.get.enableWebring,
globalLimits: config.get.globalLimits,
codeLanguages: config.get.highlightOptions.languageSubset,
defaultTheme: config.get.boardDefaults.theme,
defaultCodeTheme: config.get.boardDefaults.codeTheme,
postFilesSize: formatSize(config.get.globalLimits.postFilesSize.max),
googleRecaptchaSiteKey: google.siteKey,
hcaptchaSiteKey: hcaptcha.siteKey,
globalAnnouncement: config.get.globalAnnouncement,
captchaOptions: config.get.captchaOptions,
commit,
version,
__: i18n.__,
};
i18n.setLocale(locals, config.get.language);
return gulp.src([
`${paths.pug.src}/custompages/*.pug`,
`${paths.pug.src}/pages/404.pug`,
@ -415,29 +437,7 @@ async function custompages() {
`${paths.pug.src}/pages/503.pug`,
`${paths.pug.src}/pages/504.pug`
])
.pipe(gulppug({
locals: {
Permissions,
early404Fraction: config.get.early404Fraction,
early404Replies: config.get.early404Replies,
meta: config.get.meta,
archiveLinksURL: config.get.archiveLinksURL,
reverseImageLinksURL: config.get.reverseImageLinksURL,
enableWebring: config.get.enableWebring,
globalLimits: config.get.globalLimits,
codeLanguages: config.get.highlightOptions.languageSubset,
defaultTheme: config.get.boardDefaults.theme,
defaultCodeTheme: config.get.boardDefaults.codeTheme,
postFilesSize: formatSize(config.get.globalLimits.postFilesSize.max),
googleRecaptchaSiteKey: google.siteKey,
hcaptchaSiteKey: hcaptcha.siteKey,
globalAnnouncement: config.get.globalAnnouncement,
captchaOptions: config.get.captchaOptions,
__: i18n.__,
commit,
version,
}
}))
.pipe(gulppug({ locals }))
.pipe(gulp.dest(paths.pug.dest));
}
@ -462,6 +462,7 @@ const captchaOptions = ${JSON.stringify(reducedCaptchaOptions)};
const SERVER_TIMEZONE = '${Intl.DateTimeFormat().resolvedOptions().timeZone}';
const settings = ${JSON.stringify(config.get.frontendScriptDefault)};
const extraLocals = ${JSON.stringify({ meta: config.get.meta, reverseImageLinksURL: config.get.reverseImageLinksURL })};
const LANG = ${JSON.stringify(i18n.getCatalog())};
`;
fs.writeFileSync('gulp/res/js/locals.js', locals);

@ -15,12 +15,12 @@ const { outputFile } = require('fs-extra')
, i18n = require(__dirname+'/../locale/locale.js')
, config = require(__dirname+'/../../lib/misc/config.js');
let { archiveLinksURL, lockWait, globalLimits, boardDefaults, cacheTemplates,
let { language, archiveLinksURL, lockWait, globalLimits, boardDefaults, cacheTemplates,
reverseImageLinksURL, meta, enableWebring, captchaOptions, globalAnnouncement } = config.get
, renderLocals = null;
const updateLocals = () => {
({ archiveLinksURL, lockWait, globalLimits, boardDefaults, cacheTemplates,
({ language, archiveLinksURL, lockWait, globalLimits, boardDefaults, cacheTemplates,
reverseImageLinksURL, meta, enableWebring, captchaOptions, globalAnnouncement } = config.get);
renderLocals = {
Permissions,
@ -51,11 +51,17 @@ 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}`, {
const mergedLocals = {
...options,
...renderLocals,
});
};
//NOTE: will this cause issues with global locale?
if (options.board && options.board.settings) {
i18n.setLocale(mergedLocals, options.board.settings.language);
} else {
i18n.setLocale(renderLocals, language);
}
html = pug.renderFile(`${templateDirectory}${templateName}`, mergedLocals);
}
//lock to prevent concurrent disk write

@ -1,5 +1,4 @@
{
"test": "test",
"Recent": "Recent",
"Reports": "Reports",
"Bans": "Bans",

@ -1,5 +1,4 @@
{
"test": "test",
"Recent": "Recentes",
"Reports": "Denúncias",
"Bans": "Bans",
@ -8,5 +7,5 @@
"Accounts": "Contas",
"Roles": "Permissões",
"News": "Notícias",
"Settings": "Settings"
"Settings": "Opções"
}

@ -70,7 +70,7 @@ const config = require(__dirname+'/lib/misc/config.js')
app.set('views', views);
const loadAppLocals = () => {
const { cacheTemplates, boardDefaults, globalLimits, captchaOptions, archiveLinksURL,
const { language, cacheTemplates, boardDefaults, globalLimits, captchaOptions, archiveLinksURL,
reverseImageLinksURL, meta, enableWebring, globalAnnouncement } = config.get;
//cache loaded templates
app.cache = {};
@ -92,6 +92,7 @@ const config = require(__dirname+'/lib/misc/config.js')
app.locals.globalAnnouncement = globalAnnouncement;
app.locals.captchaOptions = captchaOptions;
app.locals.__ = i18n.__;
i18n.setLocale(app.locals, language);
};
loadAppLocals();
redis.addCallback('config', loadAppLocals);

@ -31,6 +31,9 @@ if isBoard && board.settings.customCss
//- include html_code from gulp-favicon
include ../../gulp/res/icons/html_code.html
//- language pack
//- TODO?
//- main script
script(src=`/js/all.js?v=${commit}&ct=${captchaOptions.type}`)

@ -7,7 +7,6 @@ html
include includes/navbar.pug
main(class=(minimal?'minimal':''))
.container
h1 #{__("test")}
block content
include includes/footer.pug

Loading…
Cancel
Save