What is internationalization?!?

Internationalization is the designing of a product in such a way that it will meet the needs of users in many countries or can be easily adapted to do so. Internationalization might mean designing a website so that when it is translated from English to Spanish the layout still works — many words in Spanish have more characters and therefore take up more space on the page in Spanish than in English.

quote by: https://www.investopedia.com/terms/i/internationalization.asp

Open Source to the rescue

Thanks to the restless open source community you won’t have to reinvent an i18n solution. Just to give you an idea let’s mention two mature solutions to translate your vue.js app here:

vue-i18n by kazuya kawaguchi (@kazupon on github)

Made by @kazupon a core contributor of vue.js

Easy to get started with

powerful enough for most use cases (lacks some features like proper pluralization for languages having multiple pluralforms or possibility for gender specific translations)

learn more reading the documentation

vue-i18next by Claudio Romano (@panter on github)

based on i18next: learn once — translate everywhere

extendable, powerful i18n features

plugins for language detection, loading, caching, …

learn more reading the documentation and the i18next documentation for translation functionalities like plural, context, …

From internationalization to localization

As you can see in the getting started guide of vue-i18n making your vue.js application fit for translation is not as daunting as it seemed first. Honestly it’s rather easy.

Now let us show you how easy the next step could be doing the same for localization.

After enabling the developers it’s time to enable your localization team to translate your product.

Step 1: Creating a fast translation loop — continuous localization

Our goal is to extend vue-i18n to to use it’s existing missing function to directly send new texts to the translation managment tool and to directly load translations from there.

This enables the localization team / translators to start with translations immediately plus keeps a fast feedback loop by having the translations in development without having to export and copy those files from the translation management to the codebase.

To make this magic happen we will use locize.com as our weapon of choice:

locize is a new online service that offers true continuous localization.

quote by: https://alternativeto.net/software/locize/

It’s time for some code — show me your code

First we will need to add the provided locizer script to our page to connect the locize translation management with our code:

<!DOCTYPE html>

<html>

<head>

<script src=”https://unpkg.com/vue/dist/vue.js"></script>

<script src=”https://unpkg.com/vue-i18n/dist/vue-i18n.js"></script>

<script src=”https://unpkg.com/locizer/locizer.min.js"></script>

</head>

// ...

Now let’s use the new script to automatically detect the user language and to load the translations from locize:

<script>

locizer

.init({

fallbackLng: 'en', // load this if detected lng is not support

referenceLng: 'en', // the source language

projectId: [PROJECTID], // your locize project id

apiKey: [APIKEY] // your locize api key

})

.load('translations', (err, translations, detectedLng) => {

// build message catalog format

var messages = {};

messages[detectedLng] = translations; // Create VueI18n instance with options

const i18n = new VueI18n({

locale: detectedLng, // set locale

messages: messages, // set locale messages

}) // Create a Vue instance with `i18n` option

new Vue({ i18n }).$mount('#app')

})

</script>

So now we’re already loading the translations from the locize CDN directly from our project. To switch language only append ?lng=[yourLanguage] to your url (for more options have a look detection options).

Directly loading translations from the CDN

Our translators could easily add new languages, translate the content or change existing content.

Time to have new paths sent to locize automatically

Just use the existing missing function of vue-i18n and pipe that call to the locizer script:

// Create VueI18n instance with options

const i18n = new VueI18n({

locale: detectedLng, // set locale

messages: messages, // set locale messages

missing: function(locale, path, vue) {

// pipe to locize - that key will be created for you

locizer.add('translations', path, path);

}

})

Awesome. Now we have our code connected with our translation management. Developers could create new content that is automatically passed to the translation management. Translators could do their job without having to beg for latest source files and do not need to send latest translations to development and wait for those files to be integrated into the latest build.

The power of true continuous localization

Step 2: Enable translations to be in high quality

Localization is hard. Even harder if you have to guess the context during translations. So lets improve this by enabling translations directly inside your vue.js app.

InContext editor enabled

To add the incontext editor we will need to add an additional script first:

<script src="https://unpkg.com/locize-editor/locize-editor.js"></script>

A little configuration:

locizeEditor.init({

lng: detectedLng,

defaultNS: 'translations',

referenceLng: 'en',

projectId: [PROJECTID]

})