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