Skip to content
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

localeCompare is wrong in Android vs iOS #12597

Closed
maraujop opened this issue Feb 27, 2017 · 9 comments
Closed

localeCompare is wrong in Android vs iOS #12597

maraujop opened this issue Feb 27, 2017 · 9 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@maraujop
Copy link

maraujop commented Feb 27, 2017

Description

It seems that localeCompare works differently in iOS and Android. In Android it doesn't return the expected value.

Reproduction

'a'.localeCompare('A', 'es', { sensitivity: 'base', caseFirst: false })

In Google Chrome in Mac returns 0
in Android 6.0.1 react-native (device and emulator) returns 1
in iOS 10.2 react-native returns 0

It's my understanding that localeCompare is not reliable in Android for anything that is not English. I don't know if this is an error in v8 engine, but I believe this was patched in v8-i18n, so not sure if this can be fixed in RN or not

Additional Information

  • React Native version: 0.39.2
  • Platform: Android 6.0.1
@hey99xx
Copy link

hey99xx commented Feb 27, 2017

Can you try if it's different between iOS 8 and 10? JavaScriptCore version on Android is locked as FB built it from a commit from WebKit repo close to iOS 8 branch, and never changed it. If there's a change in localeCompare implementation, we should see a difference from iOS 8 to 10.

@hey99xx
Copy link

hey99xx commented Feb 27, 2017

react-native does not use v8 on Android by the way, so that's irrelevant.

@maraujop
Copy link
Author

maraujop commented Mar 1, 2017

Yes, you are right I totally forgot it uses JavaScriptCore.

I've checked with an iOS 8.1 and it returns 1 too, so it's also broken. So as you say, there is a difference between iOS 8 and 10. Because my previous tests were in an iOS 10.2.

So, the only fix would be to update WebKit version for Android in RN, which sound like a hot potato.

Anyone knows a workaround to sort international strings?

Thanks, cheers
Miguel

@hey99xx
Copy link

hey99xx commented Mar 1, 2017

I see this polyfill https://github.com/kosmobot/locale-compare-polyfill but

Currently only supports Danish, Norwegian, Swedish and Finish, but more locales can easily be generated (take a look at src/generator.js).

@hey99xx
Copy link

hey99xx commented Mar 5, 2017

@christopherdro This does not look to be Android specific issue, it's related to JavaScriptCore versions. The 'Android' label will be misleading.

@feisan
Copy link

feisan commented Apr 21, 2017

Is there a workaround for this problem now?

@hey99xx
Copy link

hey99xx commented Jul 13, 2017

@maraujop @feisan Looks like FB is building a new version of JSC for Android https://github.com/SoftwareMansion/jsc-android-buildscripts

The README says there's support for more i18n support, but the trade-off is that your apk binary will grow in size.

(For iOS 8, no solution)

@hramos
Copy link
Contributor

hramos commented Sep 21, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

@compojoom
Copy link
Contributor

The issue is closed, but is this ever going to be addressed in RN or are we supposed to build our own version of JSC and distribute it with our Apps???

@facebook facebook locked as resolved and limited conversation to collaborators Sep 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Sep 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

7 participants