Translate HTML Page Into Different Languages – Translatorjs

Category: Javascript , Text | March 1, 2019
Author: EOussama
Views Total: 230
Official Page: Go to website
Last Update: March 1, 2019
License: MIT

Preview:

Translate HTML Page Into Different Languages – Translatorjs

Description:

Yet another page translation library which can be used to translate the HTML page into any languages defined in a JSON dictionary.

How to use it:

Download and import the Translatorjs library.

<script src="/path/to/translate.min.js"></script>

Add the CSS class trnsjs to strings which will be translated into other languages.

<p class="trnsjs">Hello</p>
<p class="trnsjs">About</p>

Define the strings in different languages as follows:

const dictionary = {
      "About": {
        'fr': 'A propos',
        'es': 'nos'
      },
      "Hello": {
        'fr': 'Bonjour',
        'es': 'Hola',
      }
};

Initialize the Translatorjs library.

const translator = new Translator(dictionary);

Switch between languages.

translator.translate('fr');
translator.translate('es');

You Might Be Interested In:


Leave a Reply