diff --git a/src/server.js b/src/server.js index 940ed15..c26f332 100644 --- a/src/server.js +++ b/src/server.js @@ -12,7 +12,6 @@ const database = require('./database'); const util = require('./util'); const logger = require('./logger'); const config = require('../config.json'); -const defaultLocale = require('../locales/en_US.json'); const { http: { port } } = config; const app = express(); @@ -137,56 +136,6 @@ app.engine('handlebars', handlebars({ neq(value1, value2) { return value1 !== value2; }, - times(n, block) { - let accum = ''; - for(let i = 0; i < n; i++) { - accum += block.fn(i); - } - return accum; - }, - localeHelper(locale, propString, propVar, extra) { - /* - locale: the json locale object - propString: the "path" to the property to get (e.g. "faq.title") - propVar: the dynamic property name to get after the "path" (e.g. localeHelper locale "account.level" would result in ) - e.g. localeHelper locale "account.test" "account.level" would result in locale.account.test[account.level] - */ - - let value = locale; - const props = propString.split('.'); - - if ( typeof propVar === 'string' || propVar instanceof String || - typeof propVar === 'number' || propVar instanceof Number ) { - props.push(propVar); - } - - function getPropFromLocale(value, props) { - for (const p of props) { - value = value[p]; - } - - return value; - } - - // fall back to english if the prop doesn't exist in the current locale - try { - value = getPropFromLocale(value, props); - } catch (e) { - value = defaultLocale; - try { - value = getPropFromLocale(value, props); - } catch (e) { - logger.error(`Could not find locale property ${props.join('.')}`); - } - } - - // TODO: Make this more dynamic - if (extra) { - value = value[extra]; - } - - return value; - }, slug(string) { return string.toLowerCase().replaceAll(/ /g, '-'); } diff --git a/src/util.js b/src/util.js index 6598b31..87149b4 100644 --- a/src/util.js +++ b/src/util.js @@ -6,11 +6,14 @@ const Stripe = require('stripe'); const { marked } = require('marked'); const { REST: DiscordRest } = require('@discordjs/rest'); const { Routes: DiscordRoutes } = require('discord-api-types/v10'); +const merge = require('lodash.merge'); + const mailer = require('./mailer'); const database = require('./database'); const logger = require('./logger'); -const config = require('../config.json'); +const config = require('../config.json'); +const baseLocale = require(`${__dirname}/../locales/en_US.json`); const discordRest = new DiscordRest({ version: '10' }).setToken(config.discord.bot_token); const stripe = new Stripe(config.stripe.secret_key); @@ -23,12 +26,15 @@ function getLocale(language, region) { const path = `${__dirname}/../locales/${language}_${region}.json`; if (fs.pathExistsSync(path)) { - return require(path); + const selectedLocale = require(path); + const finalLocale = merge(baseLocale, selectedLocale); + + return finalLocale; } logger.warn(`Could not find locale ${language}_${region}! Loading en_US`); - return require(`${__dirname}/../locales/en_US.json`); + return baseLocale; } function getRawDocs(locale, subpath, pageName) { diff --git a/views/account/account.handlebars b/views/account/account.handlebars index 2ffe7f6..a0449c6 100644 --- a/views/account/account.handlebars +++ b/views/account/account.handlebars @@ -16,21 +16,21 @@
{{tierName}}
{{else}} {{#if (neq account.access_level -1)}} -{{ localeHelper locale "account.accountLevel" account.access_level }}
+{{ lookup locale.account.accountLevel account.access_level }}
{{else}} -{{ localeHelper locale "account.banned" }}
+{{ locale.account.banned }}
{{/if}} {{/if}} @@ -38,7 +38,7 @@{{ localeHelper locale "account.settings.settingCards.nickname" }}
+{{ locale.account.settings.settingCards.nickname }}
{{account.mii.name}}
{{ localeHelper locale "account.settings.settingCards.birthDate" }}
+{{ locale.account.settings.settingCards.birthDate }}
{{account.birthdate}}
{{ localeHelper locale "account.settings.settingCards.gender" }}
+{{ locale.account.settings.settingCards.gender }}
{{account.gender}}
{{ localeHelper locale "account.settings.settingCards.country" }}
+{{ locale.account.settings.settingCards.country }}
{{account.country}}
{{ localeHelper locale "account.settings.settingCards.timezone" }}
+{{ locale.account.settings.settingCards.timezone }}
{{account.timezone.name}}
{{{ localeHelper locale "account.settings.settingCards.upgradePrompt" }}}
+{{{ locale.account.settings.settingCards.upgradePrompt }}}
{{else}} -{{ localeHelper locale "account.settings.settingCards.hasAccessPrompt" }}
+{{ locale.account.settings.settingCards.hasAccessPrompt }}
{{/unless}}{{ localeHelper locale "account.settings.settingCards.email" }}
+{{ locale.account.settings.settingCards.email }}
{{account.email.address}}
{{ localeHelper locale "account.settings.settingCards.password" }}
+{{ locale.account.settings.settingCards.password }}
●●●●●●●●
{{ localeHelper locale "account.settings.settingCards.passwordResetNotice" }}
+{{ locale.account.settings.settingCards.passwordResetNotice }}
Sign in history not currently tracked. Check back again later
{{ localeHelper locale "account.settings.settingCards.connectedToDiscord" }} {{ discordUser.username }}#{{ discordUser.discriminator }}
+{{ locale.account.settings.settingCards.connectedToDiscord }} {{ discordUser.username }}#{{ discordUser.discriminator }}
- + {{else}} -{{ localeHelper locale "account.settings.settingCards.noDiscordLinked" }} {{ localeHelper locale "account.settings.settingCards.linkDiscord" }}
+{{ locale.account.settings.settingCards.noDiscordLinked }} {{ locale.account.settings.settingCards.linkDiscord }}
{{/if}}Newsletter not currently available. Check back again later
{{ localeHelper locale "upgrade.description" }}
+{{ locale.upgrade.description }}
- {{this.price}} / {{ localeHelper locale "upgrade.month" }} + {{this.price}} / {{ locale.upgrade.month }}
{{/each}}{{{ this.postInfo.caption }}}
{{ localeHelper locale "docs.missingInLocale" }}
+{{ locale.docs.missingInLocale }}
{{/if}} {{{ content }}} diff --git a/views/docs/welcome.handlebars b/views/docs/welcome.handlebars index 5424440..76d7b25 100644 --- a/views/docs/welcome.handlebars +++ b/views/docs/welcome.handlebars @@ -44,7 +44,7 @@