v-lang-plugin

1.1.0 • Public • Published

Installation

$ npm install v-lang-plugin --save

Get started

import Vue from 'Vue';
import { VLang, WebpackLangLoader } from 'v-lang-plugin';
 
Vue.use(VLang, WebpackLangLoader(), 'en');

Vue.use(VLang, LangLoader, lang | default - first lang in list);

Configure lang folder for webpack

Please, create alias in your webpack config file:

module.exports = {
    resolve: {
        alias: {
            'langs': './path-to-your-langs-folder'
        }
    }
}

How work without loaders?

const locales = {
    'en': {
        'langName': 'en',
        'magic': 'Pony'
    },
    'ru': {
        'langName': 'ru',
        'magic': 'Пони'
    },
    ...
};
 
Vue.use(VLang, locales);

Structure langs folder and file

langs
├── en.js
├── ru.js
└── ...
module.exports = {
    'langName': 'en', // Requirement param
    'pages': {
        'home': {
            'title': 'Main site'
        }
    },
    'magic': 'Pony'
};

How use langs?

$vlang.get('pages.home.title'); // Return 'Main site'
$vlang.get('magic'); // Return 'Pony'
$vlang.get(); // Return '' and write warn to console 
 
$vlang.set('en'); // Set language for reactive update all labels
 
$vlang.list // Array of available langs. Example: ['en', 'ru', ...]
$vlang.current // Current lang. Return: 'en'

Package Sidebar

Install

npm i v-lang-plugin

Weekly Downloads

7

Version

1.1.0

License

MIT

Unpacked Size

17.6 kB

Total Files

20

Last publish

Collaborators

  • antoxa1081
  • zelourt