如果从Play商店下载应用,则无法使用Android语言环境

时间:2019-01-10 14:24:38

标签: javascript android mobile locale

我在我的应用程序中添加了多语言支持,但是当我在调试模式下测试所有语言时,我可以看到所有语言,但是当我在Play商店上发布时,我无法查看所有语言。

每当我单击任何一种语言时,所有文本视图都只有英文(原文)

更改语言(SettingActivity)

 private void showlandailog() {

        final String[] listitems = {"English","हिंदी","Türk","Deutsche","italiano","ગુજરાતી"};
        AlertDialog.Builder mBuilder = new AlertDialog.Builder(SettingsActivity.this);
        mBuilder.setTitle("Choose Language(beta)");
        mBuilder.setSingleChoiceItems(listitems, -1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {


                String name = "show";
                SharedCommon.putSharedPreferencesString(SettingsActivity.this,SharedCommon.keysettingdailog,name);


                if (i==0){

                    setlocale("en");
                    Intent startIntent = new Intent(SettingsActivity.this, MainActivity.class);
                    startActivity(startIntent);
                }
                else if (i==1){

                    setlocale("hi");
                    Toast.makeText(SettingsActivity.this, "hi", Toast.LENGTH_SHORT).show();
                    /*recreate();*/
                    Intent startIntent = new Intent(SettingsActivity.this, MainActivity.class);
                    startActivity(startIntent);
                }
                else if (i==2){

                    setlocale("tr");
                    Toast.makeText(SettingsActivity.this, "tr", Toast.LENGTH_SHORT).show();

                    Intent startIntent = new Intent(SettingsActivity.this, MainActivity.class);
                    startActivity(startIntent);
                }
                else if (i==3){

                    setlocale("de");
                    Toast.makeText(SettingsActivity.this, "de", Toast.LENGTH_SHORT).show();

                    Intent startIntent = new Intent(SettingsActivity.this, MainActivity.class);
                    startActivity(startIntent);
                }
                else if (i==4){

                    setlocale("it");
                    Toast.makeText(SettingsActivity.this, "it", Toast.LENGTH_SHORT).show();

                    Intent startIntent = new Intent(SettingsActivity.this, MainActivity.class);
                    startActivity(startIntent);
                }
                else if (i==5){

                    setlocale("gu");
                    Toast.makeText(SettingsActivity.this, "gu", Toast.LENGTH_SHORT).show();

                    Intent startIntent = new Intent(SettingsActivity.this, MainActivity.class);
                    startActivity(startIntent);
                }

                dialogInterface.dismiss();
            }
        });

        AlertDialog mDialog = mBuilder.create();

        mDialog.show();

    }



    private void setlocale(String lang) {

        Locale locale = new Locale(lang);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,  getBaseContext().getResources().getDisplayMetrics());

        SharedPreferences.Editor editor = getSharedPreferences("Settings", MODE_PRIVATE).edit();
        editor.putString("My_Lang", lang);
        editor.apply();

        SharedCommon.putSharedPreferencesString(SettingsActivity.this,SharedCommon.keylanguage,lang);

    }

    private void loadlocale() {

        SharedPreferences prefs = getSharedPreferences("Settings", Activity.MODE_PRIVATE);
        String Laguage  = prefs.getString("My_Lang", "");
        setlocale(Laguage);




        //Toast.makeText(this, ""+Laguage, Toast.LENGTH_SHORT).show();
    }

加载语言代码

 private void checklanguage() {


        String setlan = SharedCommon.getSharedPreferencesString(NewQRActivity.this, keylanguage,"");

        if (setlan.equals("en")){
            setlocale("en");


        }
        else if (setlan.equals("hi")){

            setlocale("hi");
        }
        else if (setlan.equals("tr")){
            setlocale("tr");

        }
        else if (setlan.equals("de")){
            setlocale("de");

        }
        else if (setlan.equals("it")){
            setlocale("it");

        }

        else if (setlan.equals("gu")){
            setlocale("gu");

        }


        loadlocale();
    }

    private void setlocale(String lang) {

        Locale locale = new Locale(lang);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,  getBaseContext().getResources().getDisplayMetrics());

        SharedPreferences.Editor editor = getSharedPreferences("Settings", MODE_PRIVATE).edit();
        editor.putString("My_Lang", lang);
        editor.apply();

        loadlocale();

        Toast.makeText(this, ""+lang, Toast.LENGTH_SHORT).show();

        SharedCommon.putSharedPreferencesString(SettingsActivity.this,SharedCommon.keylanguage,lang);


    }

    private void loadlocale() {

        checklanguage();

        SharedPreferences prefs = getSharedPreferences("Settings", Activity.MODE_PRIVATE);
        String Laguage  = prefs.getString("My_Lang", "");
        setlocale(Laguage);

        //Toast.makeText(this, ""+Laguage, Toast.LENGTH_SHORT).show();
    }

我的代码或播放控制台是否存在问题?

0 个答案:

没有答案