Skip to content

Commit ab393b1

Browse files
authored
Merge pull request #1818 from ZeroX-DG/fix-centralize-language
Centralized languages into 1 files
2 parents e643147 + d76db72 commit ab393b1

4 files changed

Lines changed: 83 additions & 35 deletions

File tree

browser/lib/Languages.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const languages = [
2+
{
3+
name: 'Albanian',
4+
locale: 'sq'
5+
},
6+
{
7+
name: 'Chinese (zh-CN)',
8+
locale: 'zh-CN'
9+
},
10+
{
11+
name: 'Chinese (zh-TW)',
12+
locale: 'zh-TW'
13+
},
14+
{
15+
name: 'Danish',
16+
locale: 'da'
17+
},
18+
{
19+
name: 'English',
20+
locale: 'en'
21+
},
22+
{
23+
name: 'French',
24+
locale: 'fr'
25+
},
26+
{
27+
name: 'German',
28+
locale: 'de'
29+
},
30+
{
31+
name: 'Hungarian',
32+
locale: 'hu'
33+
},
34+
{
35+
name: 'Japanese',
36+
locale: 'ja'
37+
},
38+
{
39+
name: 'Korean',
40+
locale: 'ko'
41+
},
42+
{
43+
name: 'Norwegian',
44+
locale: 'no'
45+
},
46+
{
47+
name: 'Polish',
48+
locale: 'pl'
49+
},
50+
{
51+
name: 'Portuguese',
52+
locale: 'pt'
53+
},
54+
{
55+
name: 'Russian',
56+
locale: 'ru'
57+
},
58+
{
59+
name: 'Spanish',
60+
locale: 'es-ES'
61+
}
62+
]
63+
64+
module.exports = {
65+
getLocales () {
66+
return languages.reduce(function (localeList, locale) {
67+
localeList.push(locale.locale)
68+
return localeList
69+
}, [])
70+
},
71+
getLanguages () {
72+
return languages
73+
}
74+
}
75+

browser/lib/i18n.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
const path = require('path')
22
const { remote } = require('electron')
33
const { app } = remote
4+
const { getLocales } = require('./Languages.js')
45

56
// load package for localization
67
const i18n = new (require('i18n-2'))({
78
// setup some locales - other locales default to the first locale
8-
locales: [ 'da', 'de', 'en', 'es-ES', 'fr', 'hu', 'ja', 'ko', 'pl', 'pt-BR', 'pt-PT', 'ru', 'sq', 'zh-CN', 'zh-TW' ],
9+
locales: getLocales(),
910
extension: '.json',
1011
directory: process.env.NODE_ENV === 'production'
1112
? path.join(app.getAppPath(), './locales')

browser/main/Main.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import eventEmitter from 'browser/main/lib/eventEmitter'
1515
import { hashHistory } from 'react-router'
1616
import store from 'browser/main/store'
1717
import i18n from 'browser/lib/i18n'
18+
import { getLocales } from 'browser/lib/Languages'
1819
const path = require('path')
1920
const electron = require('electron')
2021
const { remote } = electron
@@ -152,24 +153,7 @@ class Main extends React.Component {
152153
document.body.setAttribute('data-theme', 'default')
153154
}
154155

155-
const supportedLanguages = [
156-
'sq',
157-
'zh-CN',
158-
'zh-TW',
159-
'da',
160-
'fr',
161-
'de',
162-
'hu',
163-
'ja',
164-
'ko',
165-
'no',
166-
'pl',
167-
'pt',
168-
'ru',
169-
'es-ES'
170-
]
171-
172-
if (supportedLanguages.indexOf(config.ui.language) !== -1) {
156+
if (getLocales().indexOf(config.ui.language) !== -1) {
173157
i18n.setLocale(config.ui.language)
174158
} else {
175159
i18n.setLocale('en')

browser/main/modals/PreferencesModal/UiTab.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import CodeMirror from 'codemirror'
1010
import 'codemirror-mode-elixir'
1111
import _ from 'lodash'
1212
import i18n from 'browser/lib/i18n'
13+
import { getLanguages } from 'browser/lib/Languages'
1314

1415
const OSX = global.process.platform === 'darwin'
1516

@@ -182,22 +183,9 @@ class UiTab extends React.Component {
182183
onChange={(e) => this.handleUIChange(e)}
183184
ref='uiLanguage'
184185
>
185-
<option value='sq'>{i18n.__('Albanian')}</option>
186-
<option value='zh-CN'>{i18n.__('Chinese (zh-CN)')}</option>
187-
<option value='zh-TW'>{i18n.__('Chinese (zh-TW)')}</option>
188-
<option value='da'>{i18n.__('Danish')}</option>
189-
<option value='en'>{i18n.__('English')}</option>
190-
<option value='fr'>{i18n.__('French')}</option>
191-
<option value='de'>{i18n.__('German')}</option>
192-
<option value='hu'>{i18n.__('Hungarian')}</option>
193-
<option value='ja'>{i18n.__('Japanese')}</option>
194-
<option value='ko'>{i18n.__('Korean')}</option>
195-
<option value='no'>{i18n.__('Norwegian')}</option>
196-
<option value='pl'>{i18n.__('Polish')}</option>
197-
<option value='pt-BR'>{i18n.__('Portuguese (Brazil)')}</option>
198-
<option value='pt-PT'>{i18n.__('Portuguese (Portugal)')}</option>
199-
<option value='ru'>{i18n.__('Russian')}</option>
200-
<option value='es-ES'>{i18n.__('Spanish')}</option>
186+
{
187+
getLanguages().map((language) => <option value={language.locale} key={language.locale}>{i18n.__(language.name)}</option>)
188+
}
201189
</select>
202190
</div>
203191
</div>

0 commit comments

Comments
 (0)