Proxy

Get translation

The plugin accepts a proxy object which has a getTranslation method. getTranslation only needs to return a promise with the actual translation as response. The method receives the current language as a parameter and in the example we are using axios to retrieve a json file matching the translationKey of the language.

import axios from 'axios'

const proxy = {
    getTranslation: function ({ translationKey }) {
        return axios.get(`static/lang/${translationKey}.json`).then(function (response) {
            return response.data
        })
    }
}

Vue.use(VueI18nManager, { store, proxy })

Take in mind that a translation found in the translations object has priority over the proxy

Default language persistency

The plugin handle out of the box persistency of the language in the browser via localStorage but it's well known that, in specific cases, is not the best solution to handle browser data.

It is possible then to pass a localStorage object to the proxy which will handle the process.

In this case we use storage-helper which will replace all localStorage functionalities but with a better support.

import storageHelper from 'storage-helper'

const proxy = { 
    localStorage: storageHelper
}

Vue.use(VueI18nManager, { store, proxy })

results matching ""

    No results matching ""