<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title tkey="page-main-title">jQuery-multilang Example</title>
</head>
<body>
<div align="center">
<p tkey="example1"></p>
<p tkey="example2"></p>
</div>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="lang.js"></script>
</body>
</html>
var langs = ['en', 'it'];
var langCode = '';
var langJS = null;
var translate = function(jsdata) {
$("[tkey]").each(function(index) {
var strTr = jsdata[$(this).attr('tkey')];
$(this).html(strTr);
});
}
langCode = navigator.language.substr(0, 2);
if (langCode in langs)
$.getJSON('lang/' + langCode + '.json', translate);
else
$.getJSON('lang/en.json', translate);
{
"example1" : "Example n1",
"example2" : "Example n2"
}