There comes a time on almost every app life cycle where the owners ask themselves how can we engage more customers. One of the best action you can do to improve your app downloads rate is to translate it into several different languages. Languages written Left to Right are easy, just add a another strings.xml file, translate all your texts there and you’re done. But what about Right to Left languages? this could be a bit tricky.
Right to left languages usually require your elements to be placed on the opposite order, creating a separate view file for each screen is definitely something you can do, but it’s not going to be scalable as your app grows.
Luckily android 4.2 is now fully supports Right to left languages, I’ll explain each step on how to achieve that.
Update Manifest File
Update your androidManifest.xml file to tell your app it now supports Right to left languages.
Translate Strings
Translate your strings.xml file.
Android Studio comes with a built in languages editor to support many translations. Right click on your default strings.xml file and choose “Open Translations Editor” from the menu.
Use the blue globe button to add a new locale. Once you do that you must either translate all your strings or mark the once you don’t want to translate as “Untranslatable”.
Behind the scenes it creates a new folder named “values-XX” where XX is the locale code, and puts there a new strings.xml file with all the translations.
Of course you can do it manually without using the translations editor.
Update Layout Files
Just like in CSS, when you use float:left right, you enforce the element to ignore the default behavior. On Android, the gravity attribute does the same thing. Therefore it is not recommended to use it unless you’re absolutely sure you want this element to be aligned left of right no matter which language the user is using.
Instead of paddingLeft / paddingRight use paddingStart and paddingEnd, the app will determine on which language it runs and will put the padding or margin accordingly.
It also applies to marginLeft and marginRight, just use marginStart and marginEnd (In general, it’s for all the ..Left / ..Right attributes).
Forcing an element to be in certain layout mode can be done using this property: android:layoutDirection.
Android automatically mirrors your layout, just make sure you’re satisfied with the result. In case something went wrong, try to replace elements with other supported and newer once. I found the LinearLayout and the RelativeLayout to work perfectly.
Check is Right to Left on Runime
Use this handy method to determine on run-time if your app runs in Right to left mode
More Languages
Add more translations using google’s paid translations service here.
Note: You need to have an active app on google developer console in order to see this service
Cheers