Internationalization of distances in java

2019-04-20 01:36发布

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)

2条回答
疯言疯语
2楼-- · 2019-04-20 02:34

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).

查看更多
别忘想泡老子
3楼-- · 2019-04-20 02:42

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.

查看更多
登录 后发表回答