Closed shaolin405mi16 closed 8 years ago
This fix also solved issue #72
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.
Thanks for contributing @shaolin405mi16 ! Your work merged here: https://github.com/coderifous/jquery-localize/commit/eaa980b71aec65e136db94b055e7513a78a1623e
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[]
althoughnavigator.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 fornormalizeLang()
is (unexpectedly) set toundefined
:$.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).