-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlit-element-i18n.js
36 lines (32 loc) · 936 Bytes
/
lit-element-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
import i18next, { t as translate } from 'i18next'
import backend from 'i18next-xhr-backend'
export const i18nMixin = baseClass => class extends baseClass {
firstUpdated() {
i18next.on('initialized', options => {
this.requestUpdate()
})
i18next.on('languageChanged', options => {
this.requestUpdate()
})
if (!i18next.isInitialized) {
i18next.use(backend)
i18next.init({
lng: 'en',
debug: true,
defaultNS: 'app',
ns: ['app'],
fallbackLng: 'en',
backend: {
loadPath: this.languageResources || '/assets/locales/{{lng}}/{{ns}}.json'
}
})
}
super.firstUpdated && super.firstUpdated()
}
changeLanguage(lang) {
i18next.changeLanguage(lang)
}
}
export {
translate
}