Created
February 3, 2017 15:55
-
-
Save amtsh/5cf8feae8dea2307b322f04a773098ee to your computer and use it in GitHub Desktop.
HTML page that provides content in multiple languages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>i18n demo</title> | |
</head> | |
<body> | |
<div id="foo"></div> | |
<div id="bar"></div> | |
<script type="text/javascript"> | |
var translations = [{ | |
elementId: "foo", | |
lang: { | |
en: "Foo", | |
ja: "ooF" | |
} | |
}, { | |
elementId: "bar", | |
lang: { | |
en: "Bar", | |
ja: "raB" | |
} | |
}]; | |
function load(current_lang) { | |
translations.forEach(function(o) { | |
var el = o.elementId; | |
var text = o.lang[current_lang] | |
document.getElementById(el).innerHTML = text; | |
}) | |
} | |
load("en"); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment