设置土耳其语和英语区域设置:将土耳其语字符翻译为拉丁语

Isa*_*uru 20 java android locale

我想在英语和土耳其语语言环境中将我的土耳其语字符串翻译为小写.我这样做:

String myString="YA?AT BAYRI";
Locale trlocale= new Locale("tr-TR");
Locale enLocale = new Locale("en_US");

Log.v("mainlist", "en source: " +myString.toLowerCase(enLocale));
Log.v("mainlist", "tr source: " +myString.toLowerCase(trlocale));
Run Code Online (Sandbox Code Playgroud)

输出是:

en source: ya?ar bayri

tr source: ya?ar bayri
Run Code Online (Sandbox Code Playgroud)

但我希望有这样的输出:

en source: yasar bayri

tr source: ya?ar bayr?
Run Code Online (Sandbox Code Playgroud)

这在Java中可行吗?

nd.*_*nd. 38

如果您正在使用Locale构造函数,则可以并且必须将语言,国家/地区和变体设置为单独的参数:

new Locale(language)
new Locale(language, country)
new Locale(language, country, variant)
Run Code Online (Sandbox Code Playgroud)

因此,您的测试程序使用语言"tr-TR"和"en_US"创建语言环境.对于您的测试程序,您可以使用new Locale("tr", "TR")new Locale("en", "US").

如果您使用的是Java 1.7+,那么您还可以使用Locale.forLanguageTag以下方法解析语言标记:

String myString="YASAT BAYRI";
Locale trlocale= Locale.forLanguageTag("tr-TR");
Locale enLocale = Locale.forLanguageTag("en_US");
Run Code Online (Sandbox Code Playgroud)

创建具有适当语言的小写字符串的字符串.


Jon*_*eet 7

我认为这是问题所在:

Locale trlocale= new Locale("tr-TR");
Run Code Online (Sandbox Code Playgroud)

试试这个:

Locale trlocale= new Locale("tr", "TR");
Run Code Online (Sandbox Code Playgroud)

这是用于指定国家和语言的构造函数.


小智 5

你可以这样做:

Locale trlocale= new Locale("tr","TR");
Run Code Online (Sandbox Code Playgroud)

第一个参数是您的语言,而另一个参数是您的国家/地区。