2020-07-16 22:11:28 +00:00
|
|
|
import Vue from 'vue'
|
|
|
|
import VueI18n from 'vue-i18n'
|
|
|
|
|
2020-09-26 15:53:25 +00:00
|
|
|
import { locales } from '@/lang/index'
|
2020-07-16 22:11:28 +00:00
|
|
|
|
|
|
|
Vue.use(VueI18n)
|
|
|
|
|
2020-09-26 15:53:25 +00:00
|
|
|
const storedLocale = localStorage.getItem('locale')
|
|
|
|
const DEFAULT_LANG = storedLocale || 'en'
|
2020-07-16 22:11:28 +00:00
|
|
|
|
|
|
|
document.querySelector('html').setAttribute('lang', DEFAULT_LANG)
|
|
|
|
|
|
|
|
const i18n = new VueI18n({
|
|
|
|
locale: DEFAULT_LANG,
|
2020-09-26 15:53:25 +00:00
|
|
|
fallbackLocale: 'en',
|
2020-07-29 14:29:25 +00:00
|
|
|
messages: locales,
|
|
|
|
pluralizationRules: {
|
2020-07-29 16:41:08 +00:00
|
|
|
/**
|
2020-09-26 15:53:25 +00:00
|
|
|
* @param {number} choice A choice index given by the input to $tc: `$tc('path.to.rule', choiceIndex)`
|
|
|
|
* @param {number} choicesLength An overall amount of available choices
|
|
|
|
* @returns A final choice index to select plural word by
|
2020-07-29 16:41:08 +00:00
|
|
|
*/
|
2021-05-23 16:46:03 +00:00
|
|
|
ru(choice, choicesLength) {
|
|
|
|
const n = Math.abs(choice) % 100
|
|
|
|
const n1 = n % 10
|
2020-07-29 16:41:08 +00:00
|
|
|
|
|
|
|
if (n > 10 && n < 20) {
|
2020-07-29 20:11:47 +00:00
|
|
|
return 2
|
2020-07-29 16:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n1 > 1 && n1 < 5) {
|
2020-07-29 20:11:47 +00:00
|
|
|
return 1
|
2020-07-29 16:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n1 == 1) {
|
2020-07-29 20:11:47 +00:00
|
|
|
return 0
|
2020-07-29 16:41:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-29 20:11:47 +00:00
|
|
|
return 2
|
2020-07-29 16:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-16 22:11:28 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
export default i18n
|