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.
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
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 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
I have two projects
Project1 contains a strings file with entry (values, values-ar) for Arabic and English accordingly.
Project2 which include Project1 and must override the entry of strings file with Arabic text in both (values, values-ar)
When I put its value in arabic it doesn't show my text, but when I add English text it works
I have tried it many times and I don't know what the problem is, can anyone help please.
Android chooses the right string file according to device's language.
Placing the Arabic Strings on files at rec/values-ar/ folder and setting device's language to "ar" will work.
If project 2 is exclusively Arabic remove the values-ar and place all your Arabic text within the values folder.
Ensure that every string value in Project1's values is placed within Project2's values file in Arabic to override all English values.