My question is much the same as this one, but unfortunately it was never answered.
how to set application locale?
I am actually trying to load the app onto the market place but it is showing that the default language is English when I upload it. I am guessing that there is a setting in the manifest file but can't find it.
All of the text in the app is in German but I just need the application to show this.
You can choose your default language in the parameters in the Market as follow:
1st step
2nd step
3rd step
Last step
My interface is in french but it is basically the same.
If your resources are localized to German then anyone with a German-localized phone should see everything in German.
The answer is in here:
http://www.tutorialforandroid.com/2009/01/force-localize-application-on-android.html
You can also use the default files to force german.
Instead of having:
strings-en.xml
strings-de.xml
strings-ch.xml
...
Use strings.xml only, and put german strings there. Any user will see german.
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.
I'm in the UK, I've created a strings.xml and different graphics for the US English speakers as they call animals by a different name and they spell things differently. I've noticed when creating my app the default in Android Studio is "en-us", how do I change this?
Now, the issue I am having is:
Our phones are set to English (United Kingdom)
They are showing the default images (not the "drawable-en_rUS" ones - USA)
But showing the "strings-en-rUS" strings rather than the default strings.
I've copied the default strings into a generic English folder ("strings-en" & drawable-en), but then in Android Studio if I choose "English(en)" from the drop down, it shows the US images and strings rather than the ones in the "-en" folders.
Clicking "Default(en-us)" in Android Studio then shows all the defaults (UK English).
Really confused by this, I'm assuming there should be a way to set Android Studio to "en-uk" but I cannot find it or anything online to help me. I'm wanting the defaults to be the main one so any other English speakers get the non-US spellings and words.
Any help appreciated.
Means, you want generic strings (UK) needs to be the default for everywhere that speaks English except for the US.
Copy all (UK) string in default string file and copy all (US) string to values-en-rUS directory and implement this code maybe it'll help you:
if(Locale.getDefault().country.equals("US")) {
val locale = Locale("en", "US")
Locale.setDefault(locale)
}
Use this code in start of the app, Application class might be best for it.
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
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.
am wondering if is possible to use a feature on my app that can translate the app to other languages so the user can select through a list of languages so as he can read the app even if he doesnt speak English, thanks a lot
If you use the framework's localization facilities, this will happen automatically based on the user's language setting on their device
http://developer.android.com/guide/topics/resources/localization.html
Basically, instead of using string literals in your code (ie. txt.setText("Something") or android:text="Something"), you create these in your strings.xml file and use the automatically created reference id's.
res/values/strings.xml:
<string name="something">Something</string>
Then, you create alternate res/values folders for the other languages you support and create a similar strings.xml file there.
res/values-es/strings.xml
<string name="something">Algo</string>
Then your layouts and codes would have txt.setText(R.string.something) or android:text="#string/something".
You can do the same thing for drawable, layout, menu, etc.
"to use a feature on my app that can translate the app to other languages"
I do not think such feature exist from Google. But if you write the app according Google's localization guide then you can use our Nativer app, which is designed exactly for that. It takes you language resources - translates with a machine and then let's the crowd to correct it. All these happens in runtime - so you do not need to bother when the language translation finished by the crowd. You can find further info here transround.com
Peter