Android app language localization


Android app language localization



I have developed an app. Now I want to support other regional languages in it. But now the app is almost ready, changing each java file to set the texts in the textview for the corresponding language is a big pain. Is there any other simple way to do that? Like making a different string.xml file and doing some stuff, then all the views will get changed???





Check my answer here stackoverflow.com/questions/49726672/…
– hasan_shaikh
Jun 29 at 9:23





No Research has been done before putting up the question on SO.
– nitinkumarp
Jun 29 at 9:27





idownvotedbecau.se/noresearch
– Sander
Jun 29 at 10:01





Others already pointed out the way to localize an app, but if we assume that one would like to support "regional languages" for which there's no system wide support i.e. the user can't choose the language in the Android device's settings, then you'll need to switch the language programmatically.
– Markus Kauppinen
Jun 29 at 10:40





Thanks @MarkusKauppinen
– Neelesh
Jun 29 at 10:50




3 Answers
3



Create alternative resources



A large part of localizing an app is providing alternative text for different languages. In some cases you also provide alternative graphics, sounds, layouts, and other locale-specific resources.



An app can specify many res// directories, each with different qualifiers. To create an alternative resource for a different locale, you use a qualifier that specifies a language or a language-region combination. (The name of a resource directory must conform to the naming scheme described in Providing Alternative Resources, or else your app cannot compile.)



Example:



Suppose that your app's default language is English. Suppose also that you want to localize all the text in your app to French, and most of the text in your app (everything except the app's title) to Japanese. In this case, you could create three alternative strings.xml files, each stored in a locale-specific resource directory:



res/values/strings.xml Contains English text for all the strings
that the app uses, including text for a string named title.


res/values/strings.xml



res/values-fr/strings.xml Contain French text for all the strings,
including title.


res/values-fr/strings.xml


res/values-ja/strings.xml



If your Java-based code refers to R.string.title, here is what happens at runtime:


R.string.title



If the device is set to any language other than French, Android loads title from the res/values/strings.xml file.
If the device is set to French, Android loads title from the res/values-fr/strings.xml file.
Notice that if the device is set to Japanese, Android looks for title in the res/values-ja/strings.xml file. But because no such string is included in that file, Android falls back to the default, and loads title in English from the res/values/strings.xml file.



If you properly used resource references (like R.string.hello) You can create another language configuration and it should be properly loaded. If you "hard coded" strings within JAVA code with literals like "hello world" You have quite a bit of refactoring to do.


R.string.hello


"hello world"



Yes, you can follow this link and create the different string file as per your languages need.
http://www.theappguruz.com/blog/multi-language-support-to-android-app






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift