java.util.Locale使国家(地区)使用小写 [英] java.util.Locale making Country LowerCase

查看:488
本文介绍了java.util.Locale使国家(地区)使用小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置

java.util.Locale localeWithoutCountryCode = new Locale("fr_FR");

但是,当我检索其值时,它将返回我"fr_fr"(小写国家/地区),这导致我的消息查找失败. 我希望它能保持原样.

But when I retrieve its value, it returns me "fr_fr" ( Lowercase country) and this is causing my message lookups to fail. I want it to keep the country case as is.

推荐答案

Locale的单参数构造函数完全采用ISO语言作为其参数;您传递的是语言和变体形式.改为使用new Locale("fr", "FR").

The single-argument constructor for Locale takes exactly an ISO language as its parameter; you're passing in a language and variant. Use new Locale("fr", "FR") instead.

如果出于某种原因对此进行了硬编码,则可以使用Locale.FRANCE.

If this is hard-coded for some reason, you can just use Locale.FRANCE.

这篇关于java.util.Locale使国家(地区)使用小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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