0

I'm not sure if this is a silly question or not but I have an app that I need to make available to other languages. I have read a lot about this but I am confused on how to go about it. Do I actually need to translate the entire app into whichever languages I would like or will the system do that? I read the Android doc about using localization (Android docs) and many forum posts. I have read about changing the Configuration in the app but even changing the locale on my device doesn't work. Can anyone please point me in the right direction for this? I want the user to be able to change languages for the app itself as it may be passed around between people with different preferences. Thanks in advance!

3
  • I do guess you do have to translate the whole app to the defined language, or you can use some of the language translators (i dont know how to do it) like the one in facebook for example(translate by Bing). Commented Oct 2, 2012 at 20:53
  • Which bit of the docs you read don't you understand? strings.xml is pretty easy to implement. Commented Oct 2, 2012 at 20:54
  • As I understand it, the localization functionality just lets you swap between different languages after you've done the translation yourself. So for example, instead of hard coding "My Awesome App" as the app's title, you can create a string resource called "title" that points to "My Awesome App" if the devices is localized to English and to "Le App Ze Awesome C'est Moi" if it's French. But the OS won't make any attempt to translate any text for you, so I sure hope you're better at writing in French than I am. Commented Oct 2, 2012 at 20:56

2 Answers 2

3

Basically you need to put strings that you want translated into a file

res/values/strings.xml 

for the default en locale and then e.g. refer to such an entry in code via Resources.getString(R.string.theId) or in other xml files via @string/theId, where theId represents the id of the entry as e.g. in

<string name="theId">Username</string> 

in the xml file.

Now to translate it you create additional

res/values-<lc>/strings.xml 

files where stands for the respective 2 letter locale code.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your response. I have the default strings.xml file. I want the whole app to be translated as opposed to certain strings. So, the main question is do I have to do all the translations (or use a program) and put them in the res/values-<lc>/strings.xml file for each language or will the operating system do the translations?
You have to do the translations. If the operating system could do it, it wouldn't need res/values-<lc>/strings/xml :)
@Simon I understand that logic but I understood it to be that those files were needed in case you had a resource that would change as far as the size or other properties besides the text. I just thought that maybe it was possible and worth exploring with all of the apps that have multi-language capabilities. Guess I was wrong but thanks for the responses
0

To add support for more locales, create additional directories inside res/. Each directory's name should adhere to the following format:

-b+[+] For example, values-b+es/ contains string resources for locales with the language code es. Similarly, mipmap-b+es+ES/ contains icons for locales with the es language code and the ES country code. Android loads the appropriate resources according to the locale settings of the device at runtime.

For example, the following are some different resource files for different languages: English strings (default locale), /values/strings.xml:

<resources> <string name="hello">Hello</string> </resources> 

French strings (fr locale), /values-fr/strings.xml:

<resources> <string name="hello">Bonjour</string> </resources> 

Use the Resources in your App:

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello" /> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.