Closed Bug 1236623 Opened 8 years ago Closed 8 years ago

Add UnitFormat to mozIntl

Categories

(Firefox OS Graveyard :: Gaia::L10n, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: zbraniecki, Assigned: zbraniecki)

References

Details

Attachments

(1 file)

We have a lot of cases where we need to format byte units in Gaia.

At ECMA 402 we're working on UnitFormat[0] that will cover this, and I'd like to polyfill it in mozIntl for now.


[0] https://github.com/tc39/ecma402/issues/32
Comment on attachment 8704922 [details] [review]
[gaia] zbraniecki:1236623-unitformat > mozilla-b2g:master

I think this is ready for review.

UnitFormat is a mock for https://github.com/tc39/ecma402/issues/32

mozIntl._gaia.getFormattedUnit is our custom function built on top that will select the right unit to ask from UnitFormat.

I started with two types - digital and duration based on CLDR[0].
Duration will allow us to replace current code in SMS[1], while `digital` will be useful in tons of places where we currently use custom code for that. Examples:

 - https://github.com/mozilla-b2g/gaia/blob/6f60c55c63a8c3578e654fc23cd09372a5c25e52/apps/settings/js/modules/storage_helper.js#L16-L35
 - https://github.com/mozilla-b2g/gaia/blob/6f60c55c63a8c3578e654fc23cd09372a5c25e52/shared/js/download/download_formatter.js#L18-L36
 - https://github.com/mozilla-b2g/gaia/blob/4d81092531f36ebbfdb88af56bbd7ab023273429/shared/js/media/media_utils.js#L22-L37
 - https://github.com/mozilla-b2g/gaia/blob/a9399f148859dc9dce73c4f2a2fd7653388aa9bc/apps/system/js/device_storage_watcher.js#L118-L136
 - https://github.com/mozilla-b2g/gaia/blob/01ffe82cf088ca8fda9fe6783dc5cad2c3dde01c/tv_apps/smart-system/js/bluetooth_transfer.js#L101-L116
 - https://github.com/mozilla-b2g/gaia/blob/01ffe82cf088ca8fda9fe6783dc5cad2c3dde01c/tv_apps/smart-system/js/external_storage_monitor.js#L527-L546
 - https://github.com/mozilla-b2g/gaia/blob/01ffe82cf088ca8fda9fe6783dc5cad2c3dde01c/tv_apps/smart-system/js/update_manager.js#L542-L554
 - https://github.com/mozilla-b2g/gaia/blob/0d79de590f319619cd028a813f08f267e596d4a0/tv_apps/smart-system/js/app_install_manager.js#L625-L636

etc.

As I'll be porting the code to this, I may later add one more function in _gaia namespace that will take an Element and localize it to the value instead of returning a Promise<string>.

[0] http://www.unicode.org/cldr/charts/28/summary/pl.html#5642
[1] https://github.com/mozilla-b2g/gaia/blob/a6cb66d322eb721a06d773f559e1bef9bc662e75/apps/sms/views/conversation/js/information.js#L378-L409
Attachment #8704922 - Flags: review?(stas)
Assignee: nobody → gandalf
Comment on attachment 8704922 [details] [review]
[gaia] zbraniecki:1236623-unitformat > mozilla-b2g:master

This took longer than it should have, r=me.  Thanks for the tests!
Attachment #8704922 - Flags: review?(stas) → review+
Thanks!

https://github.com/mozilla-b2g/gaia/commit/ad3661ee496e22e7095ecfea13421743367f325f
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: