useMovkI18n
useMovkI18n() hides the difference between the two i18n states. Pages, navigation, search and components in the layer all use it to pick the collection and path for the current locale. Custom components should do the same instead of calling useI18n() directly.
Usage
<script setup lang="ts">
const { t, localePath, docsRoot } = useMovkI18n()
</script>
<template>
<NuxtLink :to="localePath('/releases')">
{{ t('docs.overview') }}
</NuxtLink>
<NuxtLink :to="`${docsRoot}/getting-started`">
Docs
</NuxtLink>
</template>
Signature
function useMovkI18n(): MovkI18n
interface MovkLocale {
code: string
name: string
language?: string
dir?: 'ltr' | 'rtl'
}
Return Value
| Name | Type | Description |
|---|---|---|
isEnabled | boolean | Whether the site enables @nuxtjs/i18n |
locale | Ref<string> | Current locale code |
defaultLocale | string | Default locale code |
locales | MovkLocale[] | Valid locales after build-time filtering; an empty array when i18n is disabled |
t | (key: string, params?: Record<string, string | number>) => string | Reads a built-in translation; {name} placeholders are replaced from params; unknown keys are returned as-is |
localePath | (path: string) => string | Adds the current locale prefix to an internal path; returns the path unchanged when i18n is disabled |
switchLocalePath | (code?: string) => string | Path of the current page in the target locale; an empty string when i18n is disabled |
docsRoot | ComputedRef<string> | Docs root for the current locale: /docs for the default locale, /{locale}/docs otherwise |
docsCollection | ComputedRef<string> | Docs collection name: docs for the default locale, docs_{code} otherwise |
landingCollection | ComputedRef<string> | Landing page collection name |
releasesCollection | ComputedRef<string> | Releases page collection name |
templatesCollection | ComputedRef<string> | Showcase page collection name |
- in collection names is replaced with _, so zh-TW maps to docs_zh_TW.
Two Modes
@nuxtjs/i18nenabled:locale,t,localePathandswitchLocalePathdelegate to Nuxt i18n, andlocalescomes from the layer-filteredruntimeConfig.public.movkDocs.filteredLocales.- Disabled: the locale is fixed to
appConfig.i18n.locale(defaultzh-CN),treads that locale's built-in translations, and routes are not localized.
Example
Query the docs collection for the current locale:
<script setup lang="ts">
const { locale, docsCollection } = useMovkI18n()
const { data: pages } = await useAsyncData(
() => `latest-pages-${locale.value}`,
() => queryCollection(docsCollection.value as 'docs').select('title', 'path').limit(5).all()
)
</script>
locale in the useAsyncData key, otherwise switching languages reuses the cache of the previous locale.Related
Changelog
nuxt.config Options
Every nuxt.config option and environment variable the layer reads at build time, including feature flags, AI Chat, component metadata, MCP, llms.txt, agent discovery and site info. Changing these options requires a rebuild or a dev server restart.
useLocaleSeo
Inject hreflang alternate links, x-default and og:locale on multilingual sites so search engines can tell the language versions apart. The layer's app.vue already calls it globally; call it yourself only when you rewrite app.vue.