I want to localize my webapp. Since localization through javascript only is not recommended I thought using php would be an alternative.
So with php I read a messages.json file that stores all localization data.
$json = file_get_contents("_locales/en/messages.json"); In the header of my webapp I generate some javascript with php according to the user's browser language.
echo "var localeObj = " . $json . ";"; So this is just a var that holds all data from the messages.json file that looks like that
{ "extTitle": { "message": "Test1" }, "extName":{ "message": "Test2" } } Now I want to be able to access each item from the json like
var title = getItem("extTitle"); and it returns Test1. Any idea how to do that?
I am not very familar with json but if I just alert the localeObj it gives me just [object Object].