forked from JAGFx/ets2-dashboard-skin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_i18n.js
48 lines (39 loc) · 1.17 KB
/
_i18n.js
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
/**
* @author: Emmanuel SMITH <[email protected]>
* project: ets2-dashboard-skin
* file: _i18n.js
* Date: 15/09/2021
* Time: 21:52
*/
import store from '@/store';
import fr_fr from '@/translations/fr-FR.yaml';
import cn_cn from '@/translations/cn-CN.yaml';
import ru_ru from '@/translations/ru-RU.yaml';
import pt_pt from '@/translations/pt-PT.yaml';
const availableLocale = ['fr-FR', 'en-EN', 'cn-CN', 'ru-RU', 'pt-PT'];
const fallbackLocale = 'en-EN';
const changeLocale = (locale) => {
if (availableLocale.indexOf(locale) === -1)
throw new Error(`Unsupported locale: ${locale}`);
store.commit('i18n/setLocale', locale);
};
const currentLocaleTranslations = () => {
const currentLocaleName = store.getters['i18n/locale'];
switch (currentLocaleName) {
case 'fr-FR':
return fr_fr;
case 'cn-CN':
return cn_cn;
case 'ru-RU':
return ru_ru;
case 'pt-PT':
return pt_pt;
default:
return {};
}
};
const translate = (target) => {
if (!(target in currentLocaleTranslations())) return target;
return currentLocaleTranslations()[target];
};
export { fallbackLocale, translate, currentLocaleTranslations, changeLocale };