2022-12-02 15:54:09 +03:00
|
|
|
import type { NuxtI18nOptions } from '@nuxtjs/i18n'
|
2023-01-01 17:29:11 +03:00
|
|
|
import type { DateTimeFormats, NumberFormats, PluralizationRule, PluralizationRules } from '@intlify/core-base'
|
|
|
|
|
2022-12-02 15:54:09 +03:00
|
|
|
import type { LocaleObject } from '#i18n'
|
|
|
|
|
2023-01-01 17:29:11 +03:00
|
|
|
interface LocaleObjectData extends LocaleObject {
|
|
|
|
numberFormats?: NumberFormats
|
|
|
|
dateTimeFormats?: DateTimeFormats
|
|
|
|
pluralRule?: PluralizationRule
|
|
|
|
}
|
|
|
|
|
|
|
|
const locales: LocaleObjectData[] = [
|
2022-12-02 15:54:09 +03:00
|
|
|
{
|
|
|
|
code: 'en-US',
|
|
|
|
file: 'en-US.json',
|
2022-12-28 09:50:26 +03:00
|
|
|
name: 'English (US)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'en-GB',
|
|
|
|
file: 'en-GB.json',
|
|
|
|
name: 'English (UK)',
|
2022-12-02 15:54:09 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'de-DE',
|
|
|
|
file: 'de-DE.json',
|
|
|
|
name: 'Deutsch',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'zh-CN',
|
|
|
|
file: 'zh-CN.json',
|
|
|
|
name: '简体中文',
|
|
|
|
},
|
2022-12-31 07:07:11 +03:00
|
|
|
{
|
|
|
|
code: 'zh-TW',
|
|
|
|
file: 'zh-TW.json',
|
|
|
|
name: '繁体中文',
|
|
|
|
},
|
2022-12-02 15:54:09 +03:00
|
|
|
{
|
|
|
|
code: 'ja-JP',
|
|
|
|
file: 'ja-JP.json',
|
|
|
|
name: '日本語',
|
|
|
|
},
|
2023-01-04 23:10:09 +03:00
|
|
|
{
|
|
|
|
code: 'nl-NL',
|
|
|
|
file: 'nl-NL.json',
|
|
|
|
name: 'Nederlands',
|
|
|
|
},
|
2022-12-02 15:54:09 +03:00
|
|
|
{
|
|
|
|
code: 'es-ES',
|
|
|
|
file: 'es-ES.json',
|
|
|
|
name: 'Español',
|
|
|
|
},
|
2022-12-02 23:27:58 +03:00
|
|
|
{
|
|
|
|
code: 'fr-FR',
|
|
|
|
file: 'fr-FR.json',
|
|
|
|
name: 'Français',
|
|
|
|
},
|
2023-01-08 22:35:48 +03:00
|
|
|
{
|
|
|
|
code: 'uk-UA',
|
|
|
|
file: 'uk-UA.json',
|
|
|
|
name: 'Українська',
|
|
|
|
pluralRule: (choice: number) => {
|
|
|
|
if (choice === 0)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
const name = new Intl.PluralRules('uk-UA').select(choice)
|
|
|
|
return { zero: 0, one: 1, two: 0 /* not used */, few: 2, many: 3, other: 4 }[name]
|
|
|
|
},
|
|
|
|
},
|
2022-12-15 00:19:38 +03:00
|
|
|
{
|
|
|
|
code: 'cs-CZ',
|
|
|
|
file: 'cs-CZ.json',
|
|
|
|
name: 'Česky',
|
2022-12-26 18:12:04 +03:00
|
|
|
},
|
2023-01-07 00:18:22 +03:00
|
|
|
({
|
2023-01-01 17:29:11 +03:00
|
|
|
code: 'ar-EG',
|
2022-12-26 18:12:04 +03:00
|
|
|
file: 'ar-EG.json',
|
|
|
|
name: 'العربية',
|
|
|
|
dir: 'rtl',
|
2023-01-01 17:29:11 +03:00
|
|
|
pluralRule: (choice: number) => {
|
|
|
|
const name = new Intl.PluralRules('ar-EG').select(choice)
|
|
|
|
return { zero: 0, one: 1, two: 2, few: 3, many: 4, other: 5 }[name]
|
|
|
|
},
|
2023-01-07 00:18:22 +03:00
|
|
|
} satisfies LocaleObjectData),
|
2022-12-29 21:30:28 +03:00
|
|
|
].sort((a, b) => a.code.localeCompare(b.code))
|
2022-12-02 15:54:09 +03:00
|
|
|
|
2023-01-01 17:29:11 +03:00
|
|
|
const datetimeFormats = Object.values(locales).reduce((acc, data) => {
|
|
|
|
const dateTimeFormats = data.dateTimeFormats
|
|
|
|
if (dateTimeFormats) {
|
|
|
|
acc[data.code] = { ...dateTimeFormats }
|
|
|
|
delete data.dateTimeFormats
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
acc[data.code] = {
|
2023-01-03 20:24:39 +03:00
|
|
|
shortDate: {
|
|
|
|
dateStyle: 'short',
|
|
|
|
},
|
2023-01-01 17:29:11 +03:00
|
|
|
short: {
|
|
|
|
dateStyle: 'short',
|
|
|
|
timeStyle: 'short',
|
|
|
|
},
|
|
|
|
long: {
|
|
|
|
dateStyle: 'long',
|
|
|
|
timeStyle: 'medium',
|
|
|
|
},
|
|
|
|
}
|
2022-12-02 15:54:09 +03:00
|
|
|
}
|
2023-01-01 17:29:11 +03:00
|
|
|
|
2022-12-02 15:54:09 +03:00
|
|
|
return acc
|
|
|
|
}, <DateTimeFormats>{})
|
|
|
|
|
2023-01-01 17:29:11 +03:00
|
|
|
const numberFormats = Object.values(locales).reduce((acc, data) => {
|
|
|
|
const numberFormats = data.numberFormats
|
|
|
|
if (numberFormats) {
|
|
|
|
acc[data.code] = { ...numberFormats }
|
|
|
|
delete data.numberFormats
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
acc[data.code] = {
|
|
|
|
percentage: {
|
|
|
|
style: 'percent',
|
|
|
|
maximumFractionDigits: 1,
|
|
|
|
},
|
|
|
|
smallCounting: {
|
|
|
|
style: 'decimal',
|
|
|
|
maximumFractionDigits: 0,
|
|
|
|
},
|
|
|
|
kiloCounting: {
|
2023-01-01 22:31:14 +03:00
|
|
|
notation: 'compact',
|
|
|
|
compactDisplay: 'short',
|
2023-01-01 17:29:11 +03:00
|
|
|
maximumFractionDigits: 1,
|
|
|
|
},
|
|
|
|
millionCounting: {
|
2023-01-01 22:31:14 +03:00
|
|
|
notation: 'compact',
|
|
|
|
compactDisplay: 'short',
|
2023-01-01 17:29:11 +03:00
|
|
|
maximumFractionDigits: 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc
|
|
|
|
}, <NumberFormats>{})
|
|
|
|
|
|
|
|
const pluralRules = Object.values(locales).reduce((acc, data) => {
|
|
|
|
const pluralRule = data.pluralRule
|
|
|
|
if (pluralRule) {
|
|
|
|
acc[data.code] = pluralRule
|
|
|
|
delete data.pluralRule
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc
|
|
|
|
}, <PluralizationRules>{})
|
|
|
|
|
2022-12-07 00:04:38 +03:00
|
|
|
export const i18n: NuxtI18nOptions = {
|
2022-12-02 15:54:09 +03:00
|
|
|
locales,
|
|
|
|
strategy: 'no_prefix',
|
|
|
|
detectBrowserLanguage: false,
|
|
|
|
langDir: 'locales',
|
|
|
|
defaultLocale: 'en-US',
|
|
|
|
vueI18n: {
|
|
|
|
fallbackLocale: 'en-US',
|
2022-12-02 20:23:47 +03:00
|
|
|
fallbackWarn: false,
|
|
|
|
missingWarn: false,
|
2022-12-02 15:54:09 +03:00
|
|
|
datetimeFormats,
|
2023-01-01 17:29:11 +03:00
|
|
|
numberFormats,
|
|
|
|
pluralRules,
|
2022-12-02 15:54:09 +03:00
|
|
|
},
|
|
|
|
lazy: true,
|
|
|
|
}
|