Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pespantelis/vue-localizer

:earth_africa: Localization plugin for Vue.js
https://github.com/pespantelis/vue-localizer

Last synced: 17 days ago
JSON representation

:earth_africa: Localization plugin for Vue.js

Awesome Lists containing this project

README

        

# 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
```js
import VueLocalizer from 'vue-localizer'

// install
Vue.use(VueLocalizer)

// the constructor comes with 2 optional arguments:
// - globalLocales (default: {})
// - language (default: 'en')
var localizer = new VueLocalizer()
```

#### You can add before/after change hooks
```js
localizer.beforeChange((lang) => {})
localizer.afterChange((lang) => {})
```

#### Add locales to your components if you want
```js
export default {
data: {..},

locales: {
en: {
name: {
first: 'Pantelis',
last: '{0}'
full: '{first} {last}',
}
},
el: {..},
..
},

methods: {..}
}
```

#### Change the language
```js
this.$lang.change('el') // call it from a vue instance
```

#### Template
```html

{{ $lang('name.first') }}

{{ $lang('name.last', ['Peslis']) }}

{{ $lang('name.full', {first:'Pantelis',last:'Peslis'}) }}
```

## License
Localizer is released under the MIT License. See the bundled LICENSE file for details.