mirror of
https://github.com/zen-browser/www.git
synced 2025-07-07 17:05:32 +02:00
chore: remove unnecessary mapping
This commit is contained in:
parent
b0c122f984
commit
35a7cc3fcc
2 changed files with 13 additions and 27 deletions
|
@ -453,18 +453,18 @@ async function importI18n(
|
|||
return [locale, result.default]
|
||||
}
|
||||
|
||||
export const locales = [
|
||||
const locales = [
|
||||
{ label: 'English', value: 'en', intl: 'en-US' },
|
||||
{ label: '日本語', value: 'ja', intl: 'ja-JP' },
|
||||
{ label: 'Español', value: 'es', intl: 'es-ES' },
|
||||
] as const
|
||||
|
||||
const languages = Object.fromEntries(
|
||||
export const languages = Object.fromEntries(
|
||||
(
|
||||
await Promise.all([
|
||||
importI18n('en', import('~/i18n/en/translation.json')),
|
||||
importI18n('ja', import('~/i18n/ja/translation.json')),
|
||||
importI18n('es', import('~/i18n/es/translation.json')),
|
||||
importI18n('en', import('~/i18n/en/translation.json', { with: { type: 'json' } })),
|
||||
importI18n('ja', import('~/i18n/ja/translation.json', { with: { type: 'json' } })),
|
||||
importI18n('es', import('~/i18n/es/translation.json', { with: { type: 'json' } })),
|
||||
])
|
||||
).map(([locale, result]) => {
|
||||
const parsed = i18nSchema.I18n(result)
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import { type AstroGlobal, type GetStaticPaths } from 'astro'
|
||||
|
||||
import { CONSTANT } from '~/constants'
|
||||
import { type I18nType, type Locale } from '~/constants/i18n'
|
||||
import { languages, type I18nType, type Locale } from '~/constants/i18n'
|
||||
|
||||
/**
|
||||
* List of all supported locales
|
||||
*/
|
||||
export const locales = CONSTANT.I18N.LOCALES.map(({ value }) => value)
|
||||
|
||||
/**
|
||||
* Generates a localized path by prefixing the locale if necessary
|
||||
|
@ -45,11 +50,6 @@ export const getLocale = (Astro: AstroGlobal): Locale => {
|
|||
return Astro.currentLocale as Locale
|
||||
}
|
||||
|
||||
/**
|
||||
* List of all supported locales
|
||||
*/
|
||||
export const locales = CONSTANT.I18N.LOCALES.map(({ value }) => value)
|
||||
|
||||
/**
|
||||
* List of locales excluding the default locale
|
||||
*/
|
||||
|
@ -121,26 +121,12 @@ export function deepMerge(defaultObj: I18nType, localeObj: Partial<I18nType> = {
|
|||
return result
|
||||
}
|
||||
|
||||
const defaultUI = CONSTANT.I18N.LOCALES.find(({ value }) => {
|
||||
return value === CONSTANT.I18N.DEFAULT_LOCALE
|
||||
})?.ui
|
||||
const defaultUI = languages[CONSTANT.I18N.DEFAULT_LOCALE]
|
||||
|
||||
if (!defaultUI) {
|
||||
throw new Error('Default UI translation is missing!')
|
||||
}
|
||||
|
||||
const localesMap: Record<Locale, I18nType> = {} as Record<Locale, I18nType>
|
||||
|
||||
for (const locale of locales) {
|
||||
const maybeLocale = CONSTANT.I18N.LOCALES.find(({ value }) => {
|
||||
return value === locale
|
||||
})
|
||||
|
||||
if (maybeLocale) {
|
||||
localesMap[locale] = maybeLocale.ui
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves UI translations for a given locale
|
||||
* @param {Locale} [locale] - The target locale for translations
|
||||
|
@ -149,7 +135,7 @@ for (const locale of locales) {
|
|||
export const getUI = (locale?: Locale): I18nType => {
|
||||
const validLocale = locale && locales.includes(locale) ? locale : CONSTANT.I18N.DEFAULT_LOCALE
|
||||
|
||||
return localesMap[validLocale] ?? defaultUI
|
||||
return languages[validLocale] ?? defaultUI
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue