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?
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.
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.
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
Language which you want to load by default then put that strings.xml
in values
folder without any suffix with values folder
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.
Related
The motivation of this question comes from this other question:
How do I get the current language my app is in? (Not the device's language as specified in the Settings. I want the language that Android resolved to use for my app).
This question has been asked several times on the site, but it fails to consider this corner-case:
Imagine the user has only one preferred language in his device: say German, for example.
My app two strings.xml files: The default one, and one in French (values-fr/strings.xml).
Obviously, Android will resolve to use the default strings.xml in this case.
But if I do any of the following, it will return German:
Locale.getDefault()
getResources().getConfiguration().getLocales().get(0)
getResources().getConfiguration().locale.
(And many other suggestions that I have found on the site)
And who told Android that the default strings.xml file was in German? Why did it made that assumption? The default file could be in Spanish, Italian, Polish...whatever.
Ideally, I would like a method that returns null in this case. Some method that tells me that no match was found for German and Android had to fall-back to the default strings.xml.
Does such method exist?
Put the language name in both strings.xml files. For example, as languageName.
When you get the string for R.string.languageName, it will be the language chosen by Android among the ones you support.
Those functions all return the phone's locale. They have nothing to do with resource localization. So nobody said the strings.xml file was German. The user set the phone to German, and the resource subsystem decided strings.xml was the best match for that. Basically you have the way it works backwards.
I don't think there is a way to get what you want for two reasons:
1)It's supposed to be transparent to the programmer.
2)It doesn't pick one file over the other. It picks independently for each string. So if you have a strings.xml with two strings A and B, and had a german strings file with only A, it would give you the german A and the default B.
Within my app, I let user change the language when they install the app. Lets say they choose "English" while installing the app. But after that if they change the language of the phone to "French" how should my app receive it and change its language?
Assuming you use strings.xml to manage your string resources, Android natively supports localization:
https://developer.android.com/preview/features/multilingual-support.html
The idea is that you have distinct strings and values for each language you want to manage, then when the user changes the language in settings the app will automatically choose the correct file (or fall back to the default strings.xml if you haven't defined resources for the chosen language).
The app will automatically load its respective language strings files from the res/values directory after the application restarts. You could persist and compare Locale.getDefault().getLanguage() to check if the language has changed since the last restart.
It will try to get information about french in values (value-fr) if you didnt add the translations it will keep showing english
hey mates i am Trying to Use other Languages in my App (Persian), and i want it to be Both phone Device Dependant and and Not being Dependant (Phone be English but app be Persian), So if i simply Use R.String.myOtherLang, the App's Out put is some meaningless Number like it Doesnt recognize the language, if i Use getResources().getString(R.String.myOtherLang) , it returns Could not find the Resource Exception if the App's Language be not same (Using values-fa), But when i Enter the Text in Persian directly to the XML layout file, it works Fine, Is there any Way i can Get the language Depenancy from The Phone to User Choice?
OK, you need to you put a file named strings.xml in both values-en and in values-fa.
Then in code you can set the locale to en or fa, respectively and finally apply by restarting the activity (simply finish it before restarting it).
Then it's: getResources().getString(R.String.myString) (note that myString has to have the same name in both the strings files)
I have an android application on eclipse it's text-views and the buttons' texts on Arabic language , I want to localize my application to both Arabic and English users .
Firstly under res folder I have created another folder and named it values-en .
I let the original folder values as is it and later I will use it for Arabic .
My first question it is necessary to create another folder (values-ar) for Arabic localization issues.
Or original values folder is just enough?.
Secondly
On values-en folder I created strings.xml file and added the following statement to it
COMTAS
I set the text of one of the textviews from resource chooser so choose application-title .
after that the textview's text converted to #string/application-title.
the project gives me the following message
NOTE: This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first.
Can someone explains to me how to make localization in simple steps.
And how I can retrieve textviews' texts either in english or arabic (reading from values folder)?
First: Leaving a strings.xml in the "values" folder will cause this language to be "default" (or rather "fallback") language.
Second: The text is read automatically from the strings.xml placed in the values-folder matching your System Locale (the locale you get when you call Locale.getDefault()), e.g. if system locale is set to english, the values are taken from values-en folder. Therefore it would be wise to place the arabic values in a values-ar folder.
I can't say anything related to your compile errors as you didn't post the code causing the error.
It's always good to follow the documentation. Here is the link for Localizing with Resources.
Create a values-ar folder for the arabic language, and let the default language as english. Why?
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.
So if your application is running on a device set to Spanish language, it would still load arabic language (if it's set as default).
English is a most talked language, which would be better to let english by default, ant let the arabic language in values-ar(in my humble opinion).
Hope this helps you.
I am making an app in which I want to implement internationalization.
I have created alternative resources like
res/values-fr/strings.xml
which Contains French text for all the strings, including title
Can anyone tell me what to do next...
thanks
You should always have default strings in res/values/strings.xml, because Android tries to use the most specific resource available. If you have for example res/values-fr/strings.xml and res/values-de/strings.xml and the users phone is set to English, your app will crash because neither de nor fr are applicable for English there are no fallback resources.
After you have specified your default strings and any translations in their respective subfolders, you can use the strings by their qualifiers. For example R.string.some_string. Android will then use the most appropriate translation that is available for the users current device language.
All that and more is explained here: Localizing with Resources
Device will load locale automatically based on system languge. No extra steps required unless you want to change locale in your app independently.