How to enable 2 versions of the Serbian language? with latin letters and cyrillic letters

I have an Android application and I want to translate into Serbian, and I need both versions of the language: with Latin letters and with Cyrillic letters. I tried the following options: value-sr-rRS-Latn , value-sr-Latn , value-sr-rRS-Cyrl , value-sr-Cyrl but this does not work. I get this error: android-apt-compiler: [NAMEOFAPP] invalid resource directory name: [path]\res/value-sr-rRS-Latn

In the Android documentation about res dirs and Locale I cannot find this option.

Can I make 2 dirs with 2 language options? And How?

thanks

+4
source share
2 answers

I just tested the localization of Android, and I found out that you can use any arbitrary region and it will work.

Add a folder to the project with a name like values-sr-rZZ , where ZZ is a dummy area that never existed.

Then add the following code to the Application class, I got it from here and changed a bit:

 public class MainApplication extends Application { @Override public void onCreate() { super.onCreate(); Resources res = this.getResources(); Configuration conf = res.getConfiguration(); boolean isLatinAlphabet = PreferenceManager.getDefaultSharedPreferences(this)... // get a value from the application settings if(conf.locale.getLanguage().equals("sr") && isLatinAlphabet) { conf.locale = new Locale("sr", "ZZ"); res.updateConfiguration(conf, res.getDisplayMetrics()); } } } 

In this code, the locale will only be changed if the user has selected the default Serbian language ( conf.locale.getLanguage().equals("sr") ), and also checked the application settings ( isLatinAlphabet ).

You can use another condition and change it as you like.

Also, such a dynamic way of changing the language may have errors with menu items on older devices, but it does not play on newer devices.

+1
source

Since Android 7.0, Serbian with Latin script has been officially included. values-sr is still used for the Cyrillic script, and values-b+sr+Latn used for the Latin script.

values-sr for cyrillic values-b+sr+Latn for latin

0
source

All Articles