Something went wrong. Try again.
[READ-ONLY]
a fast, modern browser for the npm registry forked from npmx.dev/npmx.dev
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443import type { DateTimeFormats, NumberFormats, PluralizationRule, PluralizationRules,} from '@intlify/core-base'import type { LocaleObject } from '@nuxtjs/i18n'
interface LocaleObjectData extends LocaleObject { numberFormats?: NumberFormats dateTimeFormats?: DateTimeFormats pluralRule?: PluralizationRule}
export const countryLocaleVariants: Record<string, (LocaleObjectData & { country?: boolean })[]> = { ar: [ // ar.json contains ar-EG translations // { code: 'ar-DZ', name: 'Arabic (Algeria)' }, // { code: 'ar-BH', name: 'Arabic (Bahrain)' }, { country: true, code: 'ar-EG', name: 'العربية' }, // { 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: [ // en.json contains en-US translations { country: true, code: 'en-US', name: 'English (US)' }, // { code: 'en-CA', name: 'English (Canada)' }, { code: 'en-GB', name: 'English (UK)' }, ], /*ca: [ // ca.json contains ca-ES translations // { code: 'ca-AD', name: 'Català (Andorra)' }, { country: true, code: 'ca-ES', name: 'Català (Espanya)' }, { code: 'ca-valencia', name: 'Català (valencià)' }, // { code: 'ca-FR', name: 'Català (França)' }, // { code: 'ca-IT', name: 'Català (Itàlia)' }, ],*/ es: [ // es.json contains es-ES translations // { 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)' }, { country: true, code: 'es-ES', name: 'Español (España)' }, // TODO: Support es-419, if we include spanish country variants remove also fix on utils/language.ts module { 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)' }, ], /*pt: [ // pt.json contains pt-PT translations { country: true, code: 'pt-PT', name: 'Português (Portugal)' }, { code: 'pt-BR', name: 'Português (Brasil)' }, ],*/}
function createPluralRule(locale: string, mapping: Record<string, number>) { return (choice: number, choicesLength: number) => { const name = new Intl.PluralRules(locale).select(choice) const plural = mapping[name] || 0
// In case translation doesn't have all plural forms, use the last available form if (plural > choicesLength - 1) { if (import.meta.dev) { // oxlint-disable-next-line no-console -- warn logging console.warn( `Plural form index ${plural} for choice ${choice} exceeds available forms ${choicesLength} for locale ${locale}.`, ) } return choicesLength - 1 }
return plural }}
const locales: (LocaleObjectData | (Omit<LocaleObjectData, 'code'> & { code: string }))[] = [ { code: 'en', file: 'en.json', name: 'English', }, { code: 'ar', file: 'ar.json', name: 'العربية', dir: 'rtl', pluralRule: createPluralRule('ar-EG', { zero: 0, one: 1, two: 2, few: 3, many: 4, other: 5 }), }, { code: 'az-AZ', file: 'az-AZ.json', name: 'Azərbaycanca', }, { code: 'bn-IN', file: 'bn-IN.json', name: 'বাংলা', }, { code: 'bg-BG', file: 'bg-BG.json', name: 'Български', pluralRule: createPluralRule('bg-BG', { zero: 1, one: 0, two: 1, few: 1, many: 1, other: 1 }), }, /*{ 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] }, }, { 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] }, }, { code: 'ca', file: 'ca.json', name: 'Català', }, { code: 'el-GR', file: 'el-GR.json', name: 'Ελληνικά', },*/ { code: 'de-DE', file: 'de-DE.json', name: 'Deutsch', }, { code: 'hi-IN', file: 'hi-IN.json', name: 'हिंदी', }, { code: 'te-IN', file: 'te-IN.json', name: 'తెలుగు', }, { code: 'mr-IN', file: 'mr-IN.json', name: 'मराठी', }, { code: 'hu-HU', file: 'hu-HU.json', name: 'Magyar', pluralRule: createPluralRule('hu-HU', { zero: 0, one: 0, two: 1, few: 1, many: 1, other: 1 }), }, { code: 'zh-CN', file: 'zh-CN.json', name: '简体中文', }, { code: 'zh-TW', file: 'zh-TW.json', name: '繁體中文', }, { code: 'ja-JP', file: 'ja-JP.json', name: '日本語', }, { code: 'ne-NP', file: 'ne-NP.json', name: 'नेपाली', }, /*{ code: 'nl-NL', file: 'nl-NL.json', name: 'Nederlands', },*/ { code: 'es', file: 'es.json', name: 'Español', }, /*{ code: 'eu-ES', file: 'eu-ES.json', name: 'Euskara', },*/ { code: 'fr-FR', file: 'fr-FR.json', name: 'Français', }, { code: 'ru-RU', file: 'ru-RU.json', name: 'Русский', pluralRule: createPluralRule('ru-RU', { zero: 2, one: 0, two: 1, few: 1, many: 2, other: 3 }), }, { code: 'uk-UA', file: 'uk-UA.json', name: 'Українська', pluralRule: createPluralRule('uk-UA', { zero: 0, one: 1, two: 0, few: 2, many: 3, other: 4 }), }, /*{ code: 'ru-RU', file: 'ru-RU.json', name: 'Русский', 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] }, },*/ { code: 'cs-CZ', file: 'cs-CZ.json', name: 'Čeština', pluralRule: createPluralRule('cs-CZ', { zero: 2, one: 0, two: 1, few: 1, many: 2, other: 2 }), } /* { 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] }, }, { code: 'pt', file: 'pt.json', name: 'Português', }, { code: 'tr-TR', file: 'tr-TR.json', name: 'Türkçe', }, { code: 'id-ID', file: 'id-ID.json', name: 'Indonesia', }, { code: 'fi', file: 'fi.json', name: 'Suomi', }, { code: 'gl-ES', file: 'gl-ES.json', name: 'Galego', }, { code: 'ko-KR', file: 'ko-KR.json', name: '한국어', },*/, { code: 'id-ID', file: 'id-ID.json', name: 'Indonesia', }, { code: 'it-IT', file: 'it-IT.json', name: 'Italiano', }, { code: 'pl-PL', file: 'pl-PL.json', name: 'Polski', pluralRule: createPluralRule('pl-PL', { zero: 0, one: 1, two: 0, few: 2, many: 3, other: 4 }), }, { code: 'pt-BR', file: 'pt-BR.json', name: 'Português (Brasil)', }, /*{ code: 'sv', file: 'sv.json', name: 'Svenska', }, { code: 'th-TH', file: 'th-TH.json', name: 'ไทย', }, { code: 'tl-PH', file: 'tl-PH.json', name: 'Tagalog', }, { code: 'vi-VN', file: 'vi-VN.json', name: 'Tiếng Việt', }, { code: 'cy', file: 'cy.json', name: 'Cymraeg', },*/ { code: 'nb-NO', file: 'nb-NO.json', name: 'Norsk (Bokmål)', },]
const lunariaJSONFiles: Record<string, string> = {}
function buildLocales() { 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, files: [data.file as string, `${l.code}.json`], } lunariaJSONFiles[l.code] = l.country ? (data.file as string) : `${l.code}.json` delete entry.file acc.push(entry) }) } else { lunariaJSONFiles[data.code] = data.file as string acc.push(data as LocaleObjectData) } return acc }, [] as LocaleObjectData[])
return useLocales.sort((a, b) => a.code.localeCompare(b.code))}
export const currentLocales = buildLocales()
export { lunariaJSONFiles }
export const datetimeFormats = Object.values(currentLocales).reduce((acc, data) => { const dateTimeFormats = data.dateTimeFormats if (dateTimeFormats) { acc[data.code] = { ...dateTimeFormats } delete data.dateTimeFormats } else { acc[data.code] = { shortDate: { dateStyle: 'short', }, short: { dateStyle: 'short', timeStyle: 'short', }, long: { dateStyle: 'long', timeStyle: 'medium', }, } }
return acc}, {} as DateTimeFormats)
export const numberFormats = Object.values(currentLocales).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: { notation: 'compact', compactDisplay: 'short', maximumFractionDigits: 1, }, millionCounting: { notation: 'compact', compactDisplay: 'short', maximumFractionDigits: 2, }, } }
return acc}, {} as NumberFormats)
export const pluralRules = Object.values(currentLocales).reduce((acc, data) => { const pluralRule = data.pluralRule if (pluralRule) { acc[data.code] = pluralRule delete data.pluralRule }
return acc}, {} as PluralizationRules)