如何通过用户选择更改应用程序语言? [英] How to change the application language by user choice?

查看:84
本文介绍了如何通过用户选择更改应用程序语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,有一个选项供用户选择语言.整个应用程序应通过选择语言进行更改.语言是从服务器端获取的.

In my project there is a option for the user to select language. The whole application should change by selecting the language. Language is fetched from the server side.

我介绍了各种站点和链接,但找不到更好的解决方案.本地化是不可能的,因为它是一个庞大的应用程序,语言也不是固定的,它是从服务器端获取的并且可以更改.

I referred various sites and links, but couldn't find a better solution. Localization is not possible, because it's a huge app and also language is not fixed , it is fetched from the server side and it can be varied.

还有其他解决方案吗?请帮忙...

Is any other solution is available? Please help...

推荐答案

尽管不建议对Android系统以外的应用程序使用单独的语言.但是您仍然可以更改它.

Although its not recommended to use separate language for your app other than the Android system's . But you can still change it .

下面是代码:

private void setLocale (String localeCode , Bundle b ){
    Log.d(TAG+"set location function: "+localeCode);
    locale = new Locale(localeCode);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
    getApplicationContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
    UserDetail.this.getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
    onCreate(null);
}

在某些用户触发器上使用此方法调用:

Use this method call on some user trigger:

setLocale("en-us",savedInstanceStat); // for english
setLocale("ar",savedInstanceStat); // for arabic

要了解有关android locals的更多信息: http://www.icanlocalize.com/site/tutorials/android-application-localization-tutorial/

To learn more about android locals: http://www.icanlocalize.com/site/tutorials/android-application-localization-tutorial/

这篇关于如何通过用户选择更改应用程序语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆