开发者

Android localization question

I'm in the process of translating an app. Looking at this, I can see that a lot of countries have several codes for language.

I tried making a folder named values-nb, for Norwegian Bokmål. I changed the locale on my phones to Norway. This worked on my Sony Ericson Xperia 8, but not on the Samsung Galaxy Tab.

I then tried renaming the folder to values-no. It now works on the galaxy tab, but not on the xperia. I create both folders, and it works. But then I have to put the same file in e开发者_StackOverflow社区ach folder!

What if someone chose Norwegian Nynorsk, would I have to create yet another folder so that they don't default to English but get the Norwegian text? values-nn?

I guess my question is this: How do I get this to work? Can I make all these folders and then make them reference the values-no? Please help :)


There's no way under the current search rules to just have a localization for a specific country and be able to search all languages. At least that's my understanding from reading the pages at http://developer.android.com/guide/topics/resources/localization.html You would need to create values-nn-rNO, values-nb-rNO, and values-no-rNO and have duplicate strings.xml entries.

I haven't tried this, but look into string aliases at http://developer.android.com/guide/topics/resources/providing-resources.html#AliasResources


I know this is an old one, but heres a trick to combine no, nb and nn as no:

Locale locale = getResources().getConfiguration().locale;
if (locale.getLanguage().equals("no") || locale.getLanguage().equals("nb") || locale.getLanguage().equals("nn")){
    locale = new Locale("no","NO");
    Configuration config = new Configuration();
    config.locale = locale;
    Resources res = getBaseContext().getResources();
    res.updateConfiguration(config, res.getDisplayMetrics());
}


Not an answer for the original question, but a solution for a related issue and this is a likely destination if you search for a solution for that issue (it was for me).

In our project, we had our resource directories created but for some reason localized strings were ignored.

The issue was with Androids support for generating Pseudolocalized resources. In older versions of Android you did it with this magic in the build.gradle file:

android.applicationVariants.all { variant ->
    // see http://blog.danlew.net/2014/04/16/android-localization-tips/
    if (variant.buildType.isDebuggable()) {
        variant.mergedFlavor.addResourceConfiguration("zz_ZZ")
    }
}

This has changed in later versions of Android and if you use that then you will not get any localization. The new way is just:

buildTypes {
    debug {
        pseudoLocalesEnabled true
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜