Skip to content

Instantly share code, notes, and snippets.

@madpilot
Created September 16, 2011 00:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madpilot/1220907 to your computer and use it in GitHub Desktop.
Save madpilot/1220907 to your computer and use it in GitHub Desktop.
Client side i18n tranlation demo
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>i18n Demo</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/madpilot/jquery-i18n/master/jquery.i18n.js"></script>
<script type="text/javascript">
var languages = {
en: {
'heading': 'This is being translated client side',
'paragraph': 'This is in English'
},
it: {
'heading': 'Questo è stato tradotto lato client',
'paragraph': 'Questo è in italiano'
}
};
$(function() {
$('#change').change(function(e) {
$.i18n.setDictionary(languages[$(this).val()]);
$('[data-i18n-key]').each(function(i, e) {
$(e)._t($(e).attr('data-i18n-key'))
});
});
});
</script>
</head>
<body>
<select id="change">
<option value="en">English</option>
<option value="it">Italiano</option>
</select>
<h1 data-i18n-key="heading">This is being translated client side</h1>
<p data-i18n-key="paragraph">This is in English</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment