---
description: https://github.com/dakk/jquery-multilang
---

# \[MultiLang] jquery-multilang (ok)

![](https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M1E4Gk2ppVKb4olmnun%2F-MZd5qB0io5BpNUddRhK%2F-MZd8egUrWdnjbb1yvAK%2FScreenshot_5.jpg?alt=media\&token=c9045fe9-c6ac-436c-ac38-1300d1366d0b)

C:\xampp\htdocs\windows\index.html

```
<!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>
```

C:\xampp\htdocs\windows\lang.js

```
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);
```

C:\xampp\htdocs\windows\lang\en.json

```
{
    "example1" : "Example n1",
    "example2" : "Example n2"
}
```
