leonardovilarinho/vue-multilanguage

How can I use with api

Closed this issue · 1 comments

Hello,
I want to use this with rest api, so I will go first api and I want to use api response data, how can I use like this ?

Hello there,

in your api, you can return some data, for example: { message: 'user.created', user: { name: 'jose' } }.

Your language file should contains user.created property, for example: en: { user: { created: '{name} has created!' }, ... }.

Finally, when you received teh data api, use the method translate for join user namewith the message translated. For example:

// 'data' is result for api: { message: 'user.created', user: { name: 'jose' } }
computed: {
     message() {
         return this.translate(data.message, data.user)
     }
}

In your template: <p>{{ message }}</p>. With it, the result show "jose has created!"