Skip to content

Instantly share code, notes, and snippets.

@spuglisi
Created February 14, 2018 15:46
Show Gist options
  • Save spuglisi/a725b96199dca5729a4f19318caf4e17 to your computer and use it in GitHub Desktop.
Save spuglisi/a725b96199dca5729a4f19318caf4e17 to your computer and use it in GitHub Desktop.
simple jed integration
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script src="jed.js"></script>
</head>
<body>
<script>
var request = new XMLHttpRequest();
request.open("GET","de_DE.json");
request.addEventListener('load', function(event) {
if (request.status >= 200 && request.status < 300) {
var jsonData = JSON.parse(request.responseText);
console.log(jsonData);
var entries = jsonData.locale_data.messages;
// quick fix jed fileformat change order.
Object.keys(entries).forEach(function(i) {
var x = jsonData.locale_data.messages[i];
if(x instanceof Array && x.length === 2 && x[0] === null) { // swap array
jsonData.locale_data.messages[i] = [x[1], x[0]];
}
});
var i18n = new Jed(jsonData);
var out = i18n.translate("Hour").fetch();
console.log(out);
} else {
console.warn(request.statusText, request.responseText);
}
});
request.send();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment