[Intergration] [I18n] Expose the mapped locale list from Nuxt I18n
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- nuxt, nuxtjs, typescript
- Ambito
- frontend, internationalization
Direzione di ricerca
Read the locale mapping added in PR #7152 and its integration point for Nuxt I18n. Trace how the mapped current locale is exposed, then identify how to expose the configured mapped locale list for ULocaleSelect. Done means consumers can use that list without importing every Nuxt UI locale, while retaining the mapped locale types.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Package
v4.x
Description
NuxtUI has made it very easy to integrate with Nuxt I18n. Still, there was one pain point that require user to handle: Mapping between NuxtUI's locales and Nuxt I18n's locales
Both packages define different types to represent locale object:
- NuxtUI's
Locale<M>: https://github.com/nuxt/ui/blob/v4/src/runtime/types/locale.ts#L235 - Nuxt I18n's
LocaleObject<T>: https://github.com/nuxt-modules/i18n/blob/main/src/types.ts#L489
So there need to be a mapping step to set NuxtUI's locale to Nuxt I18n's. Typically there are 2 places:
<UApp>: to set the app's locale itself, only the current Nuxt I18n locale need to be mapped- Language Switcher component, which NuxtUI very conveniently provided
<ULocaleSelect>: this need a list of all configured locales
For a long while. NuxtUI recommend the following pattern:
import * as locales from '@nuxt/ui/locale'
For <UApp>:
<script setup lang="ts">
import * as locales from '@nuxt/ui/locale'
const { locale } = useI18n()
</script>
<template>
<UApp :locale="locales[locale]">
<!-- ... -->
</UApp>
</template>
For <ULocaleSelect>:
<script setup lang="ts">
import * as locales from '@nuxt/ui/locale'
const { locale, setLocale } = useI18n()
</script>
<template>
<ULocaleSelect
v-model="locale"
:locales="Object.values(locales)"
@update:model-value="setLocale($event)"
/>
</template>
Perhaps people will make a nice little composable for this:
import * as nuxtUiLocales from '@nuxt/ui/locale'
export const useNuxtUiLocale = () => {
const {
locale: nuxtI18nLocaleCode,
locales: nuxtI18nLocaleObjects,
} = useI18n()
return {
nuxtUiLocale: computed(() => nuxtUiLocales[i18nLocaleCode.value]),
nuxtUiLocales: computed(() => nuxtI18nLocaleObjects.map((localeObj) => nuxtUiLocales[localeObj.code])),
}
}
However, import * cannot be tree-shaken, the build would contains all of NuxtUI's locale file even if we only use 2 or 3, and thus born https://github.com/nuxt/ui/pull/7152. In a typical fashion of Nuxt ecosystem, improve the DX by doing the mapping at build time, thereby eliminating the need for hand-mapping AND only bundle the locale that is in-use
And yet, https://github.com/nuxt/ui/pull/7152 only address 1 of the 2 places where we need to map, <UApp>. The <ULocaleSelect> part is not addressed, we have 3 options:
- Bundle everything via
import *, which defeat the purpose of https://github.com/nuxt/ui/pull/7152, and also was discouraged as of said PR. - Maintain the in-use language list by hand:
import { en, ja, de }, which go against the spirit of Nuxt (There are 2 places you need to maintain and remember to update, bad architecture), and of https://github.com/nuxt/ui/pull/7152 (the PR was made to improve that DX) - Turn off Typescript, put Nuxt I18n's
LocaleObject<T>in (which expectLocale<M>) and hope that a future version dont break, as it only work because coincidentally both types is havingcodeas a property.
None of these options are good. And all can be solved by just exposing the mapped locale list that was made in https://github.com/nuxt/ui/pull/7152
Additional context
- Lingua principale
- TypeScript
- Stelle
- 7.1k
- Fork
- 1.2k
- Merge medio
- 1g 2h
- PR unite (30g)
- 147
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nuxt/ui
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
SelectMenu: expose item for default slotForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertatriage
Difficoltà 2/5 1-3 ore Idoneità per principianti 61/100
I maintainer di solito rispondono entro 1 giorno
-
NavigationMenu: expanding a nested item in vertical orientation collapses its parent when using v-modelForse già presa @cristianchiriac l’ha presa 32 giorni fa. Apertatriage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
UAvatar wrong root for passthoughForse già presa @lazerg l’ha presa 79 giorni fa. Apertatriage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
bug priority: low role: BE stage: now
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
ahmadrosid/nakama#2594 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
milind-soni/OpenMausBot#6495 ·
I maintainer di solito rispondono entro 1 giorno
-
Navigating the session tree adds the branch's prompts to Up-arrow history againForse già presa @acmerfight l’ha presa oggi. Apertauntriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
earendil-works/pi#12279 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
approved documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 89/100
vitest-dev/vitest#12015 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno