I read this sentence " Android 2.3 added support for right-to-left (RTL) languages"
and now I want to add RTL support to my app. But I do not know what is qualifiers to add to my layouts.
About res/values/strings.xml , I can named like this res/values-ar/strings.xml
I want to have different layout for RLT languages. I do not want to have just different strings , I also want different layout. What the layout folder name should look like ?
At this moment for the left to right languages it is named
res/lauyots/main.xml
but I do not know how to name it for RTL languages
Is this kind qualifier is present at all ?
You can find -ldrtl and -ldltr qualifiers in Providing resources
res/layout-ldltr/ (Left to Right, default value)
res/layout-ldrtl/ (Right to Left)
#Silwek is right. This is his answer, I am merely putting it here because my answer has been marked as answered.
res/layout-ldltr/ (Left to Right, default value)
res/layout-ldrtl/ (Right to Left)
Old Answer
Check Localization and Multiple Screen Support, they give you idea about resource folders and qualifiers.
You can use locale specific resources and layout like this:
For language specific resources:
res/values/strings.xml
res/values-fr/strings.xml (French)
res/values-ja/strings.xml (Japanese)
For language specific layouts:
res/layout-fr/main.xml
res/layout-ar/main.xml
Using rtl with resources is not a correct approach .. you missed that Devices with RTL locale such Arabic,Hebrew, Persian ... usually enforce all apps ( even with english language only ) to use rtl as language direction and text direction... and here where its dangerous to use rtl in resources because you will cause using your RTL layout for all languages for RTL Locale device. Better to track languages.
Related
I am programming an Android application. This application isn't translated to any right to left language (like Arabic or Hebrew). I've noticed that right to left language people has it in English, but with right to left layout. The drawer menu is on the right instead of the left and the text is right aligned.
What is the good practice to manage this? Should I let the RTL layout because they are used to it or should I force LTR layout because the app is in English?
If you’re not supporting RTL languages you should not support RTL layouts (LTR languages looks pretty bad in RTL languages).
Just add android:supportRtl="false" attribute in your manifest's application tag.
It should solve it.
Even though false is the default value, one of your dependencies can override it to true if you don't set it explicitly.
Confirm that this is the issue by checking the final merged manifest if android:supportRtl is true.
I have developed an app in English language. When i change my android language to a right-to-left (later rtl) language , my app goes rtl layout but I don't want that. I want my app layout to stay left-to-right (later ltr) whether android language is ltr or rtl.
I know there is layoutdirection in a activity attributes but it's not for APIs below 17.
I'd still say to use this:
Add in styles.xml in your Base App theme style:
<item name="android:layoutDirection">ltr</item>
17+ is legitimate.
Just do this in manifest
android:supportsRtl="false"
with support rtl your layout in english is still ltr.
rtl is on only for languages how japanese and so on.
the most devices are already API 17+.
On emulator or device you can change main language, so you can use rtl or rtl layout depend on selected language.
Try to put all of your resources (layouts, strings, drawable ... etc) in rtl language folder like
layout-ar and remove default layout folder
also use values-ar, drawable-ar .... etc only
i think this will force android to read from it.
I'd like to have different layout design based on location. actually I know we can have different layout based on mobile device size.
As you know Android has very good feature that you can inflate all texts in your application based on location which is called Localization.
I am looking for a kind of similar feature that force my android app to inflate suitable layout design based on location.
In Persian and Arabic, the orientation of components is better to be Right-To-Left, although it is possible by designing exact wanted layout, but i don't know how to make it international because regardless of size, I need to have different layout design orientation based on user location, like USA, Germany, Iran and etc.
Is there any easy and automatic way to change layout orientation from left-to-right to right-to-left based on user location? I've checked similar question in stackoverflow, but that solution is not my aim and goal.
thank you :-)
You can use layout subfolders to provide different layouts depending on language direction. (layout-ldrtl).
Also You can provide different layouts depending on language (layout-ar in Your case).
In that case layouts that contained in simple layout folder will be defaults.
More info You can find in developer site
ofcurse, it has some ways to make it works.
RTL Layouts directory(the the right way)
The layout direction of your application. ldrtl means
"layout-direction-right-to-left". ldltr means
"layout-direction-left-to-right" and is the default implicit value.
This can apply to any resource such as layouts, drawables, or values.
For example, if you want to provide some specific layout for the
Arabic language and some generic layout for any other "right-to-left"
language (like Persian or Hebrew) then you would have:
res/
layout/
main.xml (Default layout)
layout-ar/
main.xml (Specific layout for Arabic)
layout-ldrtl/
main.xml (Any "right-to-left" language, except
for Arabic, because the "ar" language qualifier
has a higher precedence.) Note: To enable right-to-left layout features for your app, you must set supportsRtl
to "true" and set targetSdkVersion to 17 or higher.
https://developer.android.com/guide/topics/resources/providing-resources.html
Run time
https://stackoverflow.com/a/23203698
Set LAYOUT_DIRECTION="rtl"
and set GRAVITY="start"
I have made an application in android but now I have to provide arabic language support. I have checked many of answers in stackoverflow but from any answer I didn't get correct answer.
To provide localization support for different languages, we need to add the language specific resources into separate folder. For eg:Inorder to provide layouts for Arabic language
we need to create a separate folder under res folder i.e.,res/layout-ar like this.
In order to access the current language via code we can get the current language by calling
Locale.getDefault().getDisplayLanguage();
for more information look into following links:
for localization :http://developer.android.com/guide/topics/resources/localization.html
for RTL layout mirroring (Arabic like languages):http://android-developers.blogspot.de/2013/03/native-rtl-support-in-android-42.html
Also you may need to use 'onConfigChange' to your 'AndroidManifest' file with option 'locale'
I am just a beginner but I have looked this question up and came up with this:
http://marketplace.eclipse.org/content/android-string-localization#.VG5A_PmUeSp
Eclipse provides string localization. However, when it translated the strings to Arabic, I had to double check the translation because Arabic has Feminism in Grammar and also some plural forms aren't that correct.
In AndroidManifest.xml:
SupportRtL
this will enable alignments of images and text to right in Arabic and left in English
Create two string resource layouts (one English, one Arabic)
string Resource
Add the same string with the same name in the two layouts but change the value of the arabic string in the (ar\strings.xml)
Same goes to each drawable item
(Also for reference I'll add how you can create a resource that ar or RL)
creating arabic resourse
Also either in the base activity to set the base local language
app = (MyApplication)getApplicationContext();
lang = Actions.setLocal(this);using the function:
function
I am working on a android app which uses 29 different languages. I have created the layout according to english language in my resources folder but when the laguage changes the text views n text size changes and overlaps. Is there any way to keep the layouts constant for all laguages so that alignment of textviews and texts remain same?
yes very easy. you create for each language a values folder like values-de or values-en
in each folder you can create strings.xml
<string name="no_items">there are no items</string>
this is for the english one. create it for each language.
If you read the developer documents (here: http://developer.android.com/guide/topics/resources/localization.html#strategies), there is a good description of your problem and some ways to go about solving it. See the section "Design a flexible layout"
You can:
a) Provide different layouts per language with different layout files per language (although this can add a large amount of overhead for you to maintain your app)
or
b) Make a more flexible layout, so when long strings are passed in due to the language, everything adjusts by itself. Then you don't need to worry about which language the user is running in (or can create a lot less layouts specific to the language if some still don't look right).
you can extend TextView to adjust text size automatically to fit in.. an example of custom TextView is given in this answer https://stackoverflow.com/a/3378422/886001