如果您有ISO国家代码`US`,`FR`,您如何获得Locale代码(`Locale.US`,`Locale.FRANCE`)? [英] If you have the ISO country code `US`, `FR`, how do you get the Locale code (`Locale.US`, `Locale.FRANCE`)?

查看:681
本文介绍了如果您有ISO国家代码`US`,`FR`,您如何获得Locale代码(`Locale.US`,`Locale.FRANCE`)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您的国家代码美国 FR (ISO-3166-1 alpha-2国家/地区代码) ,如何获得Locale代码( Locale.US Locale.FRANCE )来执行以下操作:

If you have the country code US, FR (ISO-3166-1 alpha-2 country code), how do you get the Locale code (Locale.US, Locale.FRANCE) to do something like 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 €


推荐答案

你不能,因为Locale用于保存语言,而不是国家。它可以为特定国家/地区以及该国家/地区的特定变体提供语言,但它首先是语言。语言和国家之间没有一对一的关系。大多数语言在不同国家/地区使用,许多国家/地区都使用多种语言。

You can't, because a Locale is used to hold a language, not a country. It can hold a language for a specific country, and for a specific variant in this country, but it's a language first. And there is no one-to-one relationship between a language and a country. Most languages are spoken in various countries, and many countries have several languages.

如果您拥有某种语言的国家/地区代码,则可以使用 new区域设置(代码)。但是使用国家/地区代码,您只需调用 getAvailableLocales ,循环搜索结果,找到包含您的国家/地区代码的结果。但可能有几个。

If you had the country code for a language, you could use new Locale(code). But with a country code, all you can do is call getAvailableLocales, loop through the results, and find one which has your country code. But there might be several ones.

这篇关于如果您有ISO国家代码`US`,`FR`,您如何获得Locale代码(`Locale.US`,`Locale.FRANCE`)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆