Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions app/pages/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ const { locale, locales, setLocale } = useI18n()
const colorMode = useColorMode()
const { currentLocaleStatus, isSourceLocale } = useI18nStatus()

const availableLocales = computed(() =>
locales.value.map(l => (typeof l === 'string' ? { code: l, name: l } : l)),
)

// Escape to go back (but not when focused on form elements)
onKeyStroke('Escape', e => {
const target = e.target as HTMLElement
Expand Down Expand Up @@ -211,7 +207,7 @@ defineOgImageComponent('Default', {
class="w-full sm:w-auto min-w-48 bg-bg border border-border rounded-md px-3 py-2 text-sm text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 cursor-pointer"
@change="setLocale(($event.target as HTMLSelectElement).value as typeof locale)"
>
<option v-for="loc in availableLocales" :key="loc.code" :value="loc.code">
<option v-for="loc in locales" :key="loc.code" :value="loc.code" :lang="loc.code">
{{ loc.name }}
</option>
</select>
Expand Down
18 changes: 12 additions & 6 deletions config/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ export const countryLocaleVariants: Record<string, (LocaleObjectData & { country
],*/
}

const locales: (Omit<LocaleObjectData, 'code'> & { code: string })[] = [
const locales: (LocaleObjectData | (Omit<LocaleObjectData, 'code'> & { code: string }))[] = [
{
code: 'en',
file: 'en.json',
name: 'English',
},
{
code: 'ar-EG',
code: 'ar',
file: 'ar.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]
},
} satisfies LocaleObjectData,
},
/*{
code: 'ckb',
file: 'ckb.json',
Expand All @@ -103,7 +103,7 @@ const locales: (Omit<LocaleObjectData, 'code'> & { code: string })[] = [
const name = new Intl.PluralRules('ckb').select(choice)
return { zero: 0, one: 1, two: 2, few: 3, many: 4, other: 5 }[name]
},
} satisfies LocaleObjectData,
},
{
code: 'fa-IR',
file: 'fa-IR.json',
Expand All @@ -113,7 +113,7 @@ const locales: (Omit<LocaleObjectData, 'code'> & { code: string })[] = [
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,
},
{
code: 'ca',
file: 'ca.json',
Expand Down Expand Up @@ -177,7 +177,7 @@ const locales: (Omit<LocaleObjectData, 'code'> & { code: string })[] = [
const name = new Intl.PluralRules('ru-RU').select(choice)
return { zero: 2, one: 0, two: 1, few: 1, many: 2, other: 3 }[name]
},
} satisfies LocaleObjectData,
},
/*{
code: 'ru-RU',
file: 'ru-RU.json',
Expand Down Expand Up @@ -278,6 +278,8 @@ const locales: (Omit<LocaleObjectData, 'code'> & { code: string })[] = [
},*/
]

const lunariaJSONFiles: Record<string, string> = {}

function buildLocales() {
const useLocales = Object.values(locales).reduce((acc, data) => {
const locales = countryLocaleVariants[data.code]
Expand All @@ -289,10 +291,12 @@ function buildLocales() {
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
Expand All @@ -303,6 +307,8 @@ function buildLocales() {

export const currentLocales = buildLocales()

export { lunariaJSONFiles }

export const datetimeFormats = Object.values(currentLocales).reduce((acc, data) => {
const dateTimeFormats = data.dateTimeFormats
if (dateTimeFormats) {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lunaria/lunaria.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createLunaria } from '@lunariajs/core'
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { Page } from './components.ts'
import { prepareJsonFiles } from './prepare-json-files.ts'
import { lunariaJSONFiles, prepareJsonFiles } from './prepare-json-files.ts'
import type { I18nStatus } from '../shared/types/i18n-status.ts'

await prepareJsonFiles()
Expand Down Expand Up @@ -61,7 +61,7 @@ const jsonStatus: I18nStatus = {
}

const completedKeys = totalKeys - missingKeys.length
const localeFilePath = `i18n/locales/${locale.lang}.json`
const localeFilePath = `i18n/locales/${lunariaJSONFiles[locale.lang]!}.json`

return {
lang: locale.lang,
Expand Down
4 changes: 3 additions & 1 deletion lunaria/prepare-json-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import type { Locale } from '@lunariajs/core'
import type { LocaleObject } from '@nuxtjs/i18n'
import * as path from 'node:path'
import * as fs from 'node:fs/promises'
import { currentLocales } from '../config/i18n.ts'
import { currentLocales, lunariaJSONFiles } from '../config/i18n.ts'
import { deepCopy } from '@intlify/shared'

const destFolder = path.resolve('lunaria/files')
const localesFolder = path.resolve('i18n/locales')

const defaultLocale = currentLocales.find(l => l.code === 'en-US')!
/** @public */
export { lunariaJSONFiles }
/** @public */
export const sourceLocale = {
label: defaultLocale.name,
lang: defaultLocale.code,
Expand Down