[TIMOB-27892] Android: Update toLocale*String() methods to support locale/options
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-07-19T14:16:20.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 9.1.0 |
Components | Android |
Labels | DateTimeFormat, Intl, NumberFormat, android, format, locale, localization, parity |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2020-05-08T18:57:40.000+0000 |
Updated | 2020-12-04T20:31:12.000+0000 |
Description
*Summary:*
On Android, the following methods ignore the
locales
and options
arguments. They also ignore the current locale and always use "en-US"
when formatting a string.
* [Date.toLocaleString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
* [Date.toLocaleDateString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
* [Date.toLocaleTimeString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
* [Number.toLocaleString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
* [String.localeCompare()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
* [String.toLocaleLowerCase()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
* [String.toLocaleUpperCase()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
On iOS, the above methods *+do+* support locale/options.
We should add the same on Android for parity and to better support the standard JavaScript APIs.
*Note:*
To add official Intl
support to V8, we would have to #if
it in, but this involves adding the ICU (International Components for Unicode) C++ library which is about 20 MB per architecture. This is too big and is not mobile friendly. Especially since Google Play has a 100 MB limit on APKs. So, the most reasonable solution is to implement this ourselves in Java.
*Alternatives:*
On older Titanium versions, your only option to generate localized strings was via APIs:
* [String.formatDecimal()](https://docs.appcelerator.com/platform/latest/#!/api/Global.String-method-formatDecimal)
* [String.formatDate()](https://docs.appcelerator.com/platform/latest/#!/api/Global.String-method-formatDate)
* [String.formatTime()](https://docs.appcelerator.com/platform/latest/#!/api/Global.String-method-formatTime)
PR (master): https://github.com/appcelerator/titanium_mobile/pull/11698
manually rebase/merged to master, 9_1_X, 9_3_X
*Closing ticket*. Fix verified in SDK version
9.1.0.v20200724110711
,9.2.0.v20200724112452
and9.3.0.v20200724114100
. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/11698 PR (master): https://github.com/appcelerator/titanium_mobile/pull/11830 PR (9.1.x): https://github.com/appcelerator/titanium_mobile/pull/11831 *Test Environment*