15

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 each 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 :)

AmITheRWord
  • 1,363
  • 2
  • 14
  • 36
  • I really can't believe it's this difficult to support a single language. Thanks for posting your question! – DiscDev Jul 24 '15 at 22:17

3 Answers3

14

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

Eric Cloninger
  • 2,260
  • 2
  • 21
  • 26
  • That sucks. It's what I got from them too. I looked into the string aliases, but to my understanding it doesn't really fix anything. I'll have several files with lots of aliases, which still take up some space. :( – AmITheRWord Mar 01 '11 at 22:14
  • 1
    Have anyone tried to change the locale in the applicaton to solve this? If nn or nb, set no? [link](http://stackoverflow.com/questions/2900023/change-language-programatically-in-android) – Cremons Oct 15 '12 at 16:43
  • 1
    How the fark is "nn" _not_ a sublanguage of "no" when "en_CA" is sublanguage of "en" an "sv_FI" is sublanguage of "sv"? Looks like someone messed up roally some time back and now the system can't be changed to ensure backwards compatibility. That, or Ivar Aasen refused Nynorsk to be subordinate Norsk – Nilzor May 29 '15 at 11:39
10

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());
}
skvalen
  • 414
  • 5
  • 9
  • 1
    A good solution if you're controlling the entire stack but not if you're developing a library – Nilzor May 29 '15 at 11:44
  • 2
    Cool trick, but you should use res.getConfiguration() rather than creating a new configuration object. Don't want to lose the other configuration data (font scaling, etc.) – Chicowitz Sep 01 '15 at 21:58
0

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
    }
}