Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/glenzli/vue-dynamic-locale

A dynamic multi language plugin for Vue.
https://github.com/glenzli/vue-dynamic-locale

json locale multi-language vue vuex

Last synced: about 4 hours ago
JSON representation

A dynamic multi language plugin for Vue.

Awesome Lists containing this project

README

        

# Vue-Dynamic-Locale

A straightforward implemention for multi-language for local Vue app (e.g. electron). You can change language dynamically.

## Install

The recommended way to install and maintain vue-dynamic-locale in your project is through the Node.js Pacakge Manager (NPM), simply type the npm command in your project folder:

```sh
npm install vue-dynamic-locale --save
```

## Usage

To use vue-dynamic-locale, you must install it as a Vue plugin with store included in options:
```javascript
import VueDynamicLocale from 'vue-dynamic-locale'

// path is the directory of locale json files.
const path = 'static/locale'
// default locale for the application
const defaultLocale = 'en'

// Vuex store must be included in options.
Vue.install(VueDynamicLocale, { store, path, defaultLocale })
```

Then, you can use **$t** object in your Vue components to access current language for specific key. For example, the language json file may like this:

```json
{
"Hellow": {
"World": "Dynamic"
},
"Locale": "Vue",
"Array": ["Value1", "Value2", "Value3"],
"Root": {
".": "Root", // "." is a special key represents it's root
"Child": "Child"
}
}
```

Then you can use it like this in Vue template:
```javascript
$t['Hellow.World'] // === 'Dynamic'
$t['Locale'] // === 'Vue'
$t['Array.0'] // === 'Value1'
$t['Array.2'] // === 'Value3'
$t['Root'] // === 'Root'
$t['Root.Child'] // === 'Child'
```

You can change locale by **$setLocale()**, and **$getLocales()** to list all avaiable locales in your locale directory.

## License
Distributed under the MIT license. See [LICENSE](https://github.com/luz-alphacode/vue-undoable/blob/master/LICENSE) for detail.