Reputation: 872
I have an app with translations in English and Arabic, so I go with android:supportsRtl="true"
in AndroidManifest.xml
.
The problem is that some users are using some RTL languages out of Arabic that has no translation in my app, e.g. Hebrew, so it shows the English translation with RTL.
How can I avoid that and keep RTL support only when the language is Arabic and other RTL languages' users will get the English translation with LTR?
Upvotes: 1
Views: 394
Reputation: 2244
Programatically, you can alter the layout direction for some languages.
if (lang in listOf(...))
theView.layoutDirection = Layout.DIR_RIGHT_TO_LEFT
Or, you can use android:layoutDirection
attribute.
some_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layoutDirection="@integer/viewDirection"
...
Define default viewDirection
in values/viewDirection.xml
.
<integer name="viewDirection">0</string>
// 0 is for left to right
And also in the rtl
language resource folder
values-ar/viewDirection.xml
<integer name="viewDirection">0</string>
// 1 is for right to left
You have to specify layout direction in all concerned views but some dialog's may still be in rtl
mode.
It might be worth to check the documentation for LayoutInflater.Factory2
.
Maybe, there is a much simplier way to solve this problem.
Upvotes: 1