I'm currently working on setting up a web application that needs to be able to use client-side JavaScript for localization, especially since it will need to function offline. In order to achieve this, I have created a function and a JSON array within my JavaScript code:
var l10n = {
"getMessage": function(msg) {
return locales.en.msg;
}
}
along with
var locales = {
"en": {
"applicationName": "This is the application name!",
"msg": "Looks like we've gotta problem."
}
}
However, when I input
l10n.getMessage("applicationName")
, the script consistently returns the "msg" string ("Looks like we've gotta problem." which was included there for troubleshooting purposes).
The issue appears to stem from my l10n.getMessage()
function. Despite its potential simplicity in terms of resolution, my limited knowledge of JavaScript prevents me from determining how to rectify it. Any suggestions on the best approach for correcting this so that it can display the proper message for the specified string?
Your assistance is greatly appreciated!