Skip to content

tryggvigy/x-translate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

x-translate

See the component page for more information.

<x-translate>

This custom element helps with client-side i18n. Each translatable element has a key attribute translate="" which is then referenced.

Installation

bower install x-translate

How to use

Supported translation methods:

Translate with an object

Translate the h1 element to Icelandic from definitions in an object.

html:

<body>
  <x-translate></x-translate>

  <h1 translate="HEADER"> English! </h1>
</body>

js:

var langIS = {
  HEADER : "Íslenska!"
}

var translator = document.querySelector('x-translate');
translator.use(langIS);
});

JSON file translation

Translation with a JSON file.

html:

<body>
  <x-translate use="IS.json"></x-translate>

  <h1 translate="HEADER"> English! </h1>
</body>

js:

var translator = document.querySelector('x-translate');
translator.use('json');
});

About

A Custom Element providing translation of text.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages