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

99封情书 提交于 2019-12-05 09:27:36
vortexwolf

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!