adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.94k stars 1.12k forks source link

`NumberField` breaks when value is less than 3 for `locale="ar"` #6861

Open zernonia opened 2 months ago

zernonia commented 2 months ago

Provide a general summary of the issue here

When we set locale to ar, the NumberField breaks when the value is less than 3. Try clicking on decrement in the stackblitz attached.

๐Ÿค” Expected Behavior?

The component should render value 0 to 2 correctly.

๐Ÿ˜ฏ Current Behavior

Breaks when value is less than 3

๐Ÿ’ Possible Solution

No response

๐Ÿ”ฆ Context

No response

๐Ÿ–ฅ๏ธ Steps to Reproduce

https://stackblitz.com/edit/stackblitz-starters-bwt79x?file=src%2Findex.tsx

  1. Click decrement
  2. Observe the input value not showing 2 ุฃูŠุงู…

Version

1.3.1

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

Mac

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

snowystinger commented 2 months ago

Thanks for reporting this. It looks like this is going to be problematic, it doesn't actually include a numeral at all in the response (if I'm understanding this correctly, I do not read or write arabic)

let formatter = new Intl.NumberFormat('ar-AE', {style: 'unit', unit: 'day', unitDisplay: 'long'});
formatter.format(2);

Google translate of the returned string says 2 days, so I feel like adding the numeral in would just make it confusing/repetitive.

I do not know if this constitutes a bug or not in the Intl formatter... or if this is something we need to look into handling on our end. I'll need to bring this up with our Internationalization team.

peter-emad99 commented 2 months ago

Thanks for reporting this. It looks like this is going to be problematic, it doesn't actually include a numeral at all in the response (if I'm understanding this correctly, I do not read or write arabic)

let formatter = new Intl.NumberFormat('ar-AE', {style: 'unit', unit: 'day', unitDisplay: 'long'});
formatter.format(2);

Google translate of the returned string says 2 days, so I feel like adding the numeral in would just make it confusing/repetitive.

I do not know if this constitutes a bug or not in the Intl formatter... or if this is something we need to look into handling on our end. I'll need to bring this up with our Internationalization team.

Arabic is my first language , and i use this package in my app , happy to help or provide any information needed ,Thanks in advance

peter-emad99 commented 2 months ago

i think the issue related to how the arabic language represent the singular and dual counts we don't say 2 days (2 ุฃูŠุงู…) or 1 day (1ูŠูˆู…) then number is included inside the word itself ( ูŠูˆู…ุงู† ) (ูŠูˆู…) so the problem is in parsing , i don't know what will be the possible solution because the parsing should depend on the unit as the word it self change when unit chage ex: unit="hour" 1 ( ุณุงุนุฉ ) 2 (ุณุงุนุชุงู†)

snowystinger commented 2 months ago

Theoretically we should have all the available forms of the unit based on https://github.com/adobe/react-spectrum/blob/22e803a2bb79306336190e7447469dbef2dff48b/packages/%40internationalized/number/src/NumberParser.ts#L252C7-L252C20

if we passed the plural parts out of our getSymbols function, we could possibly use it in our parsing attempts https://github.com/adobe/react-spectrum/blob/22e803a2bb79306336190e7447469dbef2dff48b/packages/%40internationalized/number/src/NumberParser.ts#L262

Right now the literals such as the units/plurals are removed during sanitize https://github.com/adobe/react-spectrum/blob/22e803a2bb79306336190e7447469dbef2dff48b/packages/%40internationalized/number/src/NumberParser.ts#L121 but if fullySanitized comes back as an empty string, we could try matching it to the plural forms?