minitranslate.js

A lightweight way to change words into other words.

Type here...

...see it translated here.

Sample Library

Key Value

Features

Fast translations.

Quick RegExp matching finds the words that need to be replaced inside of a div and does it quickly.

Dead-simple library.

Word-pair library is stored in JSON format in mt-lib.js and is easy to edit both in advance and on-the-fly.

Case-insensitive.

Works with any variation of uppercase and lowercase letters and will match them.

Customizability.

Ability to ignore a div and its children or monitor a div for any changes.

Make your own!

Makes it extremely easy to make your own translator - all you need is a language in JSON-format (or a little bit of creativity)!

One tiny package.

The minified file is only 2kb in size - perfect for small web projects and quick additions to existing text interfaces.


Installation

Grab either minitranslate.js or minitranslate.min.js and include it (or a link to it on cdnjs) in your index.html along with your translations library (add the library first):

<script src="js/mt-lib.js"></script>

<script src="js/minitranslate.js"></script>

Edit mt-lib.json and add as many word-replacement pairs as you so desire, just make sure it stays in the same directory as minitranslate.

Static translation:

Simply add the class "mt-translate" to a div and watch as it is translated according to your library.

Dynamic translation:

Add two <input> divs with IDs:

<input id="mt-input"/>

<input id="mt-output"/>

Whenever the input's content is changed, the output's will be the translation according to all word-pair matches in your library.