1.0.2 • Published 5 years ago
jang v1.0.2
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.
Build Sample
tr.js file
module.exports = {
title: "Türkçe",
}
en.js file
module.exports = {
title: "Engilish",
}
Examples
Basic Usage
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.