Skip to content

Instantly share code, notes, and snippets.

@RobertCalise
Last active August 29, 2015 14:04
Show Gist options
  • Save RobertCalise/088076be6db100491ac2 to your computer and use it in GitHub Desktop.
Save RobertCalise/088076be6db100491ac2 to your computer and use it in GitHub Desktop.
Simple text replacement with jQuery.
<!DOCTYPE html>
<html>
<head>
<title>jQuery Translation Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var translate = {
"Hello, world!": "Bonjour tout le monde!",
"This is an example.": "Ceci est un exemple."
};
$.each(translate, function(key, value) {
$('body').html($('body').html().replace(key, value));
});
});
</script>
</head>
<body>
<h1>Example</h1>
<p>Hello, world!</p>
<p>This is an example.</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment