How to change the language of my application based on the language of the keyboard?

StackOverflow https://stackoverflow.com/questions/23577545

  •  19-07-2023
  •  | 
  •  

Вопрос

I am developing an android application. In that application get the language of the keyboard of user android device. If the user keyboard is in French language then The whole application font should be turn into French language.

In that I had tried following demo Example.

In Values->strings

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Localizationdemo</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
</resources>

in Values-fr->strings

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="title">Mon Application</string>
    <string name="hello_world">Bonjour le monde !</string>
</resources>

But in that I only get English language "Hello world" and my keyboard is in French language.

Это было полезно?

Решение

hope that u have written these lines in your code

Locale locale = new Locale("FR");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getApplicationContext().getResources().updateConfiguration(config, null);

because when you set local language as fr it will get the strings from Values-fr same for other language if you set it as it it will consider as you are local language italic and e.t.c..

Note: if your device may be not compatible for all the languages, in that case you need to use external ttf

Другие советы

What is your device's language? It won't work if you only change keyboard language. Try setting the device to French.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top