Internationalization of distances in java

2019-04-20 02:07发布

问题:

Is it possible in Java without any extra library to internationalize distances?

I mean it is possible to handle that with date, time, currencies, numbers...

I would have expected to find a NumberFormat.getDistanceInstance or something.

Is there something like that already embedded or should i make my own internationalization system for distances (mostly miles vs kilometers)

回答1:

I would love to hear about such formatter but unfortunately I never did. The problem is, there is no such data in CLDR yet, so it is not to easy to do.

That is to say that people actually think about this for quite a while – see ICU's Measure class. Unfortunately for now, it seems as close you can get is to determine measurement system – see LocaleData and LocaleData.MeasurementSystem.
After that you are on your own. You would need to leave this for translators (they need to actually translate units as well as formatting pattern).



回答2:

No, there's nothing in the JDK to i18n distances, weights and most other measurement units, except for calendars (I know it's not really a unit, but the lunar calendar is quite different from the Gregorian calendar). Even OSs don't have that kind of information.

The only i18n you can do with time, currencies, numbers is the formatting. There's no feature to change the measurement unit.

So you'll need to build your own for distances :S.