Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defineI18nLocale is not defined #1954

Closed
Eddie344 opened this issue Mar 26, 2023 · 8 comments
Closed

defineI18nLocale is not defined #1954

Eddie344 opened this issue Mar 26, 2023 · 8 comments
Labels

Comments

@Eddie344
Copy link

Eddie344 commented Mar 26, 2023

Environment

  • Operating System: Darwin
  • Node Version: v16.17.1
  • Nuxt Version: 3.3.2
  • Nitro Version: 2.3.2
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: modules
  • Runtime Modules: @nuxtjs/i18n@8.0.0-beta.10
  • Build Modules: -

Reproduction

stackblitz.com

Describe the bug

After installing module and configure for work with lazy loaded messages, I have an error message:
Failed locale loading: defineI18nLocale is not defined
I check a dist folder in node_modules, there is no defineI18nLocale function export in dist/runtime/composables.mjs

Additional context

No response

Logs

@nuxtjs/i18n Failed locale loading: defineI18nLocale is not defined 
@Eddie344
Copy link
Author

So, I find it in edge version. I think it's worth mentioning somewhere in the documentation

@IvanWala
Copy link

I have the same problem than you with @nuxtjs/i18n@8.0.0-beta.10

When I try to use defineI18nLocale like this in langs/en-GB.js

export default defineI18nLocale((context, locale) => {
// for example, fetch locale messages from nuxt server
return $fetch({{mi api url}}/api/language/i18n?locale=en-GB});
}))

throws the error Failed locale loading: defineI18nLocale is not defined.

when i try to do this:

export default () => {
return $fetch({{mi api url}}/api/language/i18n?locale=en-GB');
};

or this

export default async() => {
return await $fetch({{mi api url}}/api/language/i18n?locale=en-GB');
};

throws another error:
@nuxtjs/i18n Not support executable file (e.g. js, cjs, mjs)

PD: {{my api url}} is a right url.

@Eddie344
Copy link
Author

I have the same problem than you with @nuxtjs/i18n@8.0.0-beta.10

When I try to use defineI18nLocale like this in langs/en-GB.js

export default defineI18nLocale((context, locale) => {
// for example, fetch locale messages from nuxt server
return $fetch({{mi api url}}/api/language/i18n?locale=en-GB});
}))

throws the error Failed locale loading: defineI18nLocale is not defined.

when i try to do this:

export default () => {
return $fetch({{mi api url}}/api/language/i18n?locale=en-GB');
};

or this

export default async() => {
return await $fetch({{mi api url}}/api/language/i18n?locale=en-GB');
};

throws another error: @nuxtjs/i18n Not support executable file (e.g. js, cjs, mjs)

PD: {{my api url}} is a right url.

@IvanWala use this variant of installation
https://github.com/nuxt-modules/i18n#install-edge-version

@IvanWala
Copy link

Thanks @Eddie344.

I removed "next" and added "edge",

Now the problem is different when i use this inside langs/en-GB.js it return an empty object

export default defineI18nLocale((context, locale) => {
// for example, fetch locale messages from nuxt server
return $fetch({{mi api url}}/api/language/i18n?locale=en-GB});
}))

But if you access to the langs by browser url the json is correct.

@kazupon kazupon added v8 and removed pending triage labels Mar 29, 2023 — with Volta.net
Copy link
Collaborator

kazupon commented Mar 29, 2023

Docs said:

If the function returns an Object available in nuxt i18n module, you can configure the dynamic locale messages, like the API (including external API) or back-end, via fetch:

https://v8.i18n.nuxtjs.org/guide/lazy-load-translations

You need return the object.
your reproduction have returned undefined from external site with $fetch

Thanks.

@kazupon kazupon closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2023
@AlenDosev
Copy link

Why is this closed? I still have that error message.
@nuxtjs/i18n Failed locale loading: defineI18nLocale is not defined
I tried installing the edge version, it didn't help. I am trying to do the example ->
export default defineI18nLocale(async (context, locale) => { return { welcome: 'Welcome' } })

From where do I import defineI18nLocale ?

@hahatulk
Copy link

hahatulk commented Apr 8, 2023

Why is this closed? I still have that error message. @nuxtjs/i18n Failed locale loading: defineI18nLocale is not defined I tried installing the edge version, it didn't help. I am trying to do the example -> export default defineI18nLocale(async (context, locale) => { return { welcome: 'Welcome' } })

From where do I import defineI18nLocale ?

Do npm remove first, without it edge will not be installed

@letoast
Copy link

letoast commented Feb 26, 2024

Why is this closed? I still have that error message. @nuxtjs/i18n Failed locale loading: defineI18nLocale is not defined I tried installing the edge version, it didn't help. I am trying to do the example -> export default defineI18nLocale(async (context, locale) => { return { welcome: 'Welcome' } })

From where do I import defineI18nLocale ?

import { defineI18nLocale } from '#imports'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants