java - If you have the ISO country code `US`, `FR`, how do you get the Locale code (`Locale.US`, `Locale.FRANCE`)? -
if have country code us
, fr
(iso-3166-1 alpha-2 country code), how locale code (locale.us
, locale.france
) this:
system.out.println(decimalformat.getcurrencyinstance(locale.us).format(12.34)); system.out.println(decimalformat.getcurrencyinstance(locale.france).format(12.34)); $12.34 12,34 €
you can't, because locale used hold language, not country. can hold language specific country, , specific variant in country, it's language first. , there no one-to-one relationship between language , country. languages spoken in various countries, , many countries have several languages.
if had country code language, use new locale(code)
. country code, can call getavailablelocales
, loop through results, , find 1 has country code. there might several ones.
Comments
Post a Comment