有什么方法可以将来自服务器的动态值在android应用中转换为其他语言?

时间:2020-06-23 11:27:33

标签: android string android-studio android-layout translation

我的应用程序为用户提供了根据其要求更改语言的方法。我允许在我的应用程序中使用两种语言。根据用户选择的选项(英语/阿拉伯语)更改应用程序语言。我还为两种语言创建了string.xml。除了来自服务器的值以外,其他所有内容都可以正确显示。它们仅以英文显示。有什么方法可以根据所选语言来翻译和显示这些值?

这是我用于语言翻译的代码-

 SharedPreferences  pref = getApplicationContext().getSharedPreferences("LangPrefs", Context.MODE_PRIVATE);
        String language = pref.getString("lang", "");
        Locale locale = new Locale(language);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,
                getBaseContext().getResources().getDisplayMetrics());

请帮助我。 预先谢谢你。

0 个答案:

没有答案