Coder Social home page Coder Social logo

nuxt3's Introduction

@intlify/nuxt3

Nuxt3 module for vue-i18n-next

โ“ 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 buildModules options of nuxt.confg.[ts|js]

// nuxt.config.js
export default {
  // ...
  buildModules: ['@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 {
  // ...
  buildModules: ['@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 {
  // ...
  buildModules: ['@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 {
  // ...
  buildModules: ['@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

nuxt3's People

Contributors

antfu avatar kazupon avatar killix avatar luckywraptor avatar superbuba avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.