如何使用应用程序的默认语言设置google api对话框的文本

UME*_*492 15 android locale google-api google-places-api google-signin

我在hindi中设置了应用程序的默认语言(即系统默认语言除外)并使用google的api(PlaceAutocomplete,GoogleSignIn).

两者都显示英文文本(系统默认语言),而不是印地文或应用程序的默认语言.

有什么办法,我可以强制它们加载应用程序的默认语言,或者我可以传递我的默认应用程序的语言.

谢谢.这真的很有帮助.寻找任何更新.

Sav*_*een -1

你不能设置系统默认语言。如果你想提供多种语言。那么从 区域设置中你可以设置语言。默认情况下它是英语,如果你改变了,那就让它像这样。请检查下面的代码。

选择语言并将语言值保存在SharedPreferences中。每次启动应用程序后,检查语言首选项的值,然后选择其语言。

确保每个字符串都应以此形式添加到值文件夹中。

对于默认英语,则将所有字符串放入中。对于印地语,您需要设置values-hi。其他语言也会发生同样的情况,将其字符串与国家/地区代码一起放置。对于国家/地区代码,请从这里开始。

 SharedPreferences sharedPreferences = getSharedPreferences(Common.MYPREFERENCE_LANGUAGE, Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            if (parent.getSelectedItem().equals("English")) {
                Utils.updateLanguage(activity, "en");
                editor.putString("language", "en");

            } else {
                Utils.updateLanguage(activity, "hi");
                editor.putString("language", "hi");
            }
            editor.apply();
Run Code Online (Sandbox Code Playgroud)

公共静态无效updateLanguage(上下文上下文,字符串lang){

    String mlanguage = getlanguage(lang);
    PurplkiteLogs.logError("", " language update " + mlanguage);
    Locale locale = null;
    Configuration config;

    try {
        if (mlanguage.equals("en")) {
            locale = Locale.ENGLISH;

        } else if (mlanguage.equals("hi")) {
             locale = setLocale(context,"hi");

        } else {
            locale = new Locale(mlanguage);
        }

        Locale.setDefault(locale);
        config = new Configuration();
        config.locale = locale;
        context.getResources().updateConfiguration(config,
                context.getResources().getDisplayMetrics());
    } catch (Exception e) {

    } finally {
        mlanguage = null;
        config = null;
        locale = null;
        context = null;
    }
}

private static String getlanguage(String lang) {
    String mlang = null;
    if (lang != null) {
        if (lang.trim().equalsIgnoreCase("hi")) {
            mlang = "hi";
        } else {
            mlang = "en";
        }
    }
    return mlang;
}

public static Locale setLocale(Context context ,String lang ) {
    Locale myLocale = new Locale(lang);
    Resources res = context.getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    Configuration conf = res.getConfiguration();
    conf.locale = myLocale;
    res.updateConfiguration(conf, dm);
    return conf.locale;
}
Run Code Online (Sandbox Code Playgroud)

谢谢,希望这能帮助您解决问题并理清您的概念。