If you have the ISO country code `US`, `FR`, how do you get the Locale code (`Locale.US`, `Locale.FRANCE`)?(如果您有 ISO 国家代码 `US`、`FR`,如何获得区域设置代码(`Locale.US`、`Locale.FRANCE`)?)
问题描述
如果你有国家代码US
、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 Locale(code)
.但是有了国家代码,你所能做的就是调用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.US`、`Locale.FRANCE`)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果您有 ISO 国家代码 `US`、`FR`,如何获得区域设置代码(`Locale.US`、`Locale.FRANCE`)?
基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01