自定义多语言支持 [英] Custom Multi Language support

查看:84
本文介绍了自定义多语言支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道创建一个新的价值观的目录与语言code后缀的语言。德国:值德或法语:值-FR再复制我们的string.xml到这一点,将每个条目。这工作基础上,手机定位设置

I am aware of Creating a new values directory for the language with the suffix of the language code. For german: values-de or french: values-fr then copy our string.xml into that and translate each entry. And this works based on the Phone Localization settings

我想知道,如果我们可以绕过手机设置,并让用户选择自己的内部应用程序所需的语言?

I wanted to know if we can bypass the phone setting and and make the user select his required language inside the app?

我的要求是,我想给一个语言选择的选项在我的应用程序,使用户选择他想要的应用程序的语言..如何动态的string.xml之间切换(不同语言)???

My requirement is, i want to give a language selection option inside my app, and make the user select the language he wants for the app.. how to dynamically switch between the string.xml (for different languages) ???

在此先感谢

推荐答案

创建方法,设置您的基本Locale.Lets说

Create method which sets your basic Locale.Lets say

public static void setDefaultLocale(Context context,String locale) {
        Locale locJa = new Locale(locale);
        Locale.setDefault(locJa);

        Configuration config = new Configuration();
        config.locale = locJa;

        context.getResources().updateConfiguration(config, context.getResources()
                .getDisplayMetrics());

        locJa = null;
        config = null;
    }

现在(基本上我已经使用菜单语言选择在这里)检查时,用户选择的语言环境。

Now check when user selected Locale.(Here basically I have used menu for language selection).

Configuration config = new Configuration();
String newLocale = config.locale.getLanguage().substring(0, 2)
    .toLowerCase();
if ("ja".equalsIgnoreCase(newLocale)) {
// Call above method with context & newLocale
} 
// Sequentially you check for Locale & change that.

这篇关于自定义多语言支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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