How does Android handle unsupported languages?

2019-06-02 10:01发布

问题:

I've made an app that runs in multiple languages, but if the user runs it in an unsupported language, will it display the main one? If it is the case, how can I make it display in English instead?

回答1:

You are right.

Just put your english strings on the strings.xml file, so it will be loaded by default if no other language matches the phone lang.

Hope this helps.



回答2:

if the user runs it in a not supported language, will it display the main one?

The default language, yes See the docs for detailed information.

Whenever the application runs in a locale for which you have not provided locale-specific text, Android will load the default strings from res/values/strings.xml. If this default file is absent, or if it is missing a string that your application needs, then your application will not run and will show an error.


how can I make it to display English instead?

Also see the docs for that, you should use english in the default strings.xml

How to Create Default Resources

Put the application's default text in a file with the following location and name:

res/values/strings.xml (required directory)

The text strings in res/values/strings.xml should use the default language, which is the language that you expect most of your application's users to speak.



回答3:

Depends really what language are you using in your string.xml (main one). If there is no language case for what the user selects in the Settings, the app will load in the default values from the strings.xml



回答4:

Language which you want to load by default then put that strings.xml in values folder without any suffix with values folder



回答5:

In fact when you run your app, the app will check if the locale is available thanks to the string.xml contains in the value-locale folder. If nothing is found the string.xml in values is used so just put english traduction in your string.xml. I hope to be clear.