Yaron Vazana

NLP, Algorithms, Machine Learning, Data Science, tutorials, tips and more

  • About
  • Blog
  • Projects
  • Medium

Contact Me

yaronv99 [at] gmail.com

Powered by Genesis

You are here: Home / Android / Right to Left Support in Your Android App – Tutorial

Right to Left Support in Your Android App – Tutorial

October 29, 2015 by Yaron 3 Comments

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.

Android RTL languages

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

Filed Under: Android, Mobile Tagged With: Android, Android Studio, Apps, Mobile, Right to left, RTL, Translation

I am a data science team lead at Darrow and NLP enthusiastic. My interests range from machine learning modeling to solving challenging data related problems. I believe sharing ideas is where we all become better in what we do. If you’d like to get in touch, feel free to say hello through any of the social platforms. More About Yaron…

SUBSCRIBE TO BLOG

Subscribe to Blog

Subscribe to get the latest posts to your inbox

Recent Posts

  • Training an AutoEncoder to Generate Text Embeddings
  • Using Dockers for your Data Science Dev Environment
  • Identifying Real Estate Opportunities using Machine Learning
  • How to Create a Simple WhatsApp Chatbot in Python using Doc2vec
  • Average Word Vectors – Generate Document / Paragraph / Sentence Embeddings
  • Visualizing Vectors using TensorBoard
  • Training a Doc2Vec Model with Gensim
 

Loading Comments...