[READ-ONLY] a fast, modern browser for the npm registry
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(i18n): update i18n logic (#434)

Co-authored-by: Daniel Roe <daniel@roe.dev>

authored by

Joaquín Sánchez
Daniel Roe
and committed by
GitHub
d171b388 b26b3c22

+18 -14
+1 -5
app/pages/settings.vue
··· 5 5 const colorMode = useColorMode() 6 6 const { currentLocaleStatus, isSourceLocale } = useI18nStatus() 7 7 8 - const availableLocales = computed(() => 9 - locales.value.map(l => (typeof l === 'string' ? { code: l, name: l } : l)), 10 - ) 11 - 12 8 // Escape to go back (but not when focused on form elements) 13 9 onKeyStroke('Escape', e => { 14 10 const target = e.target as HTMLElement ··· 211 207 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" 212 208 @change="setLocale(($event.target as HTMLSelectElement).value as typeof locale)" 213 209 > 214 - <option v-for="loc in availableLocales" :key="loc.code" :value="loc.code"> 210 + <option v-for="loc in locales" :key="loc.code" :value="loc.code" :lang="loc.code"> 215 211 {{ loc.name }} 216 212 </option> 217 213 </select>
+12 -6
config/i18n.ts
··· 78 78 ],*/ 79 79 } 80 80 81 - const locales: (Omit<LocaleObjectData, 'code'> & { code: string })[] = [ 81 + const locales: (LocaleObjectData | (Omit<LocaleObjectData, 'code'> & { code: string }))[] = [ 82 82 { 83 83 code: 'en', 84 84 file: 'en.json', 85 85 name: 'English', 86 86 }, 87 87 { 88 - code: 'ar-EG', 88 + code: 'ar', 89 89 file: 'ar.json', 90 90 name: 'العربية', 91 91 dir: 'rtl', ··· 93 93 const name = new Intl.PluralRules('ar-EG').select(choice) 94 94 return { zero: 0, one: 1, two: 2, few: 3, many: 4, other: 5 }[name] 95 95 }, 96 - } satisfies LocaleObjectData, 96 + }, 97 97 /*{ 98 98 code: 'ckb', 99 99 file: 'ckb.json', ··· 103 103 const name = new Intl.PluralRules('ckb').select(choice) 104 104 return { zero: 0, one: 1, two: 2, few: 3, many: 4, other: 5 }[name] 105 105 }, 106 - } satisfies LocaleObjectData, 106 + }, 107 107 { 108 108 code: 'fa-IR', 109 109 file: 'fa-IR.json', ··· 113 113 const name = new Intl.PluralRules('fa-IR').select(choice) 114 114 return { zero: 0, one: 1, two: 2, few: 3, many: 4, other: 5 }[name] 115 115 }, 116 - } satisfies LocaleObjectData, 116 + }, 117 117 { 118 118 code: 'ca', 119 119 file: 'ca.json', ··· 177 177 const name = new Intl.PluralRules('ru-RU').select(choice) 178 178 return { zero: 2, one: 0, two: 1, few: 1, many: 2, other: 3 }[name] 179 179 }, 180 - } satisfies LocaleObjectData, 180 + }, 181 181 /*{ 182 182 code: 'ru-RU', 183 183 file: 'ru-RU.json', ··· 278 278 },*/ 279 279 ] 280 280 281 + const lunariaJSONFiles: Record<string, string> = {} 282 + 281 283 function buildLocales() { 282 284 const useLocales = Object.values(locales).reduce((acc, data) => { 283 285 const locales = countryLocaleVariants[data.code] ··· 289 291 name: l.name, 290 292 files: [data.file as string, `${l.code}.json`], 291 293 } 294 + lunariaJSONFiles[l.code] = l.country ? (data.file as string) : `${l.code}.json` 292 295 delete entry.file 293 296 acc.push(entry) 294 297 }) 295 298 } else { 299 + lunariaJSONFiles[data.code] = data.file as string 296 300 acc.push(data as LocaleObjectData) 297 301 } 298 302 return acc ··· 302 306 } 303 307 304 308 export const currentLocales = buildLocales() 309 + 310 + export { lunariaJSONFiles } 305 311 306 312 export const datetimeFormats = Object.values(currentLocales).reduce((acc, data) => { 307 313 const dateTimeFormats = data.dateTimeFormats
lunaria/files/ar.json lunaria/files/ar-EG.json
+2 -2
lunaria/lunaria.ts
··· 1 1 import { createLunaria } from '@lunariajs/core' 2 2 import { mkdirSync, readFileSync, writeFileSync } from 'node:fs' 3 3 import { Page } from './components.ts' 4 - import { prepareJsonFiles } from './prepare-json-files.ts' 4 + import { lunariaJSONFiles, prepareJsonFiles } from './prepare-json-files.ts' 5 5 import type { I18nStatus } from '../shared/types/i18n-status.ts' 6 6 7 7 await prepareJsonFiles() ··· 61 61 } 62 62 63 63 const completedKeys = totalKeys - missingKeys.length 64 - const localeFilePath = `i18n/locales/${locale.lang}.json` 64 + const localeFilePath = `i18n/locales/${lunariaJSONFiles[locale.lang]!}.json` 65 65 66 66 return { 67 67 lang: locale.lang,
+3 -1
lunaria/prepare-json-files.ts
··· 2 2 import type { LocaleObject } from '@nuxtjs/i18n' 3 3 import * as path from 'node:path' 4 4 import * as fs from 'node:fs/promises' 5 - import { currentLocales } from '../config/i18n.ts' 5 + import { currentLocales, lunariaJSONFiles } from '../config/i18n.ts' 6 6 import { deepCopy } from '@intlify/shared' 7 7 8 8 const destFolder = path.resolve('lunaria/files') 9 9 const localesFolder = path.resolve('i18n/locales') 10 10 11 11 const defaultLocale = currentLocales.find(l => l.code === 'en-US')! 12 + /** @public */ 13 + export { lunariaJSONFiles } 12 14 /** @public */ 13 15 export const sourceLocale = { 14 16 label: defaultLocale.name,