I'm working on localizing an app of mine, and I was reading through the android documentation on localization here. and this line caught my attention:
Put the app's default text in res/values/strings.xml.
The text strings in res/values/strings.xml should use the default language, which is the language that you expect most of your app's users to speak.
now my question is, what if the app's default text is in a right-to-left language lets say Arabic, and you build all the layouts to fit the Arabic language, then how would you deal with LTR languages? how would you tell android that the default language is RTL and Layouts were designed for RTL languages, and to actually flip the layouts when the user choses a LTR languages?
CodePudding user response:
After couple of days of research, reading articles on localization and some tinkering with xml it seems like using an RTL language as the default language and building all your UI in RTL by default is not a good option, and though can be done as explained below, I wouldn't advise doing it this way unless you have an app that has already been build with only RTL language in mind and now you want to support LTR languages without having to go and fix all your layouts manually.
the only thing that you need to do is to force android to use LTR for layouts directions (yes, LTR not RTL, since you already build layouts in RTL but android is expecting it to be LTR and will flip it, so you have to flip it again) and you can do that easily by adding <item name="android:layoutDirection">ltr</item>
into you app theme in styles.xml
.
After that you should create another styles.xml
with a localized qualifier of the supported LTR language(s) and override your app theme and use rtl
for layoutDirection
this time.