【问题标题】:How can I create an application with the local dialects different?如何创建具有不同地方方言的应用程序?
【发布时间】:2018-10-05 05:45:20
【问题描述】:

我之前测试过这些代码,但给了错误一个过时的语言环境

public static void setLanguage(Context context, String languageCode){
Locale locale = new Locale(languageCode);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;  // Deprecated !!
context.getApplicationContext().getResources().updateConfiguration(config,
        context.getResources().getDisplayMetrics());

}

【问题讨论】:

    标签: java android multilingual


    【解决方案1】:

    您的应用程序中应该有一个名为 String.xml 的文件,位于 res/values/strings.xml

    你应该把你所有的文本放在那个文件里

    例如。

    <resources>     
      <string name="title">Test</string>
      <string name="message">Test</string>
    </resources>
    

    这是您将字符串值设置为 Textview 的方式

    例如。

          <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"     
            android:text="@string/title" />
    

    因此,当您决定要添加更多语言时,您需要在资源文件夹中创建其他 string.xml 文件并在那里添加翻译后的字符串。文件夹“values-hi”下面的示例是指印地语,

    例如。

    MyProject/
    res/
       values/
           strings.xml
       values-hi/
           strings.xml
    

    然后android会根据设备配置自动本地化语言。

    更多详细信息请参考此链接 https://developer.android.com/training/basics/supporting-devices/languages.html

    【讨论】:

    • 是的,我有 String,xml 和你说的值。但我的问题是过时的本地错误。本地已弃用
    • 你不需要使用它。你能像上面的例子一样创建一个新的 string.xml 文件吗?您想将您的应用翻译成什么方言?
    • 我知道应用程序的语言会根据手机的语言而改变。但我想用不同的方言创建一个程序,而不是用不同的语言
    • 你能举一个你想翻译的方言的例子吗?
    • 检查此答案是否对您有帮助 stackoverflow.com/questions/40221711/…
    猜你喜欢
    • 1970-01-01
    • 2016-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    • 1970-01-01
    • 2014-12-31
    相关资源
    最近更新 更多