Skip to content

Commit

Permalink
docs(faq): add explanation for I18n Micro plugin issues in Nuxt
Browse files Browse the repository at this point in the history
Added a section to the FAQ addressing common issues with the
`I18n Micro` plugin in Nuxt plugins. Included example code that
illustrates potential breakage and provided a solution for
ensuring proper plugin loading order and configuration.
  • Loading branch information
s00d committed Jan 22, 2025
1 parent a99d1f5 commit d4c49e5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/guide/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@ outline: deep

# FAQ: Common Issues & Solutions

## ❓ Why does the I18n Micro plugin not work in Nuxt plugins?

With the newest version of `Nuxt I18n Micro`, there are reported issues where the I18n plugin does not work as expected within Nuxt plugins. For example, the following code may break:

```javascript
export default defineNuxtPlugin((_nuxtApp) => {
const { $t, $getLocale } = useI18n() // or const { $t, $getLocale } = useNuxtApp()
const translatedMessage = $t('test_key')
const locale = $getLocale() // error here

console.log(translatedMessage, locale)
})
```

**Solution:**

Ensure proper plugin loading order and update your configuration to resolve the issue. For example:

```javascript
export default defineNuxtPlugin({
name: 'i18n:plugin',
dependsOn: ['i18n-plugin-loader'],
enforce: 'post',
setup(_nuxtApp) {
const { $t, $getLocale } = useI18n() // or const { $t, $getLocale } = useNuxtApp()
const translatedMessage = $t('test_key')
const locale = $getLocale() // error here

console.log(translatedMessage, locale)
},
})
```

## ❓ What if a route doesn't load?

When using `Nuxt I18n Micro`, certain routes might not load as expected, especially if the router doesn't automatically assign a name to a route in subfolders.
Expand Down

0 comments on commit d4c49e5

Please sign in to comment.