Add i18n and manage translations of a Vue.js powered website

Dobromir Hristov
Jun 28, 2018 · 6 min read
Image for post
Image for post
Vue + Vue Router + Vue-i18n + Lokalise.co

TLDR:

Initial setup

Image for post
Image for post
Setup i18n
Image for post
Image for post
Pass i18n instance to Vue app

Changing the language

this.$i18n.locale = 'fr'
Image for post
Image for post
Simple language switcher

Setting the language as a route parameter

Making it work with Vue Router

Image for post
Image for post
Setup routes file
Image for post
Image for post
Instantiate Router
Image for post
Image for post
Pass router instance to App
Image for post
Image for post
Initial Router guard

Async loading translation strings

Image for post
Image for post
Async load json files
Image for post
Image for post
Separate language files

Using vue-i18n outside Vue components

Cleaning it up

Bonus: Managing translation strings using Lokalise

Hypefactors

Hypefactors Engineering — Setting the new gold standard for…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store