technical localization - android

Not picking up values from values-de-rCH/strings.xml but from values-de/strings.xml.
My device locale is set to de-CH and the same is confirmed when I debug the code at some place for loading a JSON based URL config file for other purposes...

Android has different resolution scheme for string file prior to 7.0 and after.
You can find the reference at Android developer website
Language and locale resolution .
Also if your app support different language (not same language but different country) it is better to create folder with language code only. e.g. values-de.
For detail description of naming directories explained at Support different languages and cultures.

https://blog.egorand.me/a-curious-case-of-multiple-locales/
https://developer.android.com/studio/build/shrink-code
According to the above 2 links, it asked me to mention my new region-specific locales e.g de-rCH, to the resConfigs, or set the resConfigs itself as auto. In both cases, it worked for me. I was kind of stuck in this for almost over a week now.
Thanks for your help guys...

Related

Catalan and Basque strings in Android not being used [duplicate]

When you want to add locale-specific resources in Android, you have to add the lowercase ISO-3166-1 code of the language to the resource folder's name. So far so good.
Now I want to add Catalan and Basque strings to my application. According to the ISO list, I would have to add values-ca and values-eu. But will that work, actually?
Edit: With a custom language chooser in your app, you can provide support for languages even when they're not in the device's settings menu. I've made the library that I use for this available on GitHub:
https://github.com/delight-im/Android-Languages
I don't know if Android supports all ISO codes and if these "minor" languages will be displayed at all. If Android is not available in these languages, perhaps the device will not even recognize this language as its default locale and just use es for Spanish.
Can someone help?
Many devices ship with a limited selection of languages in the settings menu, but can actually be set to any system locale using an app such as LocaleSwitch.
It should be pretty easy to test whether Basque is supported by adding a custom locale in LocaleSwitch and then adding the resource folder to see if the system loads the resources from this folder automatically.
Finally, Gingerbread 'support' for Catalan may only reference the inclusion of android.R values since 2.3, though I can't see them in the framework repository.
Actually not all languages are documented at Android docs and many brands did your custom version of Android which may change its list, but be sure that if a device has Catalan and/or Basque suports it will use ISO standard, and the values will got rigth as it is converted with string comparision.
Maybe it would be a good choice to put a handed changer if you got that most devices do not have this support on your tests.
The thing is, if the language is not listed in the language selection list on the device, the resources can never be used as the device can never be put in this configuration by the user.
On the other hand, if the device allows you to select Basque, it will be using this format, and your resources will be used.
We can now create our "values-eu-rES" folder and have our app in Basque, Android Lollipop has made it.
We can create a folder
Basque strings ->
value-eu [Basque]
another folder
Catalan strings ->
value-ca [Catalan]
Adding a new language in LocaleSwitch, you need to type the ISO 639-1 code. For instance, if you want to switch to basque you need to enter "eu". Afterwards, you will see the new locale as "vasco".
That makes me think that basque locale is supported by android.

Create Android app in multiple languages

I have submitted an Android app to Google Play and I see that I can create different descriptions for each language it supports. My question is: can I create a different APK for each language? Alternatively, how can I detect the user's preferred language, so that I can automatically activate that language for the user in the app?
Here is the official tutorial for localizing your app. :)
You can create a different apk for each language ( split-apk ) - but I would not recommend this. Better use the platform function for this and put your strings file in the right path ( values- ) - after this everything is automagically done
no just use the /res/values/strings.xml
for example to choose english language create a folder in same directory of values and call it values-en, for frensh values-fr and so on. the default language of the app is under values/
And if (for some reason) you still need to know witch is the devices language use
Locale.getDefault().getDisplayLanguage();

Using strings from #android:string

I am a bit noob in Android and recently I found out that I can use the predefined string that Android provides as #android:string/cancel or #android:string/ok. At first I thought it was a good idea to use them because is a way to reuse code, but now I am not so sure about that.
What if somebody with a device configured with a language that I don't support install my app?
I assume that the app will use a default language, probably english, but those string from #android:string will get translated to the user's language, so he will end up with a mix of languages.
It this true? What do you think about use #android:string?
Thanks!
EDIT: Apparently my question hasn't been understood properly. I am NOT asking about how to support different languages. My question is about the convenience of use strings defined on #string:android, if it is correct to use them or can be lead to undesirable situation like a mix up of languages in the same application.
To ensure that your strings are appearing properly on devices configured with different languages, you'll want to create different values directories for different languages. For example, your default string values would be kept under values/strings.xml and French string values would be kept under values-fr/strings.xml.
The Android Developer website gives you plenty of information for supporting different languages in your application. http://developer.android.com/training/basics/supporting-devices/languages.html
The android: values (strings, icons, themes, etc.) will differ between devices and Android versions. If you want to use them, it's safest to copy them into your project. So for strings, you wouldn't have to worry about partial translation.
In the ressource folder of your app (res), ther is a folder "values" in it, and in this folder is the string ressource xml (strings.xml).
Usually, your app selects the strings from this file.
But you can add other value folders like this: Just create a new folder and name it "values-countryCode", for example "values-ch" for Switzerland ;)
Your app automaticly chooses the right string ressource, depending on your device's langague settings. If the langague of your device isn't available, it just takes the sting ressource of the default "values" folder.
A list if the country-codes is here.
Further information can be found here.
Hope I helped, and this is what you're looking for!

android localization doesn't work for some languages

I've created a values-he folder with strings.xml file identical to the default strings.xml with translated string values, but running the app both on a Hebrew selected real device and on a Hebrew selected AVD still shows the default English texts. Any ideas why?
EDIT: this was answered - in some cases, Hebrew included, some android devices support deprecated language codes. For Hebrew the old 'iw' code is still supported on some devices instead of 'he'.
This is known to be the case in some other languages.
From the Android Locale class it's said:
Note that Java uses several deprecated two-letter codes. The Hebrew ("he") language code is rewritten as "iw", Indonesian ("id") as "in", and Yiddish ("yi") as "ji". This rewriting happens even if you construct your own Locale object, not just for instances returned by the various lookup methods. Also some devices use he for hebrews too so to be compatible with use both values-iw and values-he
Starting Summer 2021 Google now requires you to upload the bundle (.aab) instead of the .apk file. With that change, if your device does not support a specific language, it will not be downloaded from the Play Store.
Check the solution here.

Adding/Removing the language entries in the "Settings" -> "Select Locale" from Android phone

My question:
How can I add or remove the language entries in the "Settings" -> "Language & keyboard settings" -> "Select Locale"(or "Select Language") in the Android phone from the source code level?
I'll provide more details on what I want and what I have done. Please excuse me if I present any silly understanding or information. I'm pretty new to Android development, starting to learn it several days ago. There is still a lot that I don't know.
More info on what I want:
I'm recently working on a task to localize the entire phone product with new languages(I mean, I'm not working on a specific application. This is why I need to add a new locale in the Settings). When I got the development phone, I found there are only several language entries available in the "Select Locale", such as "English", "French" and "Spain". So first of all, I need to add and display some new language entries to this list, such as "Japanese", "Chinese", "Korean".
I have all the source code of Android platform and my own code, so I think this task can be done by modifying the source code or the resource files somewhere. Unfortunately, I don't know where the code and files are.
The "Hello, L10N" tutorial shows a way to add a new locale from "Custom Locale" at run-time. But what I want is to add the new locales at build time so when the phone is started up, the new locales will be displayed in the "Select Locale" directly without any other actions.
What I have done:
I did a lot of research on the internet before I come here. Here is what I found:
Sinkiru in Stackoverflow asked a question about what I am exactly looking for. See it here. However, nobody else replied him. His own reply only tells where to query the CURRENT language setting, which is not what I want. I personally sent him an email for this question but haven't got his reply.
I searched a lot in Stackoverflow, with the keywords "android locale", "android language", "android new locale" and something similar. Most of the questions in this site are asking how to change the locale of an app, how to add multi-language support for an app, etc.. They are NOT what I want.
I searched a lot in the android-platform Google group(http://groups.google.com/group/android-platform). Some people are asking my question, but after reading through the messages I still don't get my answer.. :-( Here is a list of the posts I read in the group(and I do not get what I want from them):
"OS localization" - I'll talk more below.
"How to add new locale and it's associated font in android source"
"How to add new L0cale"
"Addition and Removal of language from Android Phone"
"Localization, committing new language"
"Additional languages support"
"Localization - new locale - HELP"
Back to the entry "(a)" listed above. In the "OS localization" message thread, Dianne Hackborn, an Android framework engineer, said the following:
"The settings app just shows you all of
the locales that are available in the
platform resources. Adding strings
for a new locale should automatically
have those shown in settings. You
tell the build system which locale
resources to include when it does the
build... unfortunately I can't help
you on that part, but maybe someone
else can."
His words in bold suggest that my task might be done automatically by adding new locale resource to the source code, and by setting up or changing something in the build system. I'm wondering if someone here has ever done the similar thing before? I'm going to give a try tomorrow.
Last but not least, I searched in the official Android developer site. In the "Run and Test the Localized Application" of the "Hello, L10N" tutorial it says something about the available locales in the "Settings" application, but that is basically talking about what to do in the emulator and this shouldn't be what I need. I want it done on a real phone.
I had also dived into the Android platform source code trying to discover something. I started at the $(ANDR_SRC_ROOT)/Packages/app/Settings/src/.../LocalePicker.java. In the LocalePicker::onCreate() method, I noticed this line of code:
String[] locales = getAssets().getLocales();
The code below this line tries to set all the obtained locale names to an ArrayAdapter and then set the adapter to the list view to show. Thus I think the "getLocales()" method is the key to the solution.
I then looked into the getLocales() code. getLocales() is a member method of AssetManager and is declared as native, hence I stepped into the $(ANDR_SRC_ROOT)/frameworks/base/libs/utils/AssetManager.cpp which I GUESS should be the actual implementation of the java getLocales() method. The C++ AssetManager::getLocales() finally leads me to the C++ ResTable::getConfigurations() method in which a member variable "mPackageGroups" is scanned through to retrieve all the available ResTable_config items. Thus I think all the available locales should be added into this mPackageGroups during the system started up. However, I lost in the code at last and couldn't find where the locales are added to the mPackageGroups.
you have to create "values" folder in "res" folder of android's framework-res package. Name of that new folder have to contain country code of your need ie. values-pl-rPL (the rPL part is required) for polish language (for british english: en-rGB, etc), that should be enough - if not - create strings.xml file in that folder, and add there empty "resources" node.
on HTC phones you must also modify /system/customize/CID/default.xml ... That is the file they use to specify locales on their stock roms. If the rom is a WWE, supposedly editing CID is all one need do, but this doesn't always hold true.
I think that a normal application should not add locations to the phone. There are special packages like MoreLocale 2 for that purpose. If you'd add a locale, you'd be responsible not only to provide localisation for your own application but for the whole system!
To create or add multiple languages to your application, first you have to define all you string values in the string.xml in the values folder rather than hard coding them in you program. Then you also have to have different Value folders for different languages, e.g. Value-es for Spanish and Value-fr for french. This should do the job. I dont think the application can change locale by default.
I think you have to edit the
PRODUCT_LOCALES
Present in build/target/product/languages_full.mk , and add and remove the strings assigned to this.
You can define your custom string like zz_zz and add folder values_zz_zz in each of your res folders.
Have not tried this but this might work.
Note: PRODUCT_LOCALES might be overridden somewhere else depending on your build system
For removing languages, if we remove the locale string from PRODUCT_LOCALES, it will work.
I am also looking for a way to add new languages, but just adding to this doesn't help. I think we need to update some low level files or libraries in order to add new languages.

Categories

Resources