This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
i18n.jsx
209 lines (186 loc) · 5.82 KB
/
i18n.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
/* eslint-disable import/order */
const de = require('!!file-loader?name=i18n/[name].[hash].[ext]!./de.json');
const es = require('!!file-loader?name=i18n/[name].[hash].[ext]!./es.json');
const fr = require('!!file-loader?name=i18n/[name].[hash].[ext]!./fr.json');
const it = require('!!file-loader?name=i18n/[name].[hash].[ext]!./it.json');
const ja = require('!!file-loader?name=i18n/[name].[hash].[ext]!./ja.json');
const ko = require('!!file-loader?name=i18n/[name].[hash].[ext]!./ko.json');
const nl = require('!!file-loader?name=i18n/[name].[hash].[ext]!./nl.json');
const pl = require('!!file-loader?name=i18n/[name].[hash].[ext]!./pl.json');
const ptBR = require('!!file-loader?name=i18n/[name].[hash].[ext]!./pt-BR.json');
//eslint-disable-line camelcase
const tr = require('!!file-loader?name=i18n/[name].[hash].[ext]!./tr.json');
const ru = require('!!file-loader?name=i18n/[name].[hash].[ext]!./ru.json');
const zhTW = require('!!file-loader?name=i18n/[name].[hash].[ext]!./zh-TW.json');
//eslint-disable-line camelcase
const zhCN = require('!!file-loader?name=i18n/[name].[hash].[ext]!./zh-CN.json'); //eslint-disable-line camelcase
import {addLocaleData} from 'react-intl';
import deLocaleData from 'react-intl/locale-data/de';
import enLocaleData from 'react-intl/locale-data/en';
import esLocaleData from 'react-intl/locale-data/es';
import frLocaleData from 'react-intl/locale-data/fr';
import itLocaleData from 'react-intl/locale-data/it';
import jaLocaleData from 'react-intl/locale-data/ja';
import koLocaleData from 'react-intl/locale-data/ko';
import nlLocaleData from 'react-intl/locale-data/nl';
import plLocaleData from 'react-intl/locale-data/pl';
import ptLocaleData from 'react-intl/locale-data/pt';
import trLocaleData from 'react-intl/locale-data/tr';
import ruLocaleData from 'react-intl/locale-data/ru';
import zhLocaleData from 'react-intl/locale-data/zh';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import store from 'stores/redux_store.jsx';
// should match the values in model/config.go
const languages = {
de: {
value: 'de',
name: 'Deutsch',
order: 0,
url: de,
},
en: {
value: 'en',
name: 'English',
order: 1,
url: '',
},
es: {
value: 'es',
name: 'Español',
order: 2,
url: es,
},
fr: {
value: 'fr',
name: 'Français',
order: 3,
url: fr,
},
it: {
value: 'it',
name: 'Italiano',
order: 4,
url: it,
},
ja: {
value: 'ja',
name: '日本語',
order: 13,
url: ja,
},
ko: {
value: 'ko',
name: '한국어 (Alpha)',
order: 10,
url: ko,
},
nl: {
value: 'nl',
name: 'Nederlands (Alpha)',
order: 5,
url: nl,
},
pl: {
value: 'pl',
name: 'Polski (Alpha)',
order: 6,
url: pl,
},
'pt-BR': {
value: 'pt-BR',
name: 'Português (Brasil)',
order: 7,
url: ptBR,
},
tr: {
value: 'tr',
name: 'Türkçe',
order: 8,
url: tr,
},
ru: {
value: 'ru',
name: 'Pусский (Alpha)',
order: 9,
url: ru,
},
'zh-TW': {
value: 'zh-TW',
name: '中文 (繁體)',
order: 12,
url: zhTW,
},
'zh-CN': {
value: 'zh-CN',
name: '中文 (简体)',
order: 11,
url: zhCN,
},
};
export function getAllLanguages() {
return languages;
}
export function getLanguages() {
const config = getConfig(store.getState());
if (!config.AvailableLocales) {
return getAllLanguages();
}
return config.AvailableLocales.split(',').filter((l) => languages[l]).map((l) => languages[l]);
}
export function getLanguageInfo(locale) {
return getAllLanguages()[locale];
}
export function isLanguageAvailable(locale) {
return Boolean(getLanguages()[locale]);
}
export function safariFix(callback) {
require.ensure([
'intl',
'intl/locale-data/jsonp/de.js',
'intl/locale-data/jsonp/en.js',
'intl/locale-data/jsonp/es.js',
'intl/locale-data/jsonp/fr.js',
'intl/locale-data/jsonp/it.js',
'intl/locale-data/jsonp/ja.js',
'intl/locale-data/jsonp/ko.js',
'intl/locale-data/jsonp/nl.js',
'intl/locale-data/jsonp/pl.js',
'intl/locale-data/jsonp/pt.js',
'intl/locale-data/jsonp/tr.js',
'intl/locale-data/jsonp/ru.js',
'intl/locale-data/jsonp/zh.js',
], (require) => {
require('intl');
require('intl/locale-data/jsonp/de.js');
require('intl/locale-data/jsonp/en.js');
require('intl/locale-data/jsonp/es.js');
require('intl/locale-data/jsonp/fr.js');
require('intl/locale-data/jsonp/it.js');
require('intl/locale-data/jsonp/ja.js');
require('intl/locale-data/jsonp/ko.js');
require('intl/locale-data/jsonp/nl.js');
require('intl/locale-data/jsonp/pl.js');
require('intl/locale-data/jsonp/pt.js');
require('intl/locale-data/jsonp/tr.js');
require('intl/locale-data/jsonp/ru.js');
require('intl/locale-data/jsonp/zh.js');
callback();
});
}
export function doAddLocaleData() {
addLocaleData(enLocaleData);
addLocaleData(deLocaleData);
addLocaleData(esLocaleData);
addLocaleData(frLocaleData);
addLocaleData(itLocaleData);
addLocaleData(jaLocaleData);
addLocaleData(koLocaleData);
addLocaleData(nlLocaleData);
addLocaleData(plLocaleData);
addLocaleData(ptLocaleData);
addLocaleData(trLocaleData);
addLocaleData(ruLocaleData);
addLocaleData(zhLocaleData);
}