i have a e-ccommerce app is ltr and english languge...i want translate to persian and rtl
Add android:supportsRtl="true" to AndoridManifest.xml and then, you'll need to create another Strings.xml in order to translate the app to Persian or any languages.
Create values-fa in /res directory of your project and then, copy-paste the Strings.xml into the values-fa directory.
Then you'll be able to translate those words in Persian in order to show in the app later. However, Android Studio has Edit Translation for these situations which if you did like I mentioned, click on Open Editor:
Then translating the strings will be pretty easy.
Read: https://developer.android.com/training/basics/supporting-devices/languages
Related
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.
How can I in my android apps allow for several languages in the easiest way possible? I have seen bigger projects use xml files, and the coding of those isn't hard, but I can't seem to integrate it into the code. The other way which is actually very tricky is using booleans but that would require several languages from the start, and I can only supply 2 at this point.
The languages have to be easy to integrate at a late state, so it doesn't require changing several thousand lines, but the initial work has to be done in an early state(the late state integration is for the languages, the early is for support of it)
I'm using android studio
You should read the documentation. It's surprisingly very easy to incorporate multiple languages in your app as you just need to move all your strings into values/strings.xml and then provide other languages with the same string ids but different values at values-[LANGUAGE_ISO_CODE]/strings.xml.
Example
values/strings.xml
<resources>
<string name="app_name">Something</string>
</resources>
For Arabic language
values-ar/strings.xml
<resources>
<string name="app_name">شئ</string>
</resources>
To add support for more locales, create additional directories inside res/.
Each directory's name should adhere to the following format:
-b+[+] For example, values-b+es/ contains string resources for locales with the language code es.
Similarly, mipmap-b+es+ES/ contains icons for locales with the es language code and the ES country code.
Android loads the appropriate resources according to the locale settings of the device at runtime.
For example, the following are some different resource files for different languages: English strings (default locale), /values/strings.xml:
<resources>
<string name="hello">Hello</string>
</resources>
French strings (fr locale), /values-fr/strings.xml:
<resources>
<string name="hello">Bonjour</string>
</resources>
Use the Resources in your App:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello" />
Define all your text in your strings.xml file and avoid hard-coding your text into your app. You can use a third-party translation service to perform all your translations for you.
there are two ways to do so:
using systme's language: to detect the system language and then the app will launch with
this system's language.To do so,
1. first , you need to have all strings of the app not hard coded, meaning you have to have them all defined in the strings file under values folder
2. go to the strings file and on the top toolbar choose the globe icon and choose the second language you want to add.
3. the system will provide you with a translator where to translate each word of your defined strings.
4. once completed , the system will automatically add new strings file under value folder with the second language.
5. now if you change the phone system's language to the second language , the app will open with the second language automatically.
second way to support language without changing the system's language:
1. develop your code with the main language completely
2. you need ,preferably, to avoid hard coding the strings as well. so define all stings in the string file
for each language you want to add, repeat the activities you want to translate with the new language
add button for each language you need to add to the app
code onclicklistener for each button that will direct the app to the activities of its language
I'm using font-awesome for some of my buttons. One of them is a "back" button. On LTR languages, I want the button to be an arrow that points to the left, and on RTL, an arrow that points to the right.
Right now what I'm doing is this:
I'm holding two strings in my "values" folder
<string name="icon_back_ltr"></string>
<string name="icon_back_rtl"></string>
<color name="icon_back_color">#FFFFFF</color>
Then, I check programatically if the device language is an RTL language. If so, I modify the text on the button accordingly.
My question is, is there a better way to do it? One that does not require checking for layout direction programatically? For example, I know I can define the word "Hello" to be in English (using "values") and then to be something else in Hebrew (using "values-iw). The question is, can I define a certain string to be text A in all LTR languages and then to be text B in all RTL languages?
Define two reource driectories values-ldrtl (means "layout-direction-right-to-left") and values-ldltr (means "layout-direction-left-to-right").
Declare in your app manifest that your app supports RTL mirroring.
Specifically, add android:supportsRtl="true" to the <application> element in your manifest file and set targetSdkVersion to 17 or higher.
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 would like to know if there is any good idea how to switch layouts according to application language selected - e.g. switch between left-to-right layout and right-to-left layout. Have different images or written text and ofcourse the position.
I thought doing it using a private member in the application that indicates the current language selected. According to this parameter I can choose the related XML and text etc.
Actualy I might create some LayoutFactory class, although I don't really think it is required.
But will have to create the realted layout XMLs.
Is there any option to put subdirectories under he layout?
Or should I name the files like en_.xml and he_.xml etc?
For values and drawable you can add folders like values-fr for French or values-ja for Japanese. The -fr indicates that if your phone is set to French localization the app will use any folder that has the -fr added to its name. I'm guessing this goes for the layout folder aswell.
You can read about Localization here .