0

The problem that I'm running in to is when setting the Locale programmatically to Albanian (sq-AL) and Montenegran (sr-ME) the locale doesn't seem to be recognised as it defaults back to english. When setting Italian (it) or Spanish (es) there is no issues so I'm unsure what the problem could be. All string.xml's are in the correct format and named correctly. This is the code I am using to set the locale:

        Context context = getBaseContext();
        Resources res = context.getResources();
        DisplayMetrics metrics = res.getDisplayMetrics();
        android.content.res.Configuration conf = res.getConfiguration();
        langCode = "sr-ME"; // Hard setting langCode for testing
        Locale newLocale = new Locale( langCode ) ;
        conf.setLocale( newLocale );
        res.updateConfiguration( conf, metrics );

Much appreciated if anyone can help!

Louis Ferraiolo
  • 409
  • 4
  • 18

3 Answers3

2

"sr-rME" seems to not exist so android reset to default. Here is an exhaustive list of supported languages of android, you may find your answer : What is the list of supported languages/locales on Android?

  • This was initially the problem after changing the targetSdkVersion to 22 and printing out in logcat all the available locales it is displayed there but when setting it still doesn't work. – Louis Ferraiolo Jul 19 '18 at 12:48
1

In my opinion you should try something like that, because "sr-rME" is for value folder name :

`langCode = "sq"; // or 'sr-ME'  for Montenegran
Locale newLocale = new Locale( langCode ) ;`

Else if Montenegran is your default phone language you can get it by typing that: Locale current = getResources().getConfiguration().locale;

1

The problem was the way I was setting the locale. The correct way to set a locale when using region-specific locales is by using both arguments in initialising Locale. For sr-ME (Montenegran) it should be initialised like this:

Locale newLocale = new Locale( "sr", "ME" );
Louis Ferraiolo
  • 409
  • 4
  • 18