1.0.3 • Published 5 years ago

vuex-i18n-remote v1.0.3

Weekly downloads
5
License
GPL-3.0-only
Repository
github
Last release
5 years ago

vuex-i18n-remote

This is a small package that can be used to load translations from a remote server.

This is best used with grouped short key based translations (ei. home.welcome -> 'This is a welcome message.'), so that you can load groups of translations at a time.

Requirements

Usage

import Vue from 'vue';
import Vuex from 'vuex';
import Axios from 'axios';
import VuexI18nRemote from "vuex-i18n-remote"; // file from vuex-i18n-remote plugin

// ...setup Axios default config

// use Vuex
Vue.use(Vuex);

// setup store
const store = new Vuex.Store({
    // ...config options
});

// setup vuex-i18n-remote
Vue.use(VuexI18nRemote, {
    url: 'translations', // translations uri
    axios: Axios, // axios object
    store: store, // store instance
    storeModuleName: 'i18n', // store module name
    commonKeys: [ // common keys
        'common',
    ],
});

const app = new Vue({
    el: '#app',
    store,
});

Once the library is installed, vuex-i18n will also be installed.

Options

KeyDescriptionDefault
urlThis is the URL where the translations will be fetched from.translations
storeThis is the Vuex store to be used to store the translations.new Vuex.Store({})
storeModuleNameThis is the store module name used to store the translationsi18n
axiosThe Axios instance used for the http requestsAxios
commonKeysThis is an array of common keys that should be loaded by default if no option is specified by the method.[]
onTranslationNotFoundCallback used if translation is not foundfunction (locale, key) {}

Methods

Once loaded the plugin will add the following methods to Vue.

Global

Options
KeyDescriptionDefault
keyThe key to get from the servercommonKeys set above
localeThe locale to be usedlocale from Vue.i18n.locale()
Usage
Vue.i18nRemote.load(key, locale);

Instance

Options
KeyDescriptionDefault
keyThe key to get from the servercommonKeys set above
localeThe locale to be usedlocale from Vue.i18n.locale()
Usage
this.$i18nRemote.load(key, locale);
1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago