• Stars
    star
    268
  • Rank 153,144 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated 7 months ago

Reviews

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

Repository Details

🌐 vue-i18n loader for custom blocks

Vue I18n Loader logo

@intlify/vue-i18n-loader

Build Status npm

webpack loader for Vue I18n


⚠️ Notice

This package is maintained for Vue I18n v8 (Vue 2).

If you want to use Vue I18n v9 (Vue 3) or later, See the @intlify/bundle-tools repo.

πŸ’Ώ Installation

$ npm i --save-dev @intlify/vue-i18n-loader

πŸš€ Usage

the below example thatApp.vue have i18n custom block:

Basic

<template>
  <p>{{ $t('hello') }}</p>
</template>

<script>
export default {
  name: 'app',
  // ...
}
</script>

<i18n>
{
  "en": {
    "hello": "hello world!"
  },
  "ja": {
    "hello": "γ“γ‚“γ«γ‘γ―γ€δΈ–η•Œ!"
  }
}
</i18n>

The locale messages defined at i18n custom blocks are json format default.

Source importing

you also can:

<i18n src="./myLang.json"></i18n>
// ./myLnag.json
{
  "en": {
    "hello": "hello world!"
  },
  "ja": {
    "hello": "γ“γ‚“γ«γ‘γ―γ€δΈ–η•Œ!"
  }
}

Locale definition

You can define locale messages for each locale with locale attr in single-file components:

<i18n locale="en">
{
  "hello": "hello world!"
}
</i18n>

<i18n locale="ja">
{
  "hello": "γ“γ‚“γ«γ‘γ―γ€δΈ–η•Œ!"
}
</i18n>

The above defines two locales, which are merged at target single-file components.

Locale Messages formatting

Besides json format, You can be used by specifying the following format in the lang attribute:

  • yaml
  • json5

example yaml foramt:

<i18n locale="en" lang="yaml">
  hello: "hello world!"
</i18n>

<i18n locale="ja" lang="yml">
  hello: "γ“γ‚“γ«γ‘γ―γ€δΈ–η•ŒοΌ"
</i18n>

example json5 format:

<i18n lang="json5">
{
  "en": {
    // comments
    "hello": "hello world!"
  }
}
</i18n>

JavaScript

import Vue from 'vue'
import VueI18n from 'vue-i18n'
import App from './App.vue'

Vue.use(VueI18n)

const i18n = new VueI18n({
  locale: 'en',
  messages: {
    en: {
      // ...
    },
    ja: {
      // ...
    }
  }
})
new Vue({
  i18n,
  render: h => h(App)
}).$mount('#app')

Webpack Config

vue-loader (v15 or later):

// for vue.config.js (Vue CLI)
module.exports = {
  chainWebpack: config => {
    config.module
      .rule('i18n')
      .resourceQuery(/blockType=i18n/)
      .type('javascript/auto')
      .use('i18n')
      .loader('@intlify/vue-i18n-loader')
  }
}

vue-loader (v15 or later):

// for webpack.config.js (Without Vue CLI)
module.exports = {
  module: {
    rules: [
      {
        resourceQuery: /blockType=i18n/,
        type: 'javascript/auto',
        loader: '@intlify/vue-i18n-loader',
      },
    ]
  }
}

vue-loader (~v14.x):

// for webpack config file
module.exports = {
  module: {
    rules: [{
      test: /\.vue$/,
      loader: 'vue',
      options: {
        loaders: {
          i18n: '@intlify/vue-i18n-loader'
        }
      }
    }]
  }
}

πŸ“œ Changelog

Details changes for each release are documented in the CHANGELOG.md.

πŸ’ͺ Contribution

Please make sure to read the Contributing Guide before making a pull request.

©️ License

MIT

More Repositories

1

vue-i18n-next

Vue I18n for Vue 3
TypeScript
1,904
star
2

bundle-tools

bundling for intlify i18n tools
TypeScript
226
star
3

nuxt3

Nuxt 3 Module for vue-i18n-next
TypeScript
202
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