From 02e8540220440465e0c112338e5e689ad43bee19 Mon Sep 17 00:00:00 2001 From: userquin Date: Fri, 30 Jan 2026 19:19:05 +0100 Subject: [PATCH 1/2] fix: update i18n logic --- app/pages/settings.vue | 6 +----- config/i18n.ts | 18 ++++++++++++------ i18n/locales/en.json | 2 +- lunaria/files/{ar.json => ar-EG.json} | 0 lunaria/lunaria.ts | 5 +++-- lunaria/prepare-json-files.ts | 4 +++- 6 files changed, 20 insertions(+), 15 deletions(-) rename lunaria/files/{ar.json => ar-EG.json} (100%) diff --git a/app/pages/settings.vue b/app/pages/settings.vue index c7ce520573..171d6e3c20 100644 --- a/app/pages/settings.vue +++ b/app/pages/settings.vue @@ -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 @@ -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)" > - diff --git a/config/i18n.ts b/config/i18n.ts index f57b21e34e..552a137f15 100644 --- a/config/i18n.ts +++ b/config/i18n.ts @@ -78,14 +78,14 @@ export const countryLocaleVariants: Record & { code: string })[] = [ +const locales: (LocaleObjectData | (Omit & { code: string }))[] = [ { code: 'en', file: 'en.json', name: 'English', }, { - code: 'ar-EG', + code: 'ar', file: 'ar.json', name: 'العربية', dir: 'rtl', @@ -93,7 +93,7 @@ const locales: (Omit & { code: string })[] = [ 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', @@ -103,7 +103,7 @@ const locales: (Omit & { 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', @@ -113,7 +113,7 @@ const locales: (Omit & { 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', @@ -177,7 +177,7 @@ const locales: (Omit & { 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', @@ -278,6 +278,8 @@ const locales: (Omit & { code: string })[] = [ },*/ ] +const lunariaJSONFiles: Record = {} + function buildLocales() { const useLocales = Object.values(locales).reduce((acc, data) => { const locales = countryLocaleVariants[data.code] @@ -289,10 +291,12 @@ function buildLocales() { name: l.name, files: [data.file as string, `${l.code}.json`], } + lunariaJSONFiles[data.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 @@ -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) { diff --git a/i18n/locales/en.json b/i18n/locales/en.json index e0ba7476e0..8a6cc33a5a 100644 --- a/i18n/locales/en.json +++ b/i18n/locales/en.json @@ -329,7 +329,7 @@ "size": "Size", "deps": "Deps", "updated": "Updated", - "get_started": "Get started", + "install": "Install", "readme": "Readme", "maintainers": "Maintainers", "keywords": "Keywords", diff --git a/lunaria/files/ar.json b/lunaria/files/ar-EG.json similarity index 100% rename from lunaria/files/ar.json rename to lunaria/files/ar-EG.json diff --git a/lunaria/lunaria.ts b/lunaria/lunaria.ts index 2bcc0a693f..138489009b 100644 --- a/lunaria/lunaria.ts +++ b/lunaria/lunaria.ts @@ -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() @@ -61,7 +61,8 @@ const jsonStatus: I18nStatus = { } const completedKeys = totalKeys - missingKeys.length - const localeFilePath = `i18n/locales/${locale.lang}.json` + const localeFilePath = `i18n/locales/${lunariaJSONFiles[locale.lang]!}.json` + console.log(localeFilePath) return { lang: locale.lang, diff --git a/lunaria/prepare-json-files.ts b/lunaria/prepare-json-files.ts index 470f0f1c43..54b7f085dd 100644 --- a/lunaria/prepare-json-files.ts +++ b/lunaria/prepare-json-files.ts @@ -2,7 +2,7 @@ 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') @@ -10,6 +10,8 @@ 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, From b94364302a55500ef16257dc18774ab66b85784a Mon Sep 17 00:00:00 2001 From: userquin Date: Fri, 30 Jan 2026 19:41:20 +0100 Subject: [PATCH 2/2] chore: update logic --- config/i18n.ts | 2 +- i18n/locales/en.json | 2 +- lunaria/files/en-US.json | 2 +- lunaria/lunaria.ts | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/config/i18n.ts b/config/i18n.ts index 552a137f15..450c6ccec4 100644 --- a/config/i18n.ts +++ b/config/i18n.ts @@ -291,7 +291,7 @@ function buildLocales() { name: l.name, files: [data.file as string, `${l.code}.json`], } - lunariaJSONFiles[data.code] = l.country ? (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) }) diff --git a/i18n/locales/en.json b/i18n/locales/en.json index 8a6cc33a5a..e0ba7476e0 100644 --- a/i18n/locales/en.json +++ b/i18n/locales/en.json @@ -329,7 +329,7 @@ "size": "Size", "deps": "Deps", "updated": "Updated", - "install": "Install", + "get_started": "Get started", "readme": "Readme", "maintainers": "Maintainers", "keywords": "Keywords", diff --git a/lunaria/files/en-US.json b/lunaria/files/en-US.json index 8a6cc33a5a..e0ba7476e0 100644 --- a/lunaria/files/en-US.json +++ b/lunaria/files/en-US.json @@ -329,7 +329,7 @@ "size": "Size", "deps": "Deps", "updated": "Updated", - "install": "Install", + "get_started": "Get started", "readme": "Readme", "maintainers": "Maintainers", "keywords": "Keywords", diff --git a/lunaria/lunaria.ts b/lunaria/lunaria.ts index 138489009b..3b947d5e93 100644 --- a/lunaria/lunaria.ts +++ b/lunaria/lunaria.ts @@ -62,7 +62,6 @@ const jsonStatus: I18nStatus = { const completedKeys = totalKeys - missingKeys.length const localeFilePath = `i18n/locales/${lunariaJSONFiles[locale.lang]!}.json` - console.log(localeFilePath) return { lang: locale.lang,