Support smart units / unit contexts / preferences

Description

The idea here is to say that you want to format "road distance", and have the correct unit chosen based on the locale and scale.

I had an initial idea on how this could be implemented: simply add another setter to NumberFormatter like this:

Semantics: The regular "unit" setter turns into specifying the input unit; the output unit is the same as the input unit if unitContext is not specified, and the output unit could change if unitContext is specified.

We could decide whether or not to move forward with an API that directly returns the resolved unit, rather than putting it all in the formatter.

The unit preference IDs are already in CLDR data.

Related: https://unicode.org/cldr/trac/ticket/11452

Activity

Show:
Shane Carr
July 25, 2019, 9:29 PM

Moving this to "future" because this is blocked by the CLDR design.

Younies Mahmoud
September 1, 2020, 6:51 PM
Hugo van der Merwe
October 1, 2020, 1:56 PM

We can probably close this ticket soon: as soon as it’s no longer guaranteed that a commit referencing this ticket will be in ICU 68, we should associate with new tickets instead. (Something not successfully cherry-picked into 68 must not be associated with this ticket.)

Shane Carr
October 2, 2020, 12:06 AM

Closing as Fixed. If there are any remaining changes for ICU 68, we can temporarily re-open this ticket, or submit the fix in a follow-up ticket.

Carsten Hagemann
February 15, 2021, 7:55 PM
Edited

Asking because the ticket description + comments didn’t clear it up, is this already usable currently with the latest ICU version?

 

Edit: answered it myself, it was introduced in ICU 68 http://site.icu-project.org/download/68. Use it on Java like this:

Fixed

Assignee

Younies Mahmoud

Reporter

Shane Carr

Components

Labels

None

Reviewer

None

Priority

major

Time Needed

Weeks

Fix versions