From 0d943d128431f166045de53bd64575dac142d320 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Mon, 26 Apr 2021 00:18:08 +0200 Subject: Extract list of supported languages in separate file Signed-off-by: Erik Michelson --- app.js | 5 +++-- locales/_supported.json | 38 ++++++++++++++++++++++++++++++++++++++ public/js/locale.js | 12 +++++++----- public/views/index/body.ejs | 39 +-------------------------------------- 4 files changed, 49 insertions(+), 45 deletions(-) create mode 100644 locales/_supported.json diff --git a/app.js b/app.js index cdd922f9..a8380aed 100644 --- a/app.js +++ b/app.js @@ -28,6 +28,8 @@ const models = require('./lib/models') const csp = require('./lib/csp') const metrics = require('./lib/prometheus') +const supportedLocalesList = Object.keys(require('./locales/_supported.json')) + // server setup const app = express() let server = null @@ -126,8 +128,7 @@ if (config.csp.enable) { } i18n.configure({ - locales: ['en', 'zh-CN', 'zh-TW', 'fr', 'de', 'ja', 'es', 'ca', 'el', 'pt', 'it', 'tr', 'ru', 'nl', 'hr', 'pl', - 'uk', 'hi', 'sv', 'eo', 'da', 'ko', 'id', 'sr', 'vi', 'ar', 'cs', 'sk', 'ml', 'bg', 'fa', 'gl', 'he', 'hu', 'oc', 'pt-br'], + locales: supportedLocalesList, cookie: 'locale', indent: ' ', // this is the style poeditor.com exports it, this creates less churn directory: path.join(__dirname, '/locales'), diff --git a/locales/_supported.json b/locales/_supported.json new file mode 100644 index 00000000..5320bce9 --- /dev/null +++ b/locales/_supported.json @@ -0,0 +1,38 @@ +{ + "en": "English", + "zh-CN": "简体中文", + "zh-TW": "繁體中文", + "fr": "Français", + "de": "Deutsch", + "ja": "日本語", + "es": "Español", + "ca": "Català", + "el": "Ελληνικά", + "pt": "Português", + "it": "Italiano", + "tr": "Türkçe", + "ru": "Русский", + "nl": "Nederlands", + "hr": "Hrvatski", + "pl": "Polski", + "uk": "Українська", + "hi": "हिन्दी", + "sv": "Svenska", + "eo": "Esperanto", + "da": "Dansk", + "ko": "한국어", + "id": "Bahasa Indonesia", + "sr": "Cрпски", + "vi": "Tiếng Việt", + "ar": "العربية", + "cs": "Česky", + "sk": "Slovensky", + "ml": "മലയാളം", + "bg": "български език", + "fa": "فارسی", + "gl": "Galego", + "he": "עברית", + "hu": "Magyar", + "oc": "Occitan", + "pt-br": "Português do Brasil" +} \ No newline at end of file diff --git a/public/js/locale.js b/public/js/locale.js index 2470bd53..ccc1d0e4 100644 --- a/public/js/locale.js +++ b/public/js/locale.js @@ -1,8 +1,6 @@ /* eslint-env browser, jquery */ /* global Cookies */ - -const supported = ['en', 'zh-CN', 'zh-TW', 'fr', 'de', 'ja', 'es', 'ca', 'el', 'pt', 'it', 'tr', 'ru', 'nl', 'hr', 'pl', - 'uk', 'hi', 'sv', 'eo', 'da', 'ko', 'id', 'sr', 'vi', 'ar', 'cs', 'sk', 'ml', 'bg', 'fa', 'gl', 'he', 'hu', 'oc', 'pt-br'] +const supportedLanguages = require('../../locales/_supported.json') function detectLang () { if (Cookies.get('locale')) { @@ -14,9 +12,10 @@ function detectLang () { } const userLang = navigator.language || navigator.userLanguage const userLangCode = userLang.split('-')[0] - if (supported.includes(userLangCode)) { + const supportedLanguagesList = Object.keys(supportedLanguages) + if (supportedLanguagesList.includes(userLangCode)) { return userLangCode - } else if (supported.includes(userLang)) { + } else if (supportedLanguagesList.includes(userLang)) { return userLang } return 'en' @@ -24,6 +23,9 @@ function detectLang () { const lang = detectLang() const localeSelector = $('.ui-locale') +Object.entries(supportedLanguages).forEach(function ([isoCode, nativeName]) { + localeSelector.append(``) +}) // the following condition is needed as the selector is only available in the intro/history page if (localeSelector.length > 0) { diff --git a/public/views/index/body.ejs b/public/views/index/body.ejs index 54d2b32f..ca6204b1 100644 --- a/public/views/index/body.ejs +++ b/public/views/index/body.ejs @@ -127,44 +127,7 @@
- +

<%- __('Powered by %s', 'HedgeDoc') %> | <%= __('Releases') %> | <%= __('Source Code') %><% if(imprint) { %> | <%= __('Imprint') %><% } %><% if(privacyStatement) { %> | <%= __('Privacy') %><% } %><% if(termsOfUse) { %> | <%= __('Terms of Use') %><% } %>

-- cgit v1.2.3