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
Related
I want to change the application content from English to Spanish/ French as per the selection. Do we have any build-in libraries for the same. I am new to this multilanguage part, so please help me with this.
You just need to create an additional folder like values-fr (for French) and provide strings.xml with respective values.
here you can find detailed guide:
https://developer.android.com/guide/topics/resources/localization
Create strings.xml(fr) and strings.xml(es) with your translated strings in the respective language.
Use this library to set the language in your app, it manages all the overhead of Configuration Context and other boilerplate code
https://github.com/YarikSOffice/lingver.
This how you create multiple language resources
In android studio
Res-> New -> Android Resource File->
Name the file strings.xml -> Resoure Type Should be value
Select Locale From Available Qualifiers
Select Language and Set region to be any
Click Ok
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
can I change the referring a resource folders programmaticaly. I need to use a language that is not supported by android, in my case Sinhala. can I create a values_sin folder and refer it when user select Sinhala language. can I change the font together with that for entire application.
How about this: put your Sinhala strings in res/values/strings.xml, and the English strings in res/values-en/strings.xml or maybe even better, in res/values-en-rIN/strings.xml. When using the second method, your app will be in English only if the user selects "English (India)" as the phone's language. In any other case, the default resources will be used - which in your case will be in Sinhala!
Edit 2: actually, Android does support Sinhalese, using res/values-si. If you can't select Sinhalese as your device's default language, you could change it at runtime. There are plenty of posts already, such as Changing Locale within the app itself
You can use strings in this way: " R.string.*" or in xml: "android:text=#strings/*" - right?
They all take their values out of a fixed file named strings where you put them all in right?
Let's say I have an app where there is the possibility to change language. Is there a way in which I can change that string file? Let's say have a strings file for English and strings for French or anything.. so i can still use the R.string.* and #string/* but I will get different values depends on the user choice?
The Developer's Guide on Localization covers this.
In short use the same string names, but have different locale folders, like:
res/values/strings.xml for the default language
res/values-fr/strings.xml for French
res/values-ja/strings.xml for Japanese
The OS will load the appropriate language for R.string.hello for you.
I have a current Android app that uses i18n via resources. res/values-es/strings.xml and so on. When I test it on a device with the language set to Espanol it pulls the correct resources, from the values-es file, but the accent characters are way out of whack.
For example, I want to use the lowercase o with an accent (ó). I have tried with the actual character in the strings.xml file (using the character map on Ubuntu to create the string) and with the entity, in either case it comes out like some other character set accent I don't recognize:
The same character looks perfect WITHIN strings.xml when using many different text editors. And the file is UTF-8 (tried recreating it with the Android "wizard" tool in Eclipse to make sure).
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="label_app_version">Versión</string>
</resources>
Now I've used French, and German before in other Android apps, with all sorts of accents, and haven't seen this problem, so I'm entirely confused at the moment. What am I doing wrong this time?
I finally solved this one. I was using a font and calling setTypeface earlier in the code. The font I'm using must not have the special characters needed for the other languages. I need to check to make sure my user's are using a locale that my font supports before setting the font.
I should have realized this and checked it earlier.
So the bottom line is this, if you get strange results with certain characters in different locales, make sure you're not using fonts that don't support those characters. Fall back to not using a font (don't call setTypeface) and test that way.
That diacritic is actually called a breve, common in many eastern european languages. I had the same problems before once. I even have a question here on SO. Since nobody solved the problem, it's worth the shot...
This isn't clear to me yet:
Does it happen only on this project? Did you try others? (maybe a project mistake)
Try including other language folders (try, say, values-fr). Do you have the same problem?
Did you try to build your app inside Eclipse? Did you try building manually on the command line?
Then, you could try:
Instead of the "ó" (here in PT we use the same), try \u00f3. Like: Versi\u00f3n. Do you get the proper latin small o with acute? Just to clear things.
Build your app using ant ($ ant release) manually on the command line. Report back the results.
This may help the guys here (who are much more experienced than I am) guess where the problem can be.
Best regards!
Check how the actual strings.xml file is stored.
In the file tree in Eclipse, right-click on the strings.xml file and select properties.
You will get a properties dialog for the file.
If not selected already, select the "Resource" line in the left column.
Check the "Text file encoding" area at the bottom.
It maybe selected as "default" or a specific encoding such as "UTF-8" selected.
Select the UTF-8 option. Save file. Clean & Build project (to re-gen resources) and then see if any changes.
See attached screenshot.
Suerte, Andrew
This is strange as it should not cause a problem. Maybe you should try to embed string into CDATA section, like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="label_app_version"><![CDATA[Versión]]></string>
</resources>