我正在尝试本地化我的应用程序,但我遇到了麻烦,无法本地化我的应用程序

时间:2019-01-05 18:06:40

标签: android localization

尝试本地化我的应用程序,但该应用程序未本地化(动态地甚至从应用程序本地化)

我尝试创建一个语言环境帮助器类,我还创建了3个字符串文件 AR zh(默认) fr 但ar或fr均不起作用

import android.content.Context;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;

import java.util.Locale;

public class LocaleHelper {

    public static void setDefaultLocale(Context context) {
        SharakehSharedPreference sharakehSharedPreference = new SharakehSharedPreference(context);
        Locale locale;
        if (null == sharakehSharedPreference.getKey("locale")) {
            sharakehSharedPreference.setKey("locale", "en");
        }
        if (sharakehSharedPreference.getKey("locale").equalsIgnoreCase("en"))
            locale = new Locale("ar");
        else locale = new Locale("en");
        sharakehSharedPreference.setKey("locale", locale.toString());
        locale.setDefault(locale);
        Resources res = context.getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        android.content.res.Configuration conf = res.getConfiguration();
        conf.setLocale(locale);
        res.updateConfiguration(conf, dm);
        }
    }

应用程序应更改语言,但未本地化,请注意,三个字符串文件中存在相同的字符串键 enter image description here

0 个答案:

没有答案
相关问题