nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.73k stars 478 forks source link

i18n for SEO #3069

Closed coderfreii closed 2 months ago

coderfreii commented 2 months ago

Describe the feature

"I want to make sure the useI18n function is accessible during the pre Nuxt plugin setup phase to improve SEO with remote async data. now I just get a error ‘Must be called at the top of a setup function’"

usage:

import { _readSingleton } from "~/shared/directus";

export default defineNuxtPlugin({
    enforce: "pre",
    setup: async (nuxtApp) => {
        console.log("pre plugin");
        const i18 = useI18n()

        const data = await _readSingleton("site_config",i18.locale.value)
        updateSiteConfig({
            name: data.translation?.name,
            indexable: data.indexable,
            url: data.translation?.url,
        })

Additional information

Final checks

coderfreii commented 2 months ago

I made it in another way.

export default defineNuxtPlugin({
    enforce: "pre",
    dependsOn:['i18n:plugin'],
    setup: async (nuxtApp) => {
        console.log("pre plugin");
        const app = useNuxtApp()
        console.log(app.$i18n.locale.value);