2023-01-01 14:29:11 +00:00
|
|
|
import type { DateTimeFormats, NumberFormats, PluralizationRule, PluralizationRules } from '@intlify/core-base'
|
2024-02-24 16:46:14 +00:00
|
|
|
import type { LocaleObject } from '@nuxtjs/i18n'
|
2022-12-02 12:54:09 +00:00
|
|
|
|
2023-01-01 14:29:11 +00:00
|
|
|
interface LocaleObjectData extends LocaleObject {
|
|
|
|
numberFormats?: NumberFormats
|
|
|
|
dateTimeFormats?: DateTimeFormats
|
|
|
|
pluralRule?: PluralizationRule
|
|
|
|
}
|
|
|
|
|
2023-05-15 12:35:43 +00:00
|
|
|
export const countryLocaleVariants: Record<string, (LocaleObjectData & { country?: boolean }) []> = {
|
2023-01-24 14:42:57 +00:00
|
|
|
ar: [
|
2023-05-06 15:45:42 +00:00
|
|
|
// ar.json contains ar-EG translations
|
2023-01-24 14:42:57 +00:00
|
|
|
// { code: 'ar-DZ', name: 'Arabic (Algeria)' },
|
|
|
|
// { code: 'ar-BH', name: 'Arabic (Bahrain)' },
|
2023-05-15 12:35:43 +00:00
|
|
|
{ country: true, code: 'ar-EG', name: 'العربية' },
|
2023-01-24 14:42:57 +00:00
|
|
|
// { code: 'ar-EG', name: 'Arabic (Egypt)' },
|
|
|
|
// { code: 'ar-IQ', name: 'Arabic (Iraq)' },
|
|
|
|
// { code: 'ar-JO', name: 'Arabic (Jordan)' },
|
|
|
|
// { code: 'ar-KW', name: 'Arabic (Kuwait)' },
|
|
|
|
// { code: 'ar-LB', name: 'Arabic (Lebanon)' },
|
|
|
|
// { code: 'ar-LY', name: 'Arabic (Libya)' },
|
|
|
|
// { code: 'ar-MA', name: 'Arabic (Morocco)' },
|
|
|
|
// { code: 'ar-OM', name: 'Arabic (Oman)' },
|
|
|
|
// { code: 'ar-QA', name: 'Arabic (Qatar)' },
|
|
|
|
// { code: 'ar-SA', name: 'Arabic (Saudi Arabia)' },
|
|
|
|
// { code: 'ar-SY', name: 'Arabic (Syria)' },
|
|
|
|
// { code: 'ar-TN', name: 'Arabic (Tunisia)' },
|
|
|
|
// { code: 'ar-AE', name: 'Arabic (U.A.E.)' },
|
|
|
|
// { code: 'ar-YE', name: 'Arabic (Yemen)' },
|
|
|
|
],
|
|
|
|
en: [
|
2023-05-06 15:45:42 +00:00
|
|
|
// en.json contains en-US translations
|
2023-05-15 12:35:43 +00:00
|
|
|
{ country: true, code: 'en-US', name: 'English (US)' },
|
2023-01-24 14:42:57 +00:00
|
|
|
{ code: 'en-GB', name: 'English (UK)' },
|
|
|
|
],
|
2023-02-25 21:24:03 +00:00
|
|
|
ca: [
|
2023-05-06 15:45:42 +00:00
|
|
|
// ca.json contains ca-ES translations
|
2023-02-25 21:24:03 +00:00
|
|
|
// { code: 'ca-AD', name: 'Català (Andorra)' },
|
2023-05-15 12:35:43 +00:00
|
|
|
{ country: true, code: 'ca-ES', name: 'Català (Espanya)' },
|
2023-02-25 21:24:03 +00:00
|
|
|
{ code: 'ca-valencia', name: 'Català (valencià)' },
|
|
|
|
// { code: 'ca-FR', name: 'Català (França)' },
|
|
|
|
// { code: 'ca-IT', name: 'Català (Itàlia)' },
|
|
|
|
],
|
2023-01-24 14:42:57 +00:00
|
|
|
es: [
|
2023-05-06 15:45:42 +00:00
|
|
|
// es.json contains es-ES translations
|
2023-01-24 14:42:57 +00:00
|
|
|
// { code: 'es-AR', name: 'Español (Argentina)' },
|
|
|
|
// { code: 'es-BO', name: 'Español (Bolivia)' },
|
|
|
|
// { code: 'es-CL', name: 'Español (Chile)' },
|
|
|
|
// { code: 'es-CO', name: 'Español (Colombia)' },
|
|
|
|
// { code: 'es-CR', name: 'Español (Costa Rica)' },
|
|
|
|
// { code: 'es-DO', name: 'Español (República Dominicana)' },
|
|
|
|
// { code: 'es-EC', name: 'Español (Ecuador)' },
|
2023-05-15 12:35:43 +00:00
|
|
|
{ country: true, code: 'es-ES', name: 'Español (España)' },
|
2023-01-24 22:35:26 +00:00
|
|
|
// TODO: Support es-419, if we include spanish country variants remove also fix on utils/language.ts module
|
2023-01-24 14:42:57 +00:00
|
|
|
{ code: 'es-419', name: 'Español (Latinoamérica)' },
|
|
|
|
// { code: 'es-GT', name: 'Español (Guatemala)' },
|
|
|
|
// { code: 'es-HN', name: 'Español (Honduras)' },
|
|
|
|
// { code: 'es-MX', name: 'Español (México)' },
|
|
|
|
// { code: 'es-NI', name: 'Español (Nicaragua)' },
|
|
|
|
// { code: 'es-PA', name: 'Español (Panamá)' },
|
|
|
|
// { code: 'es-PE', name: 'Español (Perú)' },
|
|
|
|
// { code: 'es-PR', name: 'Español (Puerto Rico)' },
|
|
|
|
// { code: 'es-SV', name: 'Español (El Salvador)' },
|
|
|
|
// { code: 'es-US', name: 'Español (Estados Unidos)' },
|
|
|
|
// { code: 'es-UY', name: 'Español (Uruguay)' },
|
|
|
|
// { code: 'es-VE', name: 'Español (Venezuela)' },
|
|
|
|
],
|
2023-05-06 15:45:42 +00:00
|
|
|
pt: [
|
|
|
|
// pt.json contains pt-PT translations
|
2023-05-15 12:35:43 +00:00
|
|
|
{ country: true, code: 'pt-PT', name: 'Português (Portugal)' },
|
2023-05-06 15:45:42 +00:00
|
|
|
{ code: 'pt-BR', name: 'Português (Brasil)' },
|
|
|
|
],
|
2023-01-24 14:42:57 +00:00
|
|
|
}
|
|
|
|
|
2023-01-01 14:29:11 +00:00
|
|
|
const locales: LocaleObjectData[] = [
|
2022-12-02 12:54:09 +00:00
|
|
|
{
|
2023-01-23 15:34:31 +00:00
|
|
|
code: 'en',
|
|
|
|
file: 'en.json',
|
|
|
|
name: 'English',
|
2022-12-02 12:54:09 +00:00
|
|
|
},
|
2023-01-14 10:45:12 +00:00
|
|
|
({
|
2023-01-23 15:34:31 +00:00
|
|
|
code: 'ar',
|
|
|
|
file: 'ar.json',
|
2023-01-14 10:45:12 +00:00
|
|
|
name: 'العربية',
|
|
|
|
dir: 'rtl',
|
|
|
|
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]
|
|
|
|
},
|
|
|
|
} satisfies LocaleObjectData),
|
2024-03-04 20:28:57 +00:00
|
|
|
({
|
|
|
|
code: 'ckb',
|
|
|
|
file: 'ckb.json',
|
|
|
|
name: 'کوردیی ناوەندی',
|
|
|
|
dir: 'rtl',
|
|
|
|
pluralRule: (choice: number) => {
|
|
|
|
const name = new Intl.PluralRules('ckb').select(choice)
|
|
|
|
return { zero: 0, one: 1, two: 2, few: 3, many: 4, other: 5 }[name]
|
|
|
|
},
|
|
|
|
} satisfies LocaleObjectData),
|
2024-03-04 19:59:03 +00:00
|
|
|
({
|
|
|
|
code: 'fa-IR',
|
|
|
|
file: 'fa-IR.json',
|
|
|
|
name: 'فارسی',
|
|
|
|
dir: 'rtl',
|
|
|
|
pluralRule: (choice: number) => {
|
|
|
|
const name = new Intl.PluralRules('fa-IR').select(choice)
|
|
|
|
return { zero: 0, one: 1, two: 2, few: 3, many: 4, other: 5 }[name]
|
|
|
|
},
|
|
|
|
} satisfies LocaleObjectData),
|
2023-02-25 21:24:03 +00:00
|
|
|
{
|
|
|
|
code: 'ca',
|
|
|
|
file: 'ca.json',
|
|
|
|
name: 'Català',
|
|
|
|
},
|
2022-12-02 12:54:09 +00:00
|
|
|
{
|
|
|
|
code: 'de-DE',
|
|
|
|
file: 'de-DE.json',
|
|
|
|
name: 'Deutsch',
|
|
|
|
},
|
2023-09-15 21:25:34 +00:00
|
|
|
{
|
|
|
|
code: 'hu-HU',
|
|
|
|
file: 'hu-HU.json',
|
|
|
|
name: 'Magyar',
|
|
|
|
},
|
2022-12-02 12:54:09 +00:00
|
|
|
{
|
|
|
|
code: 'zh-CN',
|
|
|
|
file: 'zh-CN.json',
|
|
|
|
name: '简体中文',
|
|
|
|
},
|
2022-12-31 04:07:11 +00:00
|
|
|
{
|
|
|
|
code: 'zh-TW',
|
|
|
|
file: 'zh-TW.json',
|
2023-01-17 11:46:50 +00:00
|
|
|
name: '繁體中文',
|
2022-12-31 04:07:11 +00:00
|
|
|
},
|
2022-12-02 12:54:09 +00:00
|
|
|
{
|
|
|
|
code: 'ja-JP',
|
|
|
|
file: 'ja-JP.json',
|
|
|
|
name: '日本語',
|
|
|
|
},
|
2023-01-04 20:10:09 +00:00
|
|
|
{
|
|
|
|
code: 'nl-NL',
|
|
|
|
file: 'nl-NL.json',
|
|
|
|
name: 'Nederlands',
|
|
|
|
},
|
2022-12-02 12:54:09 +00:00
|
|
|
{
|
2023-01-23 15:34:31 +00:00
|
|
|
code: 'es',
|
|
|
|
file: 'es.json',
|
2022-12-02 12:54:09 +00:00
|
|
|
name: 'Español',
|
|
|
|
},
|
2023-02-18 15:40:28 +00:00
|
|
|
{
|
|
|
|
code: 'eu-ES',
|
|
|
|
file: 'eu-ES.json',
|
|
|
|
name: 'Euskara',
|
|
|
|
},
|
2022-12-02 20:27:58 +00:00
|
|
|
{
|
|
|
|
code: 'fr-FR',
|
|
|
|
file: 'fr-FR.json',
|
|
|
|
name: 'Français',
|
|
|
|
},
|
2023-01-23 22:29:48 +00:00
|
|
|
{
|
|
|
|
code: 'ru-RU',
|
|
|
|
file: 'ru-RU.json',
|
|
|
|
name: 'Русский',
|
2023-01-24 08:27:13 +00:00
|
|
|
pluralRule: (choice: number) => {
|
|
|
|
const name = new Intl.PluralRules('ru-RU').select(choice)
|
|
|
|
return { zero: 2 /* not used */, one: 0, two: 1 /* not used */, few: 1, many: 2, other: 3 }[name]
|
|
|
|
},
|
2023-01-23 22:29:48 +00:00
|
|
|
},
|
2023-01-08 19:35:48 +00: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-14 21:19:38 +00:00
|
|
|
{
|
|
|
|
code: 'cs-CZ',
|
|
|
|
file: 'cs-CZ.json',
|
|
|
|
name: 'Česky',
|
2022-12-26 15:12:04 +00:00
|
|
|
},
|
2023-01-22 11:13:33 +00:00
|
|
|
{
|
|
|
|
code: 'pl-PL',
|
|
|
|
file: 'pl-PL.json',
|
|
|
|
name: 'Polski',
|
|
|
|
pluralRule: (choice: number) => {
|
|
|
|
if (choice === 0)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
const name = new Intl.PluralRules('pl-PL').select(choice)
|
|
|
|
return { zero: 0, one: 1, two: 0 /* not used */, few: 2, many: 3, other: 4 }[name]
|
|
|
|
},
|
|
|
|
},
|
2023-01-15 15:19:02 +00:00
|
|
|
{
|
2023-05-06 15:45:42 +00:00
|
|
|
code: 'pt',
|
|
|
|
file: 'pt.json',
|
2023-01-15 15:19:02 +00:00
|
|
|
name: 'Português',
|
|
|
|
},
|
2023-01-14 09:56:46 +00:00
|
|
|
{
|
|
|
|
code: 'tr-TR',
|
|
|
|
file: 'tr-TR.json',
|
|
|
|
name: 'Türkçe',
|
|
|
|
},
|
2023-01-16 16:44:27 +00:00
|
|
|
{
|
|
|
|
code: 'id-ID',
|
|
|
|
file: 'id-ID.json',
|
|
|
|
name: 'Indonesia',
|
|
|
|
},
|
2023-01-22 07:19:16 +00:00
|
|
|
{
|
|
|
|
code: 'fi-FI',
|
|
|
|
file: 'fi-FI.json',
|
2023-08-24 11:08:56 +00:00
|
|
|
name: 'Suomi',
|
2023-01-22 07:19:16 +00:00
|
|
|
},
|
2023-01-25 05:50:20 +00:00
|
|
|
{
|
|
|
|
code: 'gl-ES',
|
|
|
|
file: 'gl-ES.json',
|
|
|
|
name: 'Galego',
|
|
|
|
},
|
2023-04-16 19:42:32 +00:00
|
|
|
{
|
|
|
|
code: 'ko-KR',
|
|
|
|
file: 'ko-KR.json',
|
|
|
|
name: '한국어',
|
|
|
|
},
|
2023-04-23 18:10:24 +00:00
|
|
|
{
|
|
|
|
code: 'it-IT',
|
|
|
|
file: 'it-IT.json',
|
|
|
|
name: 'Italiano',
|
|
|
|
},
|
2023-08-09 11:51:07 +00:00
|
|
|
{
|
|
|
|
code: 'th-TH',
|
|
|
|
file: 'th-TH.json',
|
|
|
|
name: 'ไทย',
|
|
|
|
},
|
2023-05-01 09:55:49 +00:00
|
|
|
{
|
|
|
|
code: 'tl-PH',
|
|
|
|
file: 'tl-PH.json',
|
|
|
|
name: 'Tagalog',
|
|
|
|
},
|
2023-05-22 12:33:30 +00:00
|
|
|
{
|
|
|
|
code: 'vi-VN',
|
|
|
|
file: 'vi-VN.json',
|
|
|
|
name: 'Tiếng Việt',
|
|
|
|
},
|
2023-01-23 15:34:31 +00:00
|
|
|
]
|
|
|
|
|
2023-03-30 19:01:24 +00:00
|
|
|
function buildLocales() {
|
2023-01-23 15:34:31 +00:00
|
|
|
const useLocales = Object.values(locales).reduce((acc, data) => {
|
|
|
|
const locales = countryLocaleVariants[data.code]
|
|
|
|
if (locales) {
|
|
|
|
locales.forEach((l) => {
|
|
|
|
const entry: LocaleObjectData = {
|
|
|
|
...data,
|
|
|
|
code: l.code,
|
|
|
|
name: l.name,
|
2024-02-24 16:46:14 +00:00
|
|
|
files: [data.file as string, `${l.code}.json`],
|
2023-01-23 15:34:31 +00:00
|
|
|
}
|
|
|
|
delete entry.file
|
|
|
|
acc.push(entry)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
acc.push(data)
|
|
|
|
}
|
|
|
|
return acc
|
|
|
|
}, <LocaleObjectData[]>[])
|
|
|
|
|
|
|
|
return useLocales.sort((a, b) => a.code.localeCompare(b.code))
|
|
|
|
}
|
2022-12-02 12:54:09 +00:00
|
|
|
|
2023-02-11 16:15:08 +00:00
|
|
|
export const currentLocales = buildLocales()
|
2023-01-23 15:34:31 +00:00
|
|
|
|
2024-02-24 16:46:14 +00:00
|
|
|
export const datetimeFormats = Object.values(currentLocales).reduce((acc, data) => {
|
2023-01-01 14:29:11 +00:00
|
|
|
const dateTimeFormats = data.dateTimeFormats
|
|
|
|
if (dateTimeFormats) {
|
|
|
|
acc[data.code] = { ...dateTimeFormats }
|
|
|
|
delete data.dateTimeFormats
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
acc[data.code] = {
|
2023-01-03 17:24:39 +00:00
|
|
|
shortDate: {
|
|
|
|
dateStyle: 'short',
|
|
|
|
},
|
2023-01-01 14:29:11 +00:00
|
|
|
short: {
|
|
|
|
dateStyle: 'short',
|
|
|
|
timeStyle: 'short',
|
|
|
|
},
|
|
|
|
long: {
|
|
|
|
dateStyle: 'long',
|
|
|
|
timeStyle: 'medium',
|
|
|
|
},
|
|
|
|
}
|
2022-12-02 12:54:09 +00:00
|
|
|
}
|
2023-01-01 14:29:11 +00:00
|
|
|
|
2022-12-02 12:54:09 +00:00
|
|
|
return acc
|
|
|
|
}, <DateTimeFormats>{})
|
|
|
|
|
2024-02-24 16:46:14 +00:00
|
|
|
export const numberFormats = Object.values(currentLocales).reduce((acc, data) => {
|
2023-01-01 14:29:11 +00:00
|
|
|
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 19:31:14 +00:00
|
|
|
notation: 'compact',
|
|
|
|
compactDisplay: 'short',
|
2023-01-01 14:29:11 +00:00
|
|
|
maximumFractionDigits: 1,
|
|
|
|
},
|
|
|
|
millionCounting: {
|
2023-01-01 19:31:14 +00:00
|
|
|
notation: 'compact',
|
|
|
|
compactDisplay: 'short',
|
2023-01-01 14:29:11 +00:00
|
|
|
maximumFractionDigits: 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc
|
|
|
|
}, <NumberFormats>{})
|
|
|
|
|
2024-02-24 16:46:14 +00:00
|
|
|
export const pluralRules = Object.values(currentLocales).reduce((acc, data) => {
|
2023-01-01 14:29:11 +00:00
|
|
|
const pluralRule = data.pluralRule
|
|
|
|
if (pluralRule) {
|
|
|
|
acc[data.code] = pluralRule
|
|
|
|
delete data.pluralRule
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc
|
|
|
|
}, <PluralizationRules>{})
|