From 01a34aa2683168bdbb49e0a7fb3150767453e8f9 Mon Sep 17 00:00:00 2001 From: Ash Monty Date: Fri, 12 Aug 2022 21:22:12 +0200 Subject: [PATCH] locales: convert codes to POSIX-style --- locales/{AR_ar.json => ar_AR.json} | 0 locales/{DE_de.json => de_DE.json} | 0 locales/{US_en.json => en_US.json} | 0 locales/{ES_es.json => es_ES.json} | 0 locales/{FR_fr.json => fr_FR.json} | 0 locales/{IT_it.json => it_IT.json} | 0 locales/{JP_ja.json => ja_JP.json} | 0 locales/{KR_ko.json => ko_KR.json} | 0 locales/{NO_nb.json => nb_NO.json} | 0 locales/{NL_nl.json => nl_NL.json} | 0 locales/{PL_pl.json => pl_PL.json} | 0 locales/{BR_pt.json => pt_BR.json} | 0 locales/{RO_ro.json => ro_RO.json} | 0 locales/{RU_ru.json => ru_RU.json} | 0 locales/{TR_tr.json => tr_TR.json} | 0 locales/{CN_zh.json => zh_CN.json} | 0 src/middleware/render-data.js | 4 ++-- src/server.js | 2 +- src/util.js | 8 ++++---- 19 files changed, 7 insertions(+), 7 deletions(-) rename locales/{AR_ar.json => ar_AR.json} (100%) rename locales/{DE_de.json => de_DE.json} (100%) rename locales/{US_en.json => en_US.json} (100%) rename locales/{ES_es.json => es_ES.json} (100%) rename locales/{FR_fr.json => fr_FR.json} (100%) rename locales/{IT_it.json => it_IT.json} (100%) rename locales/{JP_ja.json => ja_JP.json} (100%) rename locales/{KR_ko.json => ko_KR.json} (100%) rename locales/{NO_nb.json => nb_NO.json} (100%) rename locales/{NL_nl.json => nl_NL.json} (100%) rename locales/{PL_pl.json => pl_PL.json} (100%) rename locales/{BR_pt.json => pt_BR.json} (100%) rename locales/{RO_ro.json => ro_RO.json} (100%) rename locales/{RU_ru.json => ru_RU.json} (100%) rename locales/{TR_tr.json => tr_TR.json} (100%) rename locales/{CN_zh.json => zh_CN.json} (100%) diff --git a/locales/AR_ar.json b/locales/ar_AR.json similarity index 100% rename from locales/AR_ar.json rename to locales/ar_AR.json diff --git a/locales/DE_de.json b/locales/de_DE.json similarity index 100% rename from locales/DE_de.json rename to locales/de_DE.json diff --git a/locales/US_en.json b/locales/en_US.json similarity index 100% rename from locales/US_en.json rename to locales/en_US.json diff --git a/locales/ES_es.json b/locales/es_ES.json similarity index 100% rename from locales/ES_es.json rename to locales/es_ES.json diff --git a/locales/FR_fr.json b/locales/fr_FR.json similarity index 100% rename from locales/FR_fr.json rename to locales/fr_FR.json diff --git a/locales/IT_it.json b/locales/it_IT.json similarity index 100% rename from locales/IT_it.json rename to locales/it_IT.json diff --git a/locales/JP_ja.json b/locales/ja_JP.json similarity index 100% rename from locales/JP_ja.json rename to locales/ja_JP.json diff --git a/locales/KR_ko.json b/locales/ko_KR.json similarity index 100% rename from locales/KR_ko.json rename to locales/ko_KR.json diff --git a/locales/NO_nb.json b/locales/nb_NO.json similarity index 100% rename from locales/NO_nb.json rename to locales/nb_NO.json diff --git a/locales/NL_nl.json b/locales/nl_NL.json similarity index 100% rename from locales/NL_nl.json rename to locales/nl_NL.json diff --git a/locales/PL_pl.json b/locales/pl_PL.json similarity index 100% rename from locales/PL_pl.json rename to locales/pl_PL.json diff --git a/locales/BR_pt.json b/locales/pt_BR.json similarity index 100% rename from locales/BR_pt.json rename to locales/pt_BR.json diff --git a/locales/RO_ro.json b/locales/ro_RO.json similarity index 100% rename from locales/RO_ro.json rename to locales/ro_RO.json diff --git a/locales/RU_ru.json b/locales/ru_RU.json similarity index 100% rename from locales/RU_ru.json rename to locales/ru_RU.json diff --git a/locales/TR_tr.json b/locales/tr_TR.json similarity index 100% rename from locales/TR_tr.json rename to locales/tr_TR.json diff --git a/locales/CN_zh.json b/locales/zh_CN.json similarity index 100% rename from locales/CN_zh.json rename to locales/zh_CN.json diff --git a/src/middleware/render-data.js b/src/middleware/render-data.js index f534edb..50f1f97 100644 --- a/src/middleware/render-data.js +++ b/src/middleware/render-data.js @@ -8,7 +8,7 @@ async function renderDataMiddleware(request, response, next) { // Get user local const reqLocale = request.locale; - const locale = util.getLocale(reqLocale.region, reqLocale.language); + const locale = util.getLocale(reqLocale.language, reqLocale.region); response.locals.locale = locale; response.locals.localeString = reqLocale.toString(); @@ -40,4 +40,4 @@ async function renderDataMiddleware(request, response, next) { } } -module.exports = renderDataMiddleware; \ No newline at end of file +module.exports = renderDataMiddleware; diff --git a/src/server.js b/src/server.js index fd2cd7a..2dce61b 100644 --- a/src/server.js +++ b/src/server.js @@ -12,7 +12,7 @@ const database = require('./database'); const util = require('./util'); const logger = require('./logger'); const config = require('../config.json'); -const defaultLocale = require('../locales/US_en.json'); +const defaultLocale = require('../locales/en_US.json'); const { http: { port } } = config; const app = express(); diff --git a/src/util.js b/src/util.js index f7df0d8..90f4c6a 100644 --- a/src/util.js +++ b/src/util.js @@ -13,16 +13,16 @@ function fullUrl(request) { return `${request.protocol}://${request.hostname}${request.originalUrl}`; } -function getLocale(region, language) { - const path = `${__dirname}/../locales/${region}_${language}.json`; +function getLocale(language, region) { + const path = `${__dirname}/../locales/${language}_${region}.json`; if (fs.pathExistsSync(path)) { return require(path); } - logger.warn(`Could not find locale ${region}_${language}! Loading US_en`); + logger.warn(`Could not find locale ${language}_${region}! Loading en_US`); - return require(`${__dirname}/../locales/US_en.json`); + return require(`${__dirname}/../locales/en_US.json`); } function apiGetRequest(path, headers) {