mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 02:05:21 -04: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
|
@ -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(`<option value="${isoCode}">${nativeName}</option>`)
|
||||
})
|
||||
|
||||
// the following condition is needed as the selector is only available in the intro/history page
|
||||
if (localeSelector.length > 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue