-
Notifications
You must be signed in to change notification settings - Fork 4
/
i18n.ts
30 lines (25 loc) · 854 Bytes
/
i18n.ts
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
import {i18n} from '@lingui/core'
const loadMessages = (locale: Locale) => {
switch (locale) {
case 'ky':
// @ts-expect-error
return import('./locales/ky.po')
case 'en':
default:
// @ts-expect-error
return import('./locales/en.po')
}
}
const getPluralRules = (locale: Locale) => {
const tag = locale === 'ky' ? 'ky-KG' : 'en-US'
const ordinalPlurals = new Intl.PluralRules(tag, {type: 'ordinal'})
const cardinalPlurals = new Intl.PluralRules(tag, {type: 'cardinal'})
return (count: number, ordinal: boolean) =>
(ordinal ? ordinalPlurals : cardinalPlurals).select(count)
}
export async function dynamicActivate(locale: Locale) {
const {messages} = await loadMessages(locale)
i18n.loadLocaleData(locale, {plurals: getPluralRules(locale)})
i18n.load(locale, messages)
i18n.activate(locale)
}