---
title: "useMovkI18n"
description: "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."
canonical_url: "https://docs.mhaibaraai.cn/en/docs/reference/composables/use-movk-i18n"
---
# 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

```vue [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

```ts
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/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:

```vue
<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>
```

> [!NOTE]
> 
> Include 
> 
> locale
> 
>  in the 
> 
> useAsyncData
> 
>  key, otherwise switching languages reuses the cache of the previous locale.

## Related

- [Internationalization](https://docs.mhaibaraai.cn/en/docs/guide/i18n)
- [useLocaleSeo](https://docs.mhaibaraai.cn/en/docs/reference/composables/use-locale-seo)

## Changelog

See commit history for [layer/app/composables/useMovkI18n.ts](https://github.com/mhaibaraai/movk-nuxt-docs/commits/main/layer/app/composables/useMovkI18n.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-nuxt-docs/blob/main/layer/app/composables/useMovkI18n.ts)


## Sitemap

See the full [sitemap](https://docs.mhaibaraai.cn/sitemap.md) for all pages.
