简体   繁体   English

Android 国际化不适用于某些 Android 设备

[英]Android Internationalization not working for some Android devices

I have an android app that targets the SDK Version 25 and the min SDK 17. This is app is supposed to be in 4 languages : French , Swahili , English and Kirundi .我有一个针对 SDK 版本 25 和最小 SDK 17 的 android 应用程序。这个应用程序应该有 4 种语言:法语斯瓦希里语英语基隆迪语

But for some android devices, all four languages work properly but for some others, all other languages work except Kirundi when the user switches to it.但是对于某些 android 设备,所有四种语言都可以正常工作,但对于其他一些语言,当用户切换到基隆迪语之外,所有其他语言都可以正常工作。

Here is my code:这是我的代码:

public class LanguageSwitcher extends AppCompatActivity {

    //Variables declaration
    private TextView bdi,en,fr,sw;

    private Resources res;
    private DisplayMetrics dm;
    android.content.res.Configuration conf;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_language_switcher);


        bdi = (TextView)findViewById(R.id.bdi); //Kirundi textview
        fr  = (TextView)findViewById(R.id.fr); //francais textview
        en  = (TextView)findViewById(R.id.en); //english textview
        sw  = (TextView)findViewById(R.id.sw); //swahili textview


        res = getResources();
        dm  = res.getDisplayMetrics();
        conf= res.getConfiguration();


        //getting the sharedPreferences 
        SharedPreferences sharedPreferences=getSharedPreferences("profile", Context.MODE_PRIVATE);

        String lang = sharedPreferences.getString("lang","");

        final SharedPreferences.Editor editor = sharedPreferences.edit();

        bdi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                conf.locale = new Locale("rn"); // API 17+ only.
                editor.putString("lang","rn");
                editor.apply();
                res.updateConfiguration(conf, dm);
                startActivity(new Intent(getApplicationContext(),Acceuil.class));
            }
        });
        fr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                conf.locale = new Locale("fr"); // API 17+ only.
                editor.putString("lang","fr");
                editor.apply();
                res.updateConfiguration(conf, dm);
                startActivity(new Intent(getApplicationContext(),Acceuil.class));
            }
        });
        sw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                conf.locale = new Locale("sw"); // API 17+ only.
                editor.putString("lang","sw");
                editor.apply();
                res.updateConfiguration(conf, dm);
                startActivity(new Intent(getApplicationContext(),Acceuil.class));
            }
        });
        en.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                conf.locale = new Locale("en"); // API 17+ only.
                editor.putString("lang","en");
                editor.apply();
                res.updateConfiguration(conf, dm);
                startActivity(new Intent(getApplicationContext(),Acceuil.class));
            }
        });
    }
}

I don't know where I am wrong with my code.我不知道我的代码哪里错了。 I need your help我需要你的帮助

We can use custom fonts.我们可以使用自定义字体。 They can either be Downloadable Fonts or we can give Fonts in XML它们可以是可下载字体,也可以是 XML 中的字体

You can use this link for more info on how to integrate fonts in XML in the Android App.您可以使用此链接获取有关如何在 Android 应用程序中集成 XML 字体的更多信息。

Basically, we can provide the ttf or otf file in the app itself so that we can use the fonts in our app, instead of depending on the OEM font.基本上,我们可以在应用程序本身中提供ttfotf文件,以便我们可以在我们的应用程序中使用字体,而不是依赖于 OEM 字体。

在此处输入图片说明

Check the links for the step by step guide on the Android Developer website.查看 Android 开发人员网站上的分步指南链接。

在 onCreate() 或 super.onCreate() 之前设置您的语言

I made some researches and found that unlike other languages, Kirundi resources should be under res/values-rn-rBI folder instead of res/values-rn folder.我做了一些研究,发现与其他语言不同,基隆迪语资源应该在res/values-rn-rBI文件夹下,而不是res/values-rn文件夹下。 rn as ISO 639-1 language code like for any other language in Android and BI the ISO 3166-1 Alpha-2 Code for the country (Burundi) and that worked. rn作为ISO 639-1语言代码,就像 Android 和BI的任何其他语言一样,该国家/地区(布隆迪)的ISO 3166-1 Alpha-2 代码有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM