mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-28 10:00:58 -05:00
Extract list of supported languages in separate file
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
cf87499e38
commit
0d943d1284
4 changed files with 49 additions and 45 deletions
5
app.js
5
app.js
|
@ -28,6 +28,8 @@ const models = require('./lib/models')
|
||||||
const csp = require('./lib/csp')
|
const csp = require('./lib/csp')
|
||||||
const metrics = require('./lib/prometheus')
|
const metrics = require('./lib/prometheus')
|
||||||
|
|
||||||
|
const supportedLocalesList = Object.keys(require('./locales/_supported.json'))
|
||||||
|
|
||||||
// server setup
|
// server setup
|
||||||
const app = express()
|
const app = express()
|
||||||
let server = null
|
let server = null
|
||||||
|
@ -126,8 +128,7 @@ if (config.csp.enable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
i18n.configure({
|
i18n.configure({
|
||||||
locales: ['en', 'zh-CN', 'zh-TW', 'fr', 'de', 'ja', 'es', 'ca', 'el', 'pt', 'it', 'tr', 'ru', 'nl', 'hr', 'pl',
|
locales: supportedLocalesList,
|
||||||
'uk', 'hi', 'sv', 'eo', 'da', 'ko', 'id', 'sr', 'vi', 'ar', 'cs', 'sk', 'ml', 'bg', 'fa', 'gl', 'he', 'hu', 'oc', 'pt-br'],
|
|
||||||
cookie: 'locale',
|
cookie: 'locale',
|
||||||
indent: ' ', // this is the style poeditor.com exports it, this creates less churn
|
indent: ' ', // this is the style poeditor.com exports it, this creates less churn
|
||||||
directory: path.join(__dirname, '/locales'),
|
directory: path.join(__dirname, '/locales'),
|
||||||
|
|
38
locales/_supported.json
Normal file
38
locales/_supported.json
Normal file
|
@ -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"
|
||||||
|
}
|
|
@ -1,8 +1,6 @@
|
||||||
/* eslint-env browser, jquery */
|
/* eslint-env browser, jquery */
|
||||||
/* global Cookies */
|
/* global Cookies */
|
||||||
|
const supportedLanguages = require('../../locales/_supported.json')
|
||||||
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']
|
|
||||||
|
|
||||||
function detectLang () {
|
function detectLang () {
|
||||||
if (Cookies.get('locale')) {
|
if (Cookies.get('locale')) {
|
||||||
|
@ -14,9 +12,10 @@ function detectLang () {
|
||||||
}
|
}
|
||||||
const userLang = navigator.language || navigator.userLanguage
|
const userLang = navigator.language || navigator.userLanguage
|
||||||
const userLangCode = userLang.split('-')[0]
|
const userLangCode = userLang.split('-')[0]
|
||||||
if (supported.includes(userLangCode)) {
|
const supportedLanguagesList = Object.keys(supportedLanguages)
|
||||||
|
if (supportedLanguagesList.includes(userLangCode)) {
|
||||||
return userLangCode
|
return userLangCode
|
||||||
} else if (supported.includes(userLang)) {
|
} else if (supportedLanguagesList.includes(userLang)) {
|
||||||
return userLang
|
return userLang
|
||||||
}
|
}
|
||||||
return 'en'
|
return 'en'
|
||||||
|
@ -24,6 +23,9 @@ function detectLang () {
|
||||||
|
|
||||||
const lang = detectLang()
|
const lang = detectLang()
|
||||||
const localeSelector = $('.ui-locale')
|
const localeSelector = $('.ui-locale')
|
||||||
|
Object.entries(supportedLanguages).forEach(function ([isoCode, nativeName]) {
|
||||||
|
localeSelector.append(`<option value="${isoCode}">${nativeName}</option>`)
|
||||||
|
})
|
||||||
|
|
||||||
// the following condition is needed as the selector is only available in the intro/history page
|
// the following condition is needed as the selector is only available in the intro/history page
|
||||||
if (localeSelector.length > 0) {
|
if (localeSelector.length > 0) {
|
||||||
|
|
|
@ -127,44 +127,7 @@
|
||||||
|
|
||||||
<div class="mastfoot">
|
<div class="mastfoot">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<select class="ui-locale">
|
<select class="ui-locale"></select>
|
||||||
<option value="en">English</option>
|
|
||||||
<option value="zh-CN">简体中文</option>
|
|
||||||
<option value="zh-TW">繁體中文</option>
|
|
||||||
<option value="fr">Français</option>
|
|
||||||
<option value="de">Deutsch</option>
|
|
||||||
<option value="ja">日本語</option>
|
|
||||||
<option value="es">Español</option>
|
|
||||||
<option value="ca">Català</option>
|
|
||||||
<option value="el">Ελληνικά</option>
|
|
||||||
<option value="pt">Português</option>
|
|
||||||
<option value="it">Italiano</option>
|
|
||||||
<option value="tr">Türkçe</option>
|
|
||||||
<option value="ru">Русский</option>
|
|
||||||
<option value="nl">Nederlands</option>
|
|
||||||
<option value="hr">Hrvatski</option>
|
|
||||||
<option value="pl">Polski</option>
|
|
||||||
<option value="uk">Українська</option>
|
|
||||||
<option value="hi">हिन्दी</option>
|
|
||||||
<option value="sv">Svenska</option>
|
|
||||||
<option value="eo">Esperanto</option>
|
|
||||||
<option value="da">Dansk</option>
|
|
||||||
<option value="ko">한국어</option>
|
|
||||||
<option value="id">Bahasa Indonesia</option>
|
|
||||||
<option value="sr">Cрпски</option>
|
|
||||||
<option value="vi">Tiếng Việt</option>
|
|
||||||
<option value="ar">العربية</option>
|
|
||||||
<option value="cs">Česky</option>
|
|
||||||
<option value="sk">Slovensky</option>
|
|
||||||
<option value="ml">മലയാളം</option>
|
|
||||||
<option value="bg">български език</option>
|
|
||||||
<option value="fa">فارسی</option>
|
|
||||||
<option value="gl">Galego</option>
|
|
||||||
<option value="he">עברית</option>
|
|
||||||
<option value="hu">Magyar</option>
|
|
||||||
<option value="oc">Occitan</option>
|
|
||||||
<option value="pt-br">Português do Brasil</option>
|
|
||||||
</select>
|
|
||||||
<p>
|
<p>
|
||||||
<%- __('Powered by %s', '<a href="https://hedgedoc.org">HedgeDoc</a>') %> | <a href="<%- serverURL %>/s/release-notes" target="_blank" rel="noopener"><%= __('Releases') %></a> | <a href="<%- sourceURL %>" target="_blank" rel="noopener"><%= __('Source Code') %></a><% if(imprint) { %> | <a href="<%- serverURL %>/s/imprint" target="_blank" rel="noopener"><%= __('Imprint') %></a><% } %><% if(privacyStatement) { %> | <a href="<%- serverURL %>/s/privacy" target="_blank" rel="noopener"><%= __('Privacy') %></a><% } %><% if(termsOfUse) { %> | <a href="<%- serverURL %>/s/terms-of-use" target="_blank" rel="noopener"><%= __('Terms of Use') %></a><% } %>
|
<%- __('Powered by %s', '<a href="https://hedgedoc.org">HedgeDoc</a>') %> | <a href="<%- serverURL %>/s/release-notes" target="_blank" rel="noopener"><%= __('Releases') %></a> | <a href="<%- sourceURL %>" target="_blank" rel="noopener"><%= __('Source Code') %></a><% if(imprint) { %> | <a href="<%- serverURL %>/s/imprint" target="_blank" rel="noopener"><%= __('Imprint') %></a><% } %><% if(privacyStatement) { %> | <a href="<%- serverURL %>/s/privacy" target="_blank" rel="noopener"><%= __('Privacy') %></a><% } %><% if(termsOfUse) { %> | <a href="<%- serverURL %>/s/terms-of-use" target="_blank" rel="noopener"><%= __('Terms of Use') %></a><% } %>
|
||||||
</p>
|
</p>
|
||||||
|
|
Loading…
Reference in a new issue