Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include 2 variants of Serbian Language? with Latin letters and with Cyrillic letters

I have an android app and I want to translate to Serbian and I want both variants of the language: with Latin letters and with Cyrillic letters. I tried this variants: value-sr-rRS-Latn , value-sr-Latn , value-sr-rRS-Cyrl , value-sr-Cyrl but not of that is working. I get this error: android-apt-compiler: [NAMEOFAPP] invalid resource directory name: [path]\res/value-sr-rRS-Latn

On Android documentation about res dirs and Locale I can't find this option.

Can I make 2 dirs with 2 variants of the language? And how?

Thank you

like image 936
Daniel Dudas Avatar asked Mar 20 '13 08:03

Daniel Dudas


People also ask

Is Serbian language written in Cyrillic or Latin?

Standard Serbian language uses both Cyrillic (ћирилица, ćirilica) and Latin script (latinica, латиница). Serbian is a rare example of synchronic digraphia, a situation where all literate members of a society have two interchangeable writing systems available to them.

Why does Serbia use both Cyrillic and Latin?

The expansion of the Latin script into Serbia came with the formation of the Kingdom of Yugoslavia at the end of World War I when Latin and Cyrillic were both declared official scripts, as by that time Croatian had adopted the Latin alphabet.

Does Serbian language use Cyrillic?

Cyrillic was enshrined as Serbia's official alphabet in its 2006 constitution, which stipulates that communication between public institutions, as well as between such bodies and the public at large, must be in Cyrillic, except for official communication with “national minorities.”

Why do Serbs use Latin alphabet?

Serbian Alphabets: Latin The Latin script nowadays used equally in Serbia was developed from the first Croatian Latin script originated by Ljudevit Gaj. It was meant to bring together Slovenians, Croatians and Serbians living in Austro-Hungarian empire at the time.


Video Answer


2 Answers

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

values-sr for Cyrillic
values-b+sr+Latn for Latin

like image 79
Liggliluff Avatar answered Oct 05 '22 04:10

Liggliluff


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

Add a folder to the project with name like values-sr-rZZ where ZZ is a fictitious region which never existed.

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

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 be changed only if the user has chosen the serbian language as the default (conf.locale.getLanguage().equals("sr")) and also checked some checkbox in the app preferences (isLatinAlphabet).

You can use a different condition and change it as you like.

Also such dynamic way of changing language can have bugs with menu items on older devices, but it isn't reproduced on newer devices.

like image 27
vortexwolf Avatar answered Oct 05 '22 05:10

vortexwolf