支持马拉地语

Adi*_*Adi 5 android localization

我所有的文本都在string.xml文件中,而这些文件又包含在文件夹中values-hi, values-en。如何指定 Locale marathi 或请让我知道 values 文件夹的语言说明符以获取 marathi 字符串

public void setLanguage(String language) {
    Locale locale = new Locale(language);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    Locale.getAvailableLocales();
    if (checkForLocaleSupport(locale)) {
        getBaseContext().getResources().updateConfiguration(config,
                getBaseContext().getResources().getDisplayMetrics());
    }

}

public boolean checkLocaleSupport(Locale locale){
    Locale[] locs= Locale.getAvailableLocales();
    for(Locale l:locs){
        if(l.equals(locale)){
            return true;
        }
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

在我的主要活动的 oncreate() 方法中,我在设置内容之前将语言设置为 setLanguage("hi") 。然后在设置内容并初始化一个文本视图之后,我正在做 mHeaderText.setText(R.string.my_header); 我的标题是从 values-hi 文件夹中的 string.xml 读取的。但是如果我将语言设置为 "mr" ,则不会从 values-mr 文件夹中获取字符串。非常感谢帮助

Pou*_*hor 5

所以它应该是values-mr我在评论中给你的 2 个链接中的文件夹。

编辑:相关链接:http : //developer.android.com/reference/java/util/Locale.html

http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes