Great effort!
Here's how I handled my multi-language message:
To start, I created an array at the top of the page, close to the HEAD tag.
<script type="text/javascript">
var language = {};
</script>
Next, I populated the array with values retrieved from the database using a method that best suits your platform. In this case, I used ASP.NET MVC.
<script type="text/javascript">
language["greeting"] = '@Model.greeting';
language["farewell"] = '@Model.farewell';
//or you can assign values directly
language["hello"] = 'Hello';
language["goodbye"] = 'Goodbye';
</script>
<script src="javascript/translator.js" type="text/javascript"></script>
Finally, you can reference the array in your JavaScript file like so:
translate(“farewell”);
function translate(value){
alert(language[value]);
}
//Alternatively:
alert(language[“hello”]);
I hope this explanation proves helpful for you.