Installation
Two Mi18n is a client-side oriented library. It is designed to be included via a script tag. It is also available as a npm package.
Installation via script tag
<html> <head> ... <script defer src="https://unpkg.com/two-mi18n@latest/dist/TwoMi18n.umd.js"></script> </head> ...</html>
The
defer
attribute in the script tag. It is important to use it to make sure the script is loaded before the page is rendered.
Note the latest
tag in the URL. You can also use a specific version number. Here is the list of available versions.
See unpkg for more details.
<script defer src="https://unpkg.com/two-mi18n@1.0/dist/TwoMi18n.umd.js"></script>
Installation via npm as a module
You can also install Two Mi18n as an npm module.
Note that you will only be able to use the function
translate()
with this method. The functiontranslateHTML()
is only available when using the script tag.
npm i two-mi18n
Now you can use it in your code.
import TwoMi18n from "two-mi18n";
const twoMi18n = new TwoMi18n({ default: "en", translations: { en: { "hello-world": "Hello world", }, fr: { "hello-world": "Bonjour le monde", }, },});
console.log(twoMi18n.translate("hello-world", "fr")); // Bonjour le monde
See
TwoMi18n
class,translation object
, andtranslate()
.