gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 18:49:12 26 4
gpt4 key购买 nike

我已将应用程序的默认语言设置为印地语(即系统默认语言以外的语言)并使用谷歌的 API(PlaceAutocomplete、GoogleSignIn)。

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

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

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

最佳答案

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

SharedPreferences 中选择语言并保存语言值。每当启动应用程序后,检查语言首选项的值,然后选择它们。

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

对于默认的英语,然后将所有字符串放在 values 中。对于印地语,您需要设置 values-hi。对于其他语言,将字符串与国家代码放在一起也会发生同样的事情。国家代码来自 here .

 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();

public static void updateLanguage(Context context,String 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;
}

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

关于android - 如何以应用程序的默认语言设置 google api 对话框的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39449629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com