1
0
mirror of https://github.com/elk-zone/elk synced 2024-11-30 15:58:06 +09:00
elk/config/i18n.ts
Vjacheslav Trushkin 727d05915f
fix: layout fixes for RTL languages (#591)
* fix: rtl arrows on settings page

* fix: border on settings page for RTL languages

* fix: RTL fixes for logo, search box and logout icon

* fix: RTL layout bugs in conversations

* chore: remove rtl setting icon

* improve arabic locale

* add new entries to arabic locale

* chore: include number format

* fix: RTL layout on several pages

* fix: RTL layout of account header and sign in modal

* fix: always display account handle in LTR

* fix: move character counter in publish widget to left side for RTL

* fix: remove border-ss-none unocss rule

* fix: many RTL fixes

* fix: RTL fixes for many pages

* fix: use viewer's direction in all content

* chore: use new arabic plural rules

* chore: flip arrow on main content header

* chore: fix StatusPoll and show_new_items for zh-TW

* chore: StatusPoll tooltip on bottom

* chore: add `en` variants to i18n conf

* chore: update entry to use new plural rule

* fix: automatic content direction for status

* fix: direction for account handle

* fix: direction of polls

Co-authored-by: userquin <userquin@gmail.com>
Co-authored-by: Jean-Paul Khawam <jeanpaulkhawam@protonmail.com>
Co-authored-by: Daniel Roe <daniel@roe.dev>
2023-01-01 15:29:11 +01:00

149 lines
3.1 KiB
TypeScript

import type { NuxtI18nOptions } from '@nuxtjs/i18n'
import type { DateTimeFormats, NumberFormats, PluralizationRule, PluralizationRules } from '@intlify/core-base'
import type { LocaleObject } from '#i18n'
interface LocaleObjectData extends LocaleObject {
numberFormats?: NumberFormats
dateTimeFormats?: DateTimeFormats
pluralRule?: PluralizationRule
}
// @ts-expect-error dir is there, ts complaining
const locales: LocaleObjectData[] = [
{
code: 'en-US',
file: 'en-US.json',
name: 'English (US)',
},
{
code: 'en-GB',
file: 'en-GB.json',
name: 'English (UK)',
},
{
code: 'de-DE',
file: 'de-DE.json',
name: 'Deutsch',
},
{
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: 'es-ES',
file: 'es-ES.json',
name: 'Español',
},
{
code: 'fr-FR',
file: 'fr-FR.json',
name: 'Français',
},
{
code: 'cs-CZ',
file: 'cs-CZ.json',
name: 'Česky',
},
{
code: 'ar-EG',
file: 'ar-EG.json',
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]
},
},
].sort((a, b) => a.code.localeCompare(b.code))
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] = {
short: {
dateStyle: 'short',
timeStyle: 'short',
},
long: {
dateStyle: 'long',
timeStyle: 'medium',
},
}
}
return acc
}, <DateTimeFormats>{})
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: {
style: 'decimal',
maximumFractionDigits: 1,
},
millionCounting: {
style: 'decimal',
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>{})
export const i18n: NuxtI18nOptions = {
locales,
strategy: 'no_prefix',
detectBrowserLanguage: false,
langDir: 'locales',
defaultLocale: 'en-US',
vueI18n: {
fallbackLocale: 'en-US',
fallbackWarn: false,
missingWarn: false,
datetimeFormats,
numberFormats,
pluralRules,
},
lazy: true,
}