@devslab/locale-match-nuxt
v0.1.3
Published
Nuxt module for @devslab/locale-match — resolves the locale during SSR from Accept-Language, so the page never changes language after it paints.
Maintainers
Readme
@devslab/locale-match-nuxt
Open source by DevsLab · OSS brand guide · Registry O07
Nuxt module for @devslab/locale-match — locale negotiation that will not hand a Simplified Chinese reader your Traditional text.
Requires Nuxt 3.8 or newer.
npm i @devslab/locale-match @devslab/locale-match-vue @devslab/locale-match-nuxtUsage
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@devslab/locale-match-nuxt'],
localeMatch: {
supported: ['ko', 'en', 'ja', 'zh-HK', 'zh-TW'],
fallback: 'ko',
// cookieName: 'locale', storageKey: 'locale', queryParam: 'lang'
},
});<script setup lang="ts">
const { locale, setLocale, supported } = useLocale(); // auto-imported
</script>Why a module and not just the composable
On a server-rendered app the locale has to be decided before the first byte,
from the request's own Accept-Language and cookie. Decide it on the client
instead and the reader watches the page change language after it paints.
This module resolves during SSR, serializes the answer into the payload, and the client simply agrees rather than re-detecting — so there is no flash and no hydration mismatch.
License
Apache-2.0 © devslab
