How to import useI18n and useLocalePath composables in Nuxt3

See original GitHub issue

Hi. Firstly, i want to thank you for your great work on this package.

I’m using nuxt3 rc4 (with rc3 the errors were the same) and @nuxtjs/i18n-edge 8.0.0-alpha.0-27579558.fdbd51b Package.json dependencies section is very simple:

"dependencies": {
    "@nuxtjs/i18n": "npm:@nuxtjs/i18n-edge"
  },
  "devDependencies": {
    "nuxt": "3.0.0-rc.4"
  }

nuxt.config.ts was inspired by your example here https://github.com/nuxt-community/i18n-module/blob/next/playground/nuxt3/nuxt.config.ts

import { defineNuxtConfig } from "nuxt";

export default defineNuxtConfig({
  modules: ["@nuxtjs/i18n"],

  vite: { build: { minify: false } },

  i18n: {
    langDir: "locales",
    lazy: true,
    baseUrl: "http://localhost:3000",
    locales: [
      { code: "ru", iso: "ru-RU", file: "ru.json", name: "ru" },
      { code: "en", iso: "en-US", file: "en.json", name: "en" },
    ],
    defaultLocale: "ru",
    detectBrowserLanguage: false,
    vueI18n: {
      legacy: false,
      locale: "ru",
      fallbackLocale: { ru: ["en"], en: ["ru"] },
    },
  },
});

I’m using useI18n and useLocalePath composables in pages and components. I’m importing composables like this:

  import { useI18n } from "@nuxtjs/i18n/node_modules/@intlify/vue-i18n-bridge";
  import { useLocalePath } from "@nuxtjs/i18n/node_modules/vue-i18n-routing";

In your playground example it is not very clear to understand where to import they from. https://github.com/nuxt-community/i18n-module/blob/next/playground/nuxt3/pages/index.vue - here you import they from “#i18n”. I tried to import them from “@nuxtjs/i18n”, but:

Module '"@nuxtjs/i18n"' has no exported member 'useI18n'.

What is the correct way to import them?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
alexan059commented, Jun 18, 2022

It seems to be an ongoing issue at the latest alpha version. Try out this version in your package.json:

"@nuxtjs/i18n": "npm:@nuxtjs/i18n-edge@8.0.0-alpha.0-27531750.4e4cffe",

This is working for me and I will keep using it until the issue is solved: https://github.com/nuxt-community/i18n-module/issues/1451.

1reaction
alexan059commented, Jun 16, 2022

Apparently, the correct way to import those composables is to use import { useI18n } from "#i18n", as I could find in the examples in https://github.com/nuxt-community/i18n-module/issues/1451. The type recognition seems to be broken and it shows that it can’t find the declarations, but it is still working in dev/prod.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to import useI18n and useLocalePath composables in ...
I'm using useI18n and useLocalePath composables in pages and components. I'm importing composables like this: import { useI18n } from "@nuxtjs/ ...
Read more >
Nuxt 3 integration - Vue I18n - Intlify
So far we have been able to integrate Vue I18n into our Nuxt 3 application. Next, we will implement language switching and import...
Read more >
Basic Usage · @nuxtjs/i18n
useLocalePath is a composable function. Calling that composable function returns a function that is able to return the localized URL for a given...
Read more >
@leanera/nuxt-i18n: Versions | Openbase
Module compatibility with nuxt3-rc.9+ - by @johannschopplich (1d0ce) ... Import nuxt app composable from global imports - by @johannschopplich (9dbe1).
Read more >
composables/ · Nuxt Directory Structure
Nuxt 3 uses the composables/ directory to automatically import your Vue composables into your application using auto-imports! Under the hood, Nuxt auto ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found