mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
refactored code according to review
This commit is contained in:
@@ -1,65 +1,75 @@
|
|||||||
|
const 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'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
languages: [
|
getLocales () {
|
||||||
{
|
return languages.reduce(function (localeList, locale) {
|
||||||
name: 'Albanian',
|
localeList.push(locale.locale)
|
||||||
locale: 'sq'
|
return localeList
|
||||||
},
|
}, [])
|
||||||
{
|
},
|
||||||
name: 'Chinese (zh-CN)',
|
getLanguages () {
|
||||||
locale: 'zh-CN'
|
return languages
|
||||||
},
|
}
|
||||||
{
|
|
||||||
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,17 +1,12 @@
|
|||||||
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')
|
const { getLocales } = 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: locales,
|
locales: getLocales(),
|
||||||
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,7 +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'
|
import { getLocales } 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
|
||||||
@@ -153,12 +153,7 @@ class Main extends React.Component {
|
|||||||
document.body.setAttribute('data-theme', 'default')
|
document.body.setAttribute('data-theme', 'default')
|
||||||
}
|
}
|
||||||
|
|
||||||
let locales = languages.reduce(function (localeList, locale) {
|
if (getLocales().indexOf(config.ui.language) !== -1) {
|
||||||
localeList.push(locale.locale)
|
|
||||||
return localeList
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
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,7 +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'
|
import { getLanguages } from 'browser/lib/Languages'
|
||||||
|
|
||||||
const OSX = global.process.platform === 'darwin'
|
const OSX = global.process.platform === 'darwin'
|
||||||
|
|
||||||
@@ -184,9 +184,7 @@ class UiTab extends React.Component {
|
|||||||
ref='uiLanguage'
|
ref='uiLanguage'
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
languages.map((language) => {
|
getLanguages().map((language) => <option value={language.locale} key={language.locale}>{i18n.__(language.name)}</option>)
|
||||||
return (<option value={language.locale} key={language.locale}>{i18n.__(language.name)}</option>)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user