This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathl10n.js
More file actions
96 lines (85 loc) · 2.52 KB
/
Copy pathl10n.js
File metadata and controls
96 lines (85 loc) · 2.52 KB
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
import classic from 'ember-classic-decorator';
import { inject as service } from '@ember/service';
import computed from 'ember-computed';
import L10n from 'ember-l10n/services/l10n';
import moment from 'moment-timezone';
import { getScript } from 'open-event-frontend/utils/loader';
@classic
export default class L10nService extends L10n {
@service
cookies;
@service
fastboot;
@computed(function() {
return {
'ar' : 'عربي',
'bn' : 'বাংলা',
'ca' : 'Català',
'de' : 'Deutsch',
'en' : 'English',
'es' : 'Español',
'fa_IR' : 'فارسی',
'fr' : 'Français',
'hi' : 'हिंदी',
'hr' : 'Hrvatski',
'id' : 'Bahasa Indonesia',
'ja' : '日本語',
'ko' : '한국어',
'nb_NO' : 'Norsk bokmål',
'pl' : 'Polski',
'ru' : 'Русский',
'sv' : 'Svenska',
'te' : 'తెలుగు',
'th' : 'ไทย',
'vi' : 'Tiếng Việt',
'zh_Hans' : '中文(简体)',
'zh_Hant' : '中文(繁體)'
};
})
availableLocales;
localStorageKey = 'current_locale';
autoInitialize = false;
jsonPath = '/assets/locales';
switchLanguage(locale, skipRefresh) {
if (this.locale === locale) {return}
this.setLocale(locale);
this.cookies.write(this.localStorageKey, locale, { path: '/' });
if (!this.fastboot.isFastBoot && !skipRefresh) {
location.reload();
}
}
detectQueryLang() {
const params = new URLSearchParams(location.search);
const locale = params.get('lang');
if (!locale || !Object.keys(this.availableLocales).includes(locale)) {return}
this.switchLanguage(locale, true);
}
init() {
super.init(...arguments);
this.detectQueryLang();
const currentLocale = this.cookies.read(this.localStorageKey);
const detectedLocale = this.detectLocale();
let locale = 'en';
if (currentLocale) {
locale = currentLocale;
} else if (detectedLocale) {
locale = detectedLocale;
}
this.setLocale(locale);
if (locale !== 'en') {
if (locale === 'zh_Hans') {
locale = 'zh-cn';
} else if (locale === 'zh_Hant') {
locale = 'zh-tw';
} else if (locale === 'nb_NO') {
locale = 'nb';
} else if (locale === 'fa_IR') {
locale = 'fa-IR';
}
getScript(`/assets/moment-locales/${locale}.js`)
.then(() => {
moment.locale(locale);
});
}
}
}