Try getting languages into the frontend (still want a better way to only include single language packs and only a subset of keys)

merge-requests/346/merge
Thomas Lynch 1 year ago
parent a360f09929
commit 5bf792649b
  1. 7
      gulp/res/js/i18n.js
  2. 2
      gulpfile.js
  3. 1
      lib/build/render.js
  4. 4
      lib/build/tasks.js
  5. 3
      locales/en.json
  6. 3
      locales/pt.json
  7. 1
      server.js
  8. 3
      views/includes/head.pug
  9. 2
      views/includes/postform.pug
  10. 4
      views/layout.pug

@ -0,0 +1,7 @@
/* eslint-disable no-unused-vars */
/* globals LANG */
const CURRENTLANG = document.head.dataset.lang;
const __ = (key) => {
//TODO: we'll see if this needs to be more advanced in future
return LANG[CURRENTLANG][key];
};

@ -426,6 +426,7 @@ async function custompages() {
captchaOptions: config.get.captchaOptions,
commit,
version,
language: config.get.language,
__: i18n.__,
};
i18n.setLocale(locals, config.get.language);
@ -497,6 +498,7 @@ const LANG = ${JSON.stringify(i18n.getCatalog())};
gulp.src([
//put scripts in order for dependencies
`${paths.scripts.src}/locals.js`,
`${paths.scripts.src}/i18n.js`,
`${paths.scripts.src}/localstorage.js`,
// `${paths.scripts.src}/pugruntime.js`,
`${paths.scripts.src}/modal.js`,

@ -39,6 +39,7 @@ const updateLocals = () => {
hcaptchaSiteKey: hcaptcha.siteKey,
captchaOptions,
globalAnnouncement,
language,
__: i18n.__,
};
};

@ -60,6 +60,7 @@ module.exports = {
maxThreadMessageLength: bs.maxThreadMessageLength,
maxReplyMessageLength: bs.maxReplyMessageLength,
defaultName: bs.defaultName,
language: bs.language,
};
const { json } = await render(null, null, null, {
'name': `/${options.board._id}/settings.json`,
@ -73,9 +74,10 @@ module.exports = {
buildGlobalSettings: async () => {
const label = '/settings.json';
const start = process.hrtime();
const { captchaOptions: co } = config.get;
const { captchaOptions: co, language } = config.get;
const projectedSettings = {
captchaOptions: {
language: language,
type: co.type,
grid: {
size: co.grid.size,

@ -7,5 +7,6 @@
"Accounts": "Accounts",
"Roles": "Roles",
"News": "News",
"Settings": "Settings"
"Settings": "Settings",
"Name": "Name"
}

@ -7,5 +7,6 @@
"Accounts": "Contas",
"Roles": "Permissões",
"News": "Notícias",
"Settings": "Opções"
"Settings": "Opções",
"Name": "Nome"
}

@ -91,6 +91,7 @@ const config = require(__dirname+'/lib/misc/config.js')
app.locals.hcaptchaSiteKey = hcaptcha.siteKey;
app.locals.globalAnnouncement = globalAnnouncement;
app.locals.captchaOptions = captchaOptions;
app.locals.language = language
app.locals.__ = i18n.__;
i18n.setLocale(app.locals, language);
};

@ -5,9 +5,6 @@ meta(name='viewport' content='width=device-width initial-scale=1')
noscript
style .jsonly { display: none!important; } .user-id { cursor: auto!important; }
//- whether this page is rendered for a board
- const isBoard = board != null;
//- general meta and opengraph meta tags
if isBoard
if board.settings.description

@ -19,7 +19,7 @@ section.form-wrapper.flex-center
include ./subjectfield.pug
else
section.row
.label Name
.label #{__("Name")}
input.mr-1(type='text', name='name', placeholder=board.settings.defaultName maxlength=globalLimits.fieldLength.name)
a.close.postform-style(href='#!') ×
if board.settings.sageOnlyEmail && !modview

@ -1,6 +1,8 @@
doctype html
html
head
//- whether this page is rendered for a board
- const isBoard = board != null;
head(data-lang=(isBoard ? board.settings.language : language))
include includes/head.pug
block head
body#top

Loading…
Cancel
Save