Git Product home page Git Product logo

jang's Introduction

jang

For client-side language text.

Installation

$ npm install jang

Usage

<!-- html lang attribute default language -->

<!DOCTYPE html>
<html lang="tr">

<head>
    <meta charset="utf-8" />
</head>

<body>
    <jang text="language"></jang>
    <button id="changeBtn" jang="title:title;">
        <jang text="change.title"></jang>
    </button>

    <script src="./index.build.min.js"></script>
</body>

</html>

index.js file

const jang = require("jang");
const en = require('./locales/en.js');
const tr = require('./locales/tr.js');

jang.add('en', en);
jang.add([
    { name: 'tr', value: tr }
]);

// html lang attribute is default language or if it doesn't exist, first added language is default
jang.refresh();

jang.onChange(function (name, value) {
    console.log('current language: ' + name);
});

document.getElementById("changeBtn").addEventListener("click", function (e) {
    jang.set(jang.current == 'tr' ? 'en' : 'tr');
});

document.getElementById("addBtn").addEventListener("click", function (e) {
    var div = document.createElement('div');
    div.innerHTML = `<jang text="language"></jang> 
        <button jang="title:new.title;"> <jang text="new.title"></jang> </button>`;
    document.querySelector('body').append(div);
    jang.refresh();
});

index.build.js file

index.build.js file is generated from index.js with libraries like browserify or babel or parcel or webpack.

tr.js file

module.exports = {
    title: "Türkçe",
}

en.js file

module.exports = {
    title: "Engilish",
}

Examples

This example shows the most basic way of usage.

License

This software is free to use under the JosephUz. See the LICENSE file for license text and copyright information.

jang's People

Contributors

josephuz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.