How to change the language to use Latin Serbian (instead of Cyrillic Serbian)

Serbian language has latin and cyrillic alphabets. In the Android Date and Time widgets, the displayed alphabet for Serbian locales seems to be Cyrillic, as shown here.

enter image description here

I wanted to change the locale so that android widgets use the Latin Serbian alphabet.

The current language / country code (with Cyrillic) is sr and RS respectively. Therefore, my setLocale function is called

 setLocale("sr", "RS"); 

This is the part I'm not sure about - according to localeplanet.com , the local code for Latin Serbian is sr_Latn_RS . However, I tried both

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

none of them work (no changes, by default - in English). According to the Android documentation, it seems that setLocale is expecting two letter codes.

Language codes are two-letter lowercase ISO language codes (such as "en") as defined in ISO 639-1. Country codes are two-letter uppercase ISO codes (for example, "USA") as defined in ISO 3166-1. Option codes are not specified.

So, how do I specify the Latin Serbian language code? Or does he not exist?

+4
source share
4 answers

The previous answer works well if you only support Lollipop or higher. However, if you code in Serbian, many of your user bases probably won't have this. Here is a solution that works for old and new versions.

 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; } 
+3
source

Please find your request before submitting a question. It can be answered in some other related form.

  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()); 

I found these two answers suitable for your android custom date-picker SO request and from English to French .

EDIT

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

I know that there will be an effective way to do this, however you can get the direction you need to get a list of available locales and get the desired language. Hope this helps.

EDIT-2 (final)

you can create a locale using:

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

To get the latin locale, I first used the code below.

 new Locale.Builder().setLanguage("sr").setRegion("RS").setScript("Latn").build(); 

But this solution did not work on my Android 5.1.1 device (it was still in Cyrillic). So, I removed the region setting as follows:

 new Locale.Builder().setLanguage("sr").setScript("Latn").build(); 
0
source

Can you use below one?

 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()); } } } 

Note: Replace the string YourContryCode in conf.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> 

Hope this helps you.

-1
source

All Articles