New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix android quirks (navigator.languages is empty on Android >= 5.0) #74

Closed
wants to merge 3 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@shaolin405mi16
Contributor

shaolin405mi16 commented Apr 10, 2016

Hi,

I encountered an issue on Cordova + jQuery + jquery-localize on Android 5.0 and up (confirmed on 5.0 / 5.1 / 6.0 AVD emulators). I guess it is the same issue as issue #72 .

This issue happens when navigator.languages returns an empty array [] although navigator.language itself contains a value. Seems like it's happening on Android 5.0 and up (see also: “navigator.languages is empty in webview”)

In line 20 of src/jquery.localize.coffee, the argument for normalizeLang() is (unexpectedly) set to undefined:

$.defaultLanguage = normaliseLang(if navigator.languages then navigator.languages[0] else navigator.language or navigator.userLanguage)

then in the line 14, it fails with the message "Uncaught TypeError: Cannot read property 'replace' of undefined".

So here's the fix for this, ensuring navigator.languages is not empty:

$.defaultLanguage = normaliseLang(if navigator.languages and navigator.languages.length > 0 then navigator.languages[0] else navigator.language or navigator.userLanguage)

I believe this trivial patch has no side effect (for older Android versions / iOS / other browsers).

@shaolin405mi16 shaolin405mi16 changed the title from * fix android quirks (navigator.languages is empty on Android >= 5.0) to fix android quirks (navigator.languages is empty on Android >= 5.0) Apr 10, 2016

@ArkeoSupport

This comment has been minimized.

Show comment
Hide comment
@ArkeoSupport

ArkeoSupport Apr 15, 2016

This fix also solved issue #72

ArkeoSupport commented Apr 15, 2016

This fix also solved issue #72

@oSoMoN

This comment has been minimized.

Show comment
Hide comment
@oSoMoN

oSoMoN Sep 6, 2016

This also fixes a similar issue in oxide (a web engine based on the chromium content API).
Although it clearly is a bug in the web engine / webview, it’s easy enough to work around in jquery-localize, so I would like to see this fix included.

oSoMoN commented Sep 6, 2016

This also fixes a similar issue in oxide (a web engine based on the chromium content API).
Although it clearly is a bug in the web engine / webview, it’s easy enough to work around in jquery-localize, so I would like to see this fix included.

@coderifous

This comment has been minimized.

Show comment
Hide comment
@coderifous

coderifous Oct 13, 2016

Owner

Thanks for contributing @shaolin405mi16 ! Your work merged here: eaa980b

Owner

coderifous commented Oct 13, 2016

Thanks for contributing @shaolin405mi16 ! Your work merged here: eaa980b

@coderifous coderifous closed this Oct 13, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment