I would like to provide support for the Flemish language in my Android app, but as per ISO 639-1 there is no separate code for this language. How can I then do this?
Bear in mind that the resource qualifier can combine language and country. Although Dutch and Flemish are both ISO 639-1 nl, you can attach a region qualifier as well to further specify the region.
The documentation provides an example for British English:
Also, you might not need to create alternative text for every string. For example, assume the following:
Your application's default language is American English. Every string that the application uses is defined, using American English spellings, in res/values/strings.xml.
For a few important phrases, you want to provide British English spelling. You want these alternative strings to be used when your application runs on a device in the United Kingdom.
To do this, you could create a small file called res/values-en-rGB/strings.xml that includes only the strings that should be different when the application runs in the U.K.
Similarly, you could provide this for Flemish by specifying the resource directory values-nl-rBE.
If the language got no code, then you got rather no other way to "hijack" the code of other language or write own localization engine (or use something existing, but not the framework's one). As for hijacking the existing code, simply pick up that one that your user are most unlikely to face in real life and put your translation there.
using nl-rBE (dutch as used in Belgium) worked for me.
(r is required per the Android localization reference--the r denotes "region".)
http://www.localeplanet.com/icu/nl-BE/index.html
Related
The motivation of this question comes from this other question:
How do I get the current language my app is in? (Not the device's language as specified in the Settings. I want the language that Android resolved to use for my app).
This question has been asked several times on the site, but it fails to consider this corner-case:
Imagine the user has only one preferred language in his device: say German, for example.
My app two strings.xml files: The default one, and one in French (values-fr/strings.xml).
Obviously, Android will resolve to use the default strings.xml in this case.
But if I do any of the following, it will return German:
Locale.getDefault()
getResources().getConfiguration().getLocales().get(0)
getResources().getConfiguration().locale.
(And many other suggestions that I have found on the site)
And who told Android that the default strings.xml file was in German? Why did it made that assumption? The default file could be in Spanish, Italian, Polish...whatever.
Ideally, I would like a method that returns null in this case. Some method that tells me that no match was found for German and Android had to fall-back to the default strings.xml.
Does such method exist?
Put the language name in both strings.xml files. For example, as languageName.
When you get the string for R.string.languageName, it will be the language chosen by Android among the ones you support.
Those functions all return the phone's locale. They have nothing to do with resource localization. So nobody said the strings.xml file was German. The user set the phone to German, and the resource subsystem decided strings.xml was the best match for that. Basically you have the way it works backwards.
I don't think there is a way to get what you want for two reasons:
1)It's supposed to be transparent to the programmer.
2)It doesn't pick one file over the other. It picks independently for each string. So if you have a strings.xml with two strings A and B, and had a german strings file with only A, it would give you the german A and the default B.
From a question received privately:
I'm currently creating an Android app and one of the requirements is that it supports a second language. I've Googled the language codes but I'm not finding the one that I need; could you tell me if you support the Welsh language, which is a place in the United Kingdom? And if so, what is the country code for it?
That would be on Android’s side, not on the IDE side, to support; the resources are bundled within the APK itself and you should put localised strings in a localised values folder within the res/ folder. For example:
res/
values/ # Default locale (e.g., American English)
values-en-rGB/ # British English
values-it/ # Italian (any country)
In general, localisations on Android are defined as a two-letter ISO 639-1 language code, optionally followed by a two letter ISO 3166-1-alpha-2 region code (preceded by lowercase r). Wales is not an independent country, but is part of Great Britain, and as such there is no ISO code for Wales as a region. But, there is a Welsh language code! So you should be able to localise your app by putting your Welsh strings in the res/values-cy or res/values-cy-rGB. The former will be used on all devices that are set to Cymraeg, regardless of the country they’re set to; the latter is specific to devices in Welsh with the country set to Great Britain. For Welsh, the two things are essentially the same, since there aren’t variations of it outside the UK, but this mechanism can be used for example to differentiate Traditional Chinese (zh-rTW) from simplified Chinese (zh-rCN).
For more details on how localisation works on Android, I recommend referring to the Localisation guide on the Android Developers website: https://developer.android.com/guide/topics/resources/localization
For the list of supported ISO languages and countries, you can refer to the Wikipedia: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for the countries, and https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes for the languages.
Someone please explain what is the main idea of using strings.xml?
I think it would be useful for multi-language support but how can we organise it for that?
Do I need it if I don't want to use multi-language support in my android application?
The idea is that it represents a single location for various strings, so your code isn't peppered with string literals. In addition to that, you gain the ability to easily localize. Organization of files for localization is covered here:
http://developer.android.com/guide/topics/resources/localization.html#creating-alternatives
Do you need it if you're not localizing? No. But it may make things easier in the long run, and I would recommend using it just for that reason.
Hard-coding strings is Bad.
Parameterizing strings (e.g. with strings.xml) is Good.
Being able to internationalize your strings (with language and/or locale-specific versions of strings.xml) is even Better :)
PS:
To make use of internationalization, just create resource subdirectories. Google will give you plenty of references/examples. Herre's one:
http://developer.android.com/guide/topics/resources/localization.html
* res/values/strings.xml
Contains English text for all the strings that the application
uses, including text for a string named title.
* res/values-fr/strings.xml
Contain French text for all the strings, including title.
* res/values-ja/strings.xml
Contain Japanese text for all the strings...
And yes, you should absolutely get in the habit of using strings.xml (and colors.xml and dimens.xml etc etc) even if you don't plan on internationalizing immediately.
IMHO....
am wondering if is possible to use a feature on my app that can translate the app to other languages so the user can select through a list of languages so as he can read the app even if he doesnt speak English, thanks a lot
If you use the framework's localization facilities, this will happen automatically based on the user's language setting on their device
http://developer.android.com/guide/topics/resources/localization.html
Basically, instead of using string literals in your code (ie. txt.setText("Something") or android:text="Something"), you create these in your strings.xml file and use the automatically created reference id's.
res/values/strings.xml:
<string name="something">Something</string>
Then, you create alternate res/values folders for the other languages you support and create a similar strings.xml file there.
res/values-es/strings.xml
<string name="something">Algo</string>
Then your layouts and codes would have txt.setText(R.string.something) or android:text="#string/something".
You can do the same thing for drawable, layout, menu, etc.
"to use a feature on my app that can translate the app to other languages"
I do not think such feature exist from Google. But if you write the app according Google's localization guide then you can use our Nativer app, which is designed exactly for that. It takes you language resources - translates with a machine and then let's the crowd to correct it. All these happens in runtime - so you do not need to bother when the language translation finished by the crowd. You can find further info here transround.com
Peter
I have some customers who have volunteered to translate my app's strings into their native languages. Of course they will not be using the Eclipse Android environment to do this, so what Windows-based tool/editor would be appropriate for them to use to work on the XML files that I send them?
I've been following your strategy as well for quite some time. Whenever a volunteer wanted to translate the app, he got the XML file containing all the strings, translated it and sent it back to me.
But people who are not very familiar with computers tend to fail at that task: I often received the XML files back as Microsoft Word documents (.doc) or they translated the XML keys (which become the strings' IDs later) as well.
Therefore I recommend you to use some convenient tool for collaborative translation such as Transifex, crowdin or Get Localization.
You can even use a small website I've set up mainly for myself that offers Android translation as well if you don't want to pay for those services. It's not beautiful, but it should do everything you need.
I use the Notepad++ editor for manipulate xmls, it is very easy to use this application.
If you are looking for an automatic translation tool. I had created one and is available here.
I also created an android string translator and prepared a short video to explain how it works. This video can be opened at the indicated link from screencast. The link links to the location of the Excel file that runs the translation code. The file is code signed, free and ready to go.
https://app.screencast.com/3175zvrfOg6dZ?conversation=DJjUGfR9NPJLPAxLv3Hg5F&tab=Details
`
In Android Studio I developed nine hundred key string pairs relevant to my application.
Android encapsulates each of these strings in a particular format.
Android provides for different languages by retaining a key value and a translated value as part of a unique string. A list of strings needs to exist in the app, for all required languages.
The Program translated 907 strings into twelve different languages. These languages are English, Arabic, Bengali, Chinese, French, Hindi, Indonesian, Japanese, Korean, Portuguese, Russian, Spanish. The total count of strings is close to 11000.
This would be a formidable task if done manually and so a computerized process makes it easier.
These languages are now all set up in my android application.
An android user can choose one of eleven languages to use the application. The translations are based on the visual basic routines created in Microsoft excel. The program backcheck the translated words back into English. The translations do not always carry the intending meaning when backchecked.
For example, when the program translates the English string, False, into Bengali, the program produces a Bengali string. When the program backchecks the Bengali string to English, the result is the English word, lie. There is a connection to the original meaning.
I concluded that the program would be useable in another language. The user would need to pay attention these variations in nuance.