2016-03-08 116 views
3

塞尔维亚语具有拉丁和西里尔字母。在Android的日期和时间选取器小部件中,显示的塞尔维亚语言区域的字母表似乎是西里尔字母,如此处所示。如何更改区域以使用拉丁语塞尔维亚语(而不是西里尔字母塞尔维亚语)

enter image description here

我想,这样的Android部件使用拉丁文字母塞尔维亚改变语言环境。

当前语言/国家代码(产生西里尔语)分别为srRS。因此,我的setLocale的功能被称为

setLocale("sr", "RS"); 

这是部Im不能确定 - 根据localeplanet.com,拉丁塞尔维亚本地代码是sr_Latn_RS。然而,我试过

setLocale("sr_Latn", "RS"); 
//and 
setLocale("sr_Latn_RS", "RS"); 

两者都没有工作(没有发生变化,默认为英语)。根据Android文档,它看起来像setLocale期望两个字母代码。

语言代码是由ISO 639-1定义的两字母小写ISO语言代码(如 作为“en”)。国家代码是由ISO 3166-1定义的双字母 大写的ISO国家代码(如“US”)。 变体代码未指定。

那么如何指定拉丁塞尔维亚语语言环境代码?还是不存在?

回答

-1

你可以请用下面的一个吗?

public class MyApplication extends Application { 
    @Override 
    public void onCreate() { 
     super.onCreate(); 

     Resources res = this.getResources(); 
     Configuration conf = res.getConfiguration(); 
     boolean isLatinAlphabet = PreferenceManager.getDefaultSharedPreferences(this); 

     if(conf.locale.getLanguage().equals("sr") && isLatinAlphabet) { 
      conf.locale = new Locale("sr", "YourContryCode"); 
      res.updateConfiguration(conf, res.getDisplayMetrics()); 
     } 
    } 
} 

注:替换您YourContryCodeconf.locale = new Locale("sr", "YourContryCode");线。

的Manifest.xml

<application 
     android:name=".MyApplication" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/application_name" 
     android:theme="@style/AppTheme"> 

    ... 

</application> 

希望这会帮助你。

0

请在发布问题之前搜索您的查询。它可能以其他一些相关形式回答。

Locale newLocale = new Locale("sr","RS"); 
    Configuration config = new Configuration(); 
    config.setLocale(newLocale); 
    // using this to reference my Activity 
    this.getBaseContext().getResources().updateConfiguration(config, this.getBaseContext().getResources().getDisplayMetrics()); 

,我发现这两个答案适合您的查询 android custom date-picker SOlocale from english to french

编辑

Locale[] locales = Locale.getAvailableLocales(); 
    for(Locale locale : locales){ 
     if(locale.getCountry().equalsIgnoreCase("RS") 
       && locale.getScript().equalsIgnoreCase("Latn")) 
     { 
      Configuration config = new Configuration(); 
      config.setLocale(locale); 
      // using this to reference my Activity 
      this.getBaseContext().getResources().updateConfiguration(config, this.getBaseContext().getResources().getDisplayMetrics()); 
      break; 
     } 
    } 

我知道会有这样做的有效途径,但是你可以得到你需要得到可用的语言环境列表,并得到你想要的语言环境的方向。希望它可以帮助

EDIT-2(最终)

您可以使用构建区域:

Locale locale = new Locale.Builder().setLanguage("sr").setRegion("RS").setScript("Latn").build(); 
setLocale(locale); 
+1

哈哈,确定就可以了,标题是有点误导,但我做我的研究,以帮助您找到做埃里克答案 –

+0

,您可以使用最后的编辑。对不起,这么多的编辑 –

+0

谢谢我会试试这个。 –

1

以前的答案效果很好,如果你只支持棒棒糖以上。但是,如果您使用塞尔维亚语进行编码,您的许多用户群可能不会拥有它。这是一个适用于旧版和新版的解决方案。

private static Locale serbianLatinLocale(){ 

    Locale locale = null; 
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { 
     for (Locale checkLocale : Locale.getAvailableLocales()) { 
      if (checkLocale.getISO3Language().equals("srp") && checkLocale.getCountry().equals("LATN") && checkLocale.getVariant().equals("")) { 
       locale = checkLocale; 
      } 
     } 
    } else { 
     locale = new Locale.Builder().setLanguage("sr").setRegion("RS").setScript("Latn").build(); 
    } 

    return locale; 
} 
相关问题