Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🌐 vue-i18n loader for custom blocks

License

NotificationsYou must be signed in to change notification settings

intlify/vue-i18n-loader

Vue I18n Loader logo

@intlify/vue-i18n-loader

Build Statusnpm

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 havei18n custom block:

Basic

<template>  <p>{{ $t('hello') }}</p></template><script>exportdefault {  name:'app',// ...}</script><i18n>{  "en": {    "hello": "hello world!"  },  "ja": {    "hello": "こんにちは、世界!"  }}</i18n>

The locale messages defined ati18n custom blocks arejson 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 withlocale 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 thelang 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

importVuefrom'vue'importVueI18nfrom'vue-i18n'importAppfrom'./App.vue'Vue.use(VueI18n)consti18n=newVueI18n({locale:'en',messages:{en:{// ...},ja:{// ...}}})newVue({  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 filemodule.exports={module:{rules:[{test:/\.vue$/,loader:'vue',options:{loaders:{i18n:'@intlify/vue-i18n-loader'}}}]}}

📜 Changelog

Details changes for each release are documented in theCHANGELOG.md.

💪 Contribution

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

©️ License

MIT

About

🌐 vue-i18n loader for custom blocks

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors13


[8]ページ先頭

©2009-2025 Movatter.jp