Localizer
Installation
Install via NPM
Available through npm as vue-localizer
.
npm install --save vue-localizer
Usage
You can set the locales globally or.. into each component separately!
- Firsty it checks about the given path into the component's locales.
- If it exist, returns the specified text.
- Otherwise it checks into the global locales and if it does not exist, it returns the path.
Create a new Localizer instance
// installVue // the constructor comes with 2 optional arguments:// - globalLocales (default: {})// - language (default: 'en')var localizer =
You can add before/after change hooks
localizerlocalizer
Add locales to your components if you want
data: locales: en: name: first: 'Pantelis' last: '{0}' full: '{first} {last}' el: methods:
Change the language
this$lang // call it from a vue instance
Template
<!-- plain text -->{{ $lang('name.first') }} <!-- with indexed replacements -->{{ $lang('name.last', ['Peslis']) }} <!-- with associative replacements -->{{ $lang('name.full', {first:'Pantelis',last:'Peslis'}) }}
License
Localizer is released under the MIT License. See the bundled LICENSE file for details.