useMovkI18n

A single i18n entry point that works the same whether or not @nuxtjs/i18n is enabled. Read the current locale, translate built-in strings, build locale-prefixed links, and get the content collection and docs root for the current locale.

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

app/components/DocsLink.vue
<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

NameTypeDescription
isEnabledbooleanWhether the site enables @nuxtjs/i18n
localeRef<string>Current locale code
defaultLocalestringDefault locale code
localesMovkLocale[]Valid locales after build-time filtering; an empty array when i18n is disabled
t(key: string, params?: Record<string, string | number>) => stringReads a built-in translation; {name} placeholders are replaced from params; unknown keys are returned as-is
localePath(path: string) => stringAdds the current locale prefix to an internal path; returns the path unchanged when i18n is disabled
switchLocalePath(code?: string) => stringPath of the current page in the target locale; an empty string when i18n is disabled
docsRootComputedRef<string>Docs root for the current locale: /docs for the default locale, /{locale}/docs otherwise
docsCollectionComputedRef<string>Docs collection name: docs for the default locale, docs_{code} otherwise
landingCollectionComputedRef<string>Landing page collection name
releasesCollectionComputedRef<string>Releases page collection name
templatesCollectionComputedRef<string>Showcase page collection name

- in collection names is replaced with _, so zh-TW maps to docs_zh_TW.

Two Modes

  • @nuxtjs/i18n enabled: locale, t, localePath and switchLocalePath delegate to Nuxt i18n, and locales comes from the layer-filtered runtimeConfig.public.movkDocs.filteredLocales.
  • Disabled: the locale is fixed to appConfig.i18n.locale (default zh-CN), t reads 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>
Include locale in the useAsyncData key, otherwise switching languages reuses the cache of the previous locale.

Changelog

No recent changes
Copyright © 2024 - 2026