• Stars
    star
    202
  • Rank 193,691 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 3 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Nuxt 3 Module for vue-i18n-next

@intlify/nuxt3

Nuxt3 module for vue-i18n-next

** ⚠️ IMPORTANT**

This project is maintenance mode, because I'm forcusing @nuxtjs/i18n. We would recommend to use it

❓ What is defference from @nuxtjs/i18n ?

This nuxt module is intended to be a quick and easy way for people to use vue-i18n-next with Nuxt3.

It also has the purpose of finding issues on the vue-i18n-next so that @nuxtjs/i18n can support Nuxt3.

  • Setup vue-i18n for your Nuxt3 project
    • You do not need to entrypoint codes with createI18n.
  • Setup bundle tools
    • @intlify/vue-i18n-loader and @intlify/vite-plugin-vue-i18n are included
  • Locale resources importing

πŸ’Ώ Installation

First install

# for npm
npm install --save-dev @intlify/nuxt3

# for yarn
yarn add -D @intlify/nuxt3

After the installation in the previous section, you need to add @intlify/nuxt3 module to modules options of nuxt.confg.[ts|js]

// nuxt.config.js
export default {
  // ...
  modules: ['@intlify/nuxt3']
  // ...
}

πŸ”§ Configurations

You can set the following types in nuxt.config with below options:

export interface IntlifyModuleOptions {
  /**
   * Options specified for `createI18n` in vue-i18n.
   *
   * If you want to specify not only objects but also functions such as messages functions and modifiers for the option, specify the path where the option is defined.
   * The path should be relative to the Nuxt project.
   */
  vueI18n?: I18nOptions | string
  /**
   * Define the directory where your locale messages files will be placed.
   *
   * If you don't specify this option, default value is `locales`
   */
  localeDir?: string
}

The above options can be specified in the intlify config of nuxt.config

nuxt.config below:

export default {
  // ...
  modules: ['@intlify/nuxt3'],
  // config for `@intlify/nuxt3`
  intlify: {
    vueI18n: {
      // You can setting same `createI18n` options here !
      locale: 'en',
      messages: {
        en: {
          hello: 'Hello'
        },
        ja: {
          hello: 'こんにけは'
        }
      }
    }
  }
}

If you specify the path to intlify.vueI18n, you need to set it to a file in mjs format.

The following Λ‹nuxt.config`:

export default {
  // ...
  modules: ['@intlify/nuxt3'],
  // config for `@intlify/nuxt3`
  intlify: {
    vueI18n: 'vue-i18n.mjs'
  }
}

vue-i18n.mjs as follows:

// The configuration must be returned with an **async function**.
export default async () => ({
  locale: 'en',
  messages: {
    en: {
      hello: ({ named }) => `HELLO, ${named('name')}!`
    },
    ja: {
      hello: 'こんにけは、{name}!'
    }
  }
})

πŸ“ Locale resources importing

You can load the locale resources stored in the file from the directory specified in intlify.localeDir.

The following is an example of the nuxt.conf:

export default {
  // ...
  modules: ['@intlify/nuxt3'],
  // config for `@intlify/nuxt3`
  intlify: {
    localeDir: 'locales', // set the `locales` directory at source directory of your Nuxt application
    vueI18n: {
      // ...
    }
  }
}

The following is a set of files of locale resources defined in the directory:

-| app/
---| nuxt.config.js
---| package.json
---| locales/
------| en.json/
------| ja.json/

The locale messages defined above will be loaded by the @intlify/nuxt3 module and set to the messages option of createI18n on the module side.

Each locale in the messages option is used as a file name without its extension. For example, In the locales directory above, en.json will use en as the locale.

©️ LICENSE

MIT

More Repositories

1

vue-i18n-next

Vue I18n for Vue 3
TypeScript
1,904
star
2

vue-i18n-loader

🌐 vue-i18n loader for custom blocks
TypeScript
268
star
3

bundle-tools

bundling for intlify i18n tools
TypeScript
226
star
4

vue-cli-plugin-i18n

🌐 Vue CLI plugin to add vue-i18n to your Vue Project
JavaScript
197
star
5

vite-plugin-vue-i18n

🌐 Vite plugin for Vue I18n
TypeScript
130
star
6

eslint-plugin-vue-i18n

🌐 ESLint plugin for Vue I18n
TypeScript
120
star
7

vue-i18n-extensions

🌐 vue-i18n extensions
TypeScript
89
star
8

vue-i18n-locale-message

🌐 i18n locale messages management tool for vue-i18n
TypeScript
72
star
9

vue-i18n-composable

Composition API for vue-i18n in Vue 2.x
JavaScript
44
star
10

h3

Internationalization middleware & utilities for h3
TypeScript
25
star
11

vite-vue-i18n-starter

⚑ Vite Vue I18n Starter
Vue
24
star
12

routing

The i18n routing libraries
TypeScript
16
star
13

hono

Internationalization middleware & utilities for Hono
TypeScript
14
star
14

utils

Collection of i18n utilities
TypeScript
12
star
15

devtools

βš™οΈ i18n devtools for debugging Intlify applications
TypeScript
11
star
16

cli

CLI Tooling for i18n development
TypeScript
10
star
17

bridging

Utilities that provide universal compatibility for Vue 2 & Vue 3
JavaScript
10
star
18

rollup-plugin-vue-i18n

🌐 vue-i18n rollup plugin for custom blocks
JavaScript
9
star
19

vue-i18n-jest

🌐 vue-jest wrapper for i18n custom blocks
JavaScript
7
star
20

intlify.dev

🌐 Website for Intlify
Vue
6
star
21

eslint-plugin-svelte

ESLint plugin for internationalization with Svelte
TypeScript
4
star
22

poeditor-service-provider

POEditor service provider for vue-i18n-locale-message
TypeScript
4
star
23

intlify-core

3
star
24

express

intlify for express middleware
TypeScript
2
star
25

blog

πŸ“” The official Intlify blog
Vue
2
star
26

art

🎨 Artworks
1
star
27

.github

1
star