mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Centralized languages into 1 file
This commit is contained in:
65
browser/lib/Languages.js
Normal file
65
browser/lib/Languages.js
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
module.exports = {
|
||||||
|
languages: [
|
||||||
|
{
|
||||||
|
name: 'Albanian',
|
||||||
|
locale: 'sq'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Chinese (zh-CN)',
|
||||||
|
locale: 'zh-CN'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Chinese (zh-TW)',
|
||||||
|
locale: 'zh-TW'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Danish',
|
||||||
|
locale: 'da'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'English',
|
||||||
|
locale: 'en'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'French',
|
||||||
|
locale: 'fr'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'German',
|
||||||
|
locale: 'de'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Hungarian',
|
||||||
|
locale: 'hu'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Japanese',
|
||||||
|
locale: 'ja'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Korean',
|
||||||
|
locale: 'ko'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Norwegian',
|
||||||
|
locale: 'no'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Polish',
|
||||||
|
locale: 'pl'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Portuguese',
|
||||||
|
locale: 'pt'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Russian',
|
||||||
|
locale: 'ru'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Spanish',
|
||||||
|
locale: 'es-ES'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const { remote } = require('electron')
|
const { remote } = require('electron')
|
||||||
const { app } = remote
|
const { app } = remote
|
||||||
|
const { languages } = require('./Languages.js')
|
||||||
|
|
||||||
|
let locales = languages.reduce(function (localeList, locale) {
|
||||||
|
localeList.push(locale.locale)
|
||||||
|
return localeList
|
||||||
|
}, [])
|
||||||
|
|
||||||
// load package for localization
|
// load package for localization
|
||||||
const i18n = new (require('i18n-2'))({
|
const i18n = new (require('i18n-2'))({
|
||||||
// setup some locales - other locales default to the first locale
|
// setup some locales - other locales default to the first locale
|
||||||
locales: ['en', 'sq', 'zh-CN', 'zh-TW', 'da', 'fr', 'de', 'hu', 'ja', 'ko', 'no', 'pl', 'pt', 'es-ES'],
|
locales: locales,
|
||||||
extension: '.json',
|
extension: '.json',
|
||||||
directory: process.env.NODE_ENV === 'production'
|
directory: process.env.NODE_ENV === 'production'
|
||||||
? path.join(app.getAppPath(), './locales')
|
? path.join(app.getAppPath(), './locales')
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import eventEmitter from 'browser/main/lib/eventEmitter'
|
|||||||
import { hashHistory } from 'react-router'
|
import { hashHistory } from 'react-router'
|
||||||
import store from 'browser/main/store'
|
import store from 'browser/main/store'
|
||||||
import i18n from 'browser/lib/i18n'
|
import i18n from 'browser/lib/i18n'
|
||||||
|
import { languages } from 'browser/lib/Languages'
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const { remote } = electron
|
const { remote } = electron
|
||||||
@@ -152,24 +153,12 @@ class Main extends React.Component {
|
|||||||
document.body.setAttribute('data-theme', 'default')
|
document.body.setAttribute('data-theme', 'default')
|
||||||
}
|
}
|
||||||
|
|
||||||
const supportedLanguages = [
|
let locales = languages.reduce(function (localeList, locale) {
|
||||||
'sq',
|
localeList.push(locale.locale)
|
||||||
'zh-CN',
|
return localeList
|
||||||
'zh-TW',
|
}, [])
|
||||||
'da',
|
|
||||||
'fr',
|
|
||||||
'de',
|
|
||||||
'hu',
|
|
||||||
'ja',
|
|
||||||
'ko',
|
|
||||||
'no',
|
|
||||||
'pl',
|
|
||||||
'pt',
|
|
||||||
'ru',
|
|
||||||
'es-ES'
|
|
||||||
]
|
|
||||||
|
|
||||||
if (supportedLanguages.indexOf(config.ui.language) !== -1) {
|
if (locales.indexOf(config.ui.language) !== -1) {
|
||||||
i18n.setLocale(config.ui.language)
|
i18n.setLocale(config.ui.language)
|
||||||
} else {
|
} else {
|
||||||
i18n.setLocale('en')
|
i18n.setLocale('en')
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import CodeMirror from 'codemirror'
|
|||||||
import 'codemirror-mode-elixir'
|
import 'codemirror-mode-elixir'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import i18n from 'browser/lib/i18n'
|
import i18n from 'browser/lib/i18n'
|
||||||
|
import { languages } from 'browser/lib/Languages'
|
||||||
|
|
||||||
const OSX = global.process.platform === 'darwin'
|
const OSX = global.process.platform === 'darwin'
|
||||||
|
|
||||||
@@ -182,21 +183,11 @@ class UiTab extends React.Component {
|
|||||||
onChange={(e) => this.handleUIChange(e)}
|
onChange={(e) => this.handleUIChange(e)}
|
||||||
ref='uiLanguage'
|
ref='uiLanguage'
|
||||||
>
|
>
|
||||||
<option value='sq'>{i18n.__('Albanian')}</option>
|
{
|
||||||
<option value='zh-CN'>{i18n.__('Chinese (zh-CN)')}</option>
|
languages.map((language) => {
|
||||||
<option value='zh-TW'>{i18n.__('Chinese (zh-TW)')}</option>
|
return (<option value={language.locale} key={language.locale}>{i18n.__(language.name)}</option>)
|
||||||
<option value='da'>{i18n.__('Danish')}</option>
|
})
|
||||||
<option value='en'>{i18n.__('English')}</option>
|
}
|
||||||
<option value='fr'>{i18n.__('French')}</option>
|
|
||||||
<option value='de'>{i18n.__('German')}</option>
|
|
||||||
<option value='hu'>{i18n.__('Hungarian')}</option>
|
|
||||||
<option value='ja'>{i18n.__('Japanese')}</option>
|
|
||||||
<option value='ko'>{i18n.__('Korean')}</option>
|
|
||||||
<option value='no'>{i18n.__('Norwegian')}</option>
|
|
||||||
<option value='pl'>{i18n.__('Polish')}</option>
|
|
||||||
<option value='pt'>{i18n.__('Portuguese')}</option>
|
|
||||||
<option value='ru'>{i18n.__('Russian')}</option>
|
|
||||||
<option value='es'>{i18n.__('Spanish')}</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user