2.0.0 • Published 1 year ago

basajs v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Basajs

a javascript library that allows your website to be multi-language with ease of use.

Installation

Add script in the <head>:

<script src="https://unpkg.com/basajs@latest/dist/basa.js"></script>

Use It

Basic

<p data-basa="hello"></p>
<p data-basa="greeting"></p>

<button onclick="Basa.changeLang('id')">id</button>
<button onclick="Basa.changeLang('en')">en</button>

<script>
    const dict = {
        hello: {
            id: "halo",
            en: "hello",
        },
        greeting: {
            id: "selamat datang",
            en: "welcome",
        },
    };

    Basa.init({
        languages: ["id", "en"],
        useLocalStorage: true,
        dictionary: dict,
    });
</script>

Nested

const dict = {
    hello: {
        top: {
            id: "halo",
            en: "hello"
        }
    }
}

use it with

<p data-basa="hello.top"></p>

Default Settings

Basa.init({
    languages: [], // language array
    useLocalStorage: false, // if true, localstorage will store the language in the `lang` key which can be used if the client revisits the page, the language will automatically use the one in localstorage
    addActiveClass: false, // if true, it will add the "active" class to the element with the id being the name of one of the provided languages
    dictionary: {} // translation object
});
2.0.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago