facebook / hermes

A JavaScript engine optimized for running React Native.
https://hermesengine.dev/
MIT License
9.54k stars 612 forks source link

Android: PlatformNumberFormatterICU does not support currencyDisplay=narrowSymbol #600

Open mcuelenaere opened 2 years ago

mcuelenaere commented 2 years ago

Bug Description

Hermes version: 0.8.1 React Native version (if any): 0.65.1 OS version (if any): Android 10 Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): n/a

Steps To Reproduce

  1. Executeconsole.log(new Intl.NumberFormat('en', { currencyDisplay: 'narrowSymbol', style: 'currency', currency: 'USD' }).format(100));
  2. Observe 100 US$ being displayed

The Expected Behavior

$100

Fix

I've traced this down to https://github.com/facebook/hermes/blob/main/lib/Platform/Intl/java/com/facebook/hermes/intl/PlatformNumberFormatterICU.java#L73-L74 calling https://github.com/facebook/hermes/blob/main/lib/Platform/Intl/java/com/facebook/hermes/intl/IPlatformNumberFormatter.java#L213-L219, which does not use https://developer.android.com/reference/android/icu/util/Currency#NARROW_SYMBOL_NAME (which is only available on API>=30).

I could make a rudimentary PR for this, but since we'll be going with a different approach in our project (we need to support Android devices older than 11), I won't be able to validate/test the PR. So instead I created this issue so others have a good starting point if they would want to fix this issue.

regalstreak commented 1 year ago

Facing the same issue

NoahZJY commented 1 month ago

Facing the same issue

The same issue , do you have any solution?

neildhar commented 1 month ago

I apologise we haven't previously responded here. Hermes Intl has been implemented on top of platform APIs which means that it isn't always possible to implement the entirety of Intl, and we've run into problems with varying support on different platforms and versions.

We have plans to migrate our implementation to provide a more feature rich implementation (see the discussion in https://github.com/facebook/hermes/discussions/1211).