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!
- 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).baTimá– baTimá2012-10-02 20:53:24 +00:00Commented Oct 2, 2012 at 20:53
- Which bit of the docs you read don't you understand? strings.xml is pretty easy to implement.Simon– Simon2012-10-02 20:54:35 +00:00Commented 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.Andy– Andy2012-10-02 20:56:02 +00:00Commented Oct 2, 2012 at 20:56
2 Answers
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.
3 Comments
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" />