Irrelon / jquery-lang-js

i18n Allow instant language switching on HTML pages without reloading the page.
https://www.irrelon.com
362 stars 132 forks source link

Language sometimes reverting back to default when refreshing #136

Closed JVoye closed 3 years ago

JVoye commented 3 years ago

I'm having a strange issue to where sometimes the language reverts back to the default when the pages refresh. I have 3 languages set langpacks, English being the default. This seems to only happen in Chrome, I can't recreate in Firefox or Edge. It doesn't happen on every refresh, just sometimes as if the cookie.js file fails to load.

My script structure in the head is as follows bootstrap 4.5 main css

ajax 3.3.1 first cookie.js jquery-lang.js text/javascript

at the bottom of the body I'm using popper.js bootstrap 4.5 main js

Any ideas on how to resolve this? Thank you.

JVoye commented 3 years ago

If jquery needs to be in the head of my document for the translation to work the rest of my jquery doesn't work, that is unless I have another script at the bottom of the body as well. Any work around for this? Thanks.

Irrelon commented 3 years ago

Hey, the plugin doesn't have any special requirements except that jQuery needs to be present before the library is loaded since the plugin is a jQuery plugin.

If jquery needs to be in the head of my document for the translation to work the rest of my jquery doesn't work

"the rest of my jquery doesn't work" - That seems to be the issue. Do you know why this is? Loading jQuery in the head shouldn't stop it working for any other scripts that need it.

JVoye commented 3 years ago

I found the culprit that was causing the language to occasionally revert back to the default. I'm using the jquery .load to load in my footers to each page from footer.html #footer. The .load is in my main.js file which is the last script on the page. Removing the .load from my main.js file and placing a separate script on each page directly under the lang.init() did improve the situation, but didn't resolve it completely.

The jquery .load() is interfering resulting in the language to occasionally revert back to default on refresh. Removing the .load() feature entirely resolves this issue.

Irrelon commented 3 years ago

Thanks for the feedback. I'll close this now as I don't think I can add anything of value.