coderifous / jquery-localize

a jQuery plugin that makes it easy to internationalize your web site.
465 stars 142 forks source link

Callback not working with Phonegap + Onsen UI #101

Open qroft opened 5 years ago

qroft commented 5 years ago

I am developing a hybrid app with Phonegap and Onsen UI. My console shows me that the language file has been correctly loaded, but the localization does not appear. After several tries, i used the example with the callback from this Github repo together with a simple alert AND a console.log - but nothing happens.

This is my code so far:

var opts = { language: "de", pathPrefix: "/js", skipLanguage: "en-US" }; opts.callback = function(data, defaultCallback) { data.message = "Optional call back works."; $("[data-localize]").css({color: "#FF8833"}); defaultCallback(data); alert("this is an alert for the callback"); console.log("the callback console logger."); } $("[data-localize]").localize("lang", opts)

I have a CSP Meta-Tag that should allow everything (also load local JSON files, afaik). It looks like this: ` meta http-equiv="Content-Security-Policy" content=" default-src 'unsafe-eval' 'unsafe-inline' ; script-src 'self' 'unsafe-inline' 'unsafe-eval' ; worker-src blob:; style-src 'self' 'unsafe-inline' ; img-src 'self' 'unsafe-inline' 'unsafe-eval' "

I am sure that i am missing some privileges somewhere, but i am not able to find the error.`

qroft commented 5 years ago

[UPDATE] It definitely has to do something with the CORS. I have just emulated my app to the browser and there everything works as expected. At the same time, the phonegap console also shows that everything is loaded, but that is untrue. I will now try to figure out hwo to change my META CSP tag so that JSON files are allowed to load locally and as soon as i find out i will post it in here.

qroft commented 5 years ago

[SOLUTION] For some odd reason i had to prepare the phonegap project. It now works. Check that you have the Whitelist plugin installed. Check that you have the config.xml set up properly Check that you have the Content-Security-Policy inside your index.html

Then everything should work fine!