Build-time resource/layout selection in Eclipse for Android? - android

My company ships Android devices to control industrial equipment we make. We only ship one specific device running Android 2.36 that we buy in quantity and load our own app on, so we don't have to worry about accommodating different layouts, resolutions, etc.
We have a customer in Israel who would like us to have the legends on our buttons in Hebrew. Android 2.36 doesn't have good support for Hebrew (or RTL languages in general) so what we thought we would do is replace the text for these buttons with an image of the Hebrew text.
Since Hebrew is not a supported language on these devices I can't just put the whole device in Hebrew and have Android select the layout XML files with the images instead of text to use at runtime, so I think I might have to do it at build time, in other words have some kind of switch or setting that says use THESE layout resources instead of THOSE layout resources when building a Hebrew version of our product.
My Question: What's a good way to do that? Is there a simple way to force it to use a particular set of layout XML files at build time or am I thinking about this wrong?

If you're using Gradle for Android with Android Studio, this would be a fine place to use product flavors:
Have the bulk of your code and resources be in the main sourceset as normal
Define standard and hebrew product flavors in your build.gradle file
Have the normal (non-Hebrew) resources be in a standard sourceset
Have the Hebrew resources be in a hebrew sourceset
Then, a hebrew build will use the Hebrew layouts, while a standard build would use the normal layouts.
If Gradle for Android is not an option, since you control the hardware, you could drop some file in some special spot on the device, and check that when your process starts to determine if you should be in Hebrew-compatibility mode or not. This presumes that the users of the Android device do not have arbitrary access to it (so external storage would be safe) or that you inject the file into internal storage after installing your app (adb shell run-as should handle this, though I have only ever used it for read operations, not write operations).

I was going to say you could use the layout-LANG to specify region based layouts, but I don't think you can do that if the language isn't supported there.
https://developer.android.com/guide/topics/resources/localization.html
Does your app have a settings screen? You could simply have a setting to change all the layouts in run time.
Do you use Android Studio? Android studio allows different build profiles for debug, release, etc. You could set one up for Israel.

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.

Add language into Android Wear 1.5/2.0

If I added Slovak (SK) language (values-sk-rSK and values-sk) to the Android Wear 1.5 apks (framework-res.apk also), language wasn't set to SK automatically even I had SK on the phone.. so for change language on the Wear watches is needed to translate also Wear app on the phone to SK lang..? Or why my translation wasn't loaded on the watches..?
I have a lot of experiences with adding translation into the Android ROM for phones, but seems it works differently on Android Wear...
Thank you for any help...
As stated in this Localization Tips: Design your application to work in any locale documentation, if your application is missing even one default resource, it will not run on a device that is set to an unsupported locale.
For example, the res/values/strings.xml default file might lack one string that the application needs: When the application runs in an unsupported locale and attempts to load res/values/strings.xml, the user will see an error message and a Force Close button.
You may also check this link which explains challenges in resolving Language resources. Be noted that when your Java code refers to strings, the system would load strings from the default (en_US) resource file, even if the app has Spanish resources localized under es_ES. This is because when the system cannot find an exact match, it continues to look for resources by stripping the country code off the locale. Finally, if no match is found, the system falls back to the default, which is en_US.
Here's a related SO thread which might help.

How to support different languages in older Android devices?

I'm trying to create an app in a different language (in particular Tamil). I've just used Tamil text in the places where I'd use strings and the text renders correctly for newer device simulators (I've tested on API 16 and above). However, when I try running on a simulator with API 10, then I just get rectangles in place of characters. How can I get the text to render correctly on these older devices too?
Did you put it in correct res folder? If your app is supporting multiple language, you must have multiple 'values-xx' in your res folder. For example, if your app supports telugu, you need to create 'values-te' folder with strings.xml inside that folder and put your tamil translation in that file. And you also need to have proper font to render. You can check on your device settings > languages and input > language. See if there any preferred language that you're looking for. If not, you need to provide your own fonts in your app.
You can refer your issue here, and also Android Documentation on how to properly handle multiple languages.

Android adding additional languages after app is installed

I have placed the resources to support different languages in appropriate packages as suggested in Android Localization documentation. Is there a way to add additional languages, i.e, resources after the app is installed without having to download and re-install the app. I mean updating the app - adding new resources and even updating some existing ones.
For example if my app initially supported English and French. Now suppose I want to add new language say Hindi and update few of the resources in English. So what is the approach..?
I had this issue, my approach is to create separate folder on the device \data\packageName\languages\
there will be one file called supportedfiles.lang the format of the file will be
English en
Russian ru
...
also in same location you will have the following files
en.lang
ru.lang
the format of each language file ie(en.lang / ru.lang) will be like regular strings.xml
Some text
when you load the application in settings screen you will read the supportedfiles.lang and show to user the supported languages when he choose different language you just need to load the appropriate language file
Maybe it is over kill, but you will have the flexibility to support other languages while the application installed without updating the application just copy the files into /data/package/languages/

Android app support multiple languages

If I want to upload my Android app with an aim of supporting multiple languages, do I have to upload multiple .apks, each designed for the language I would like to support, or do I implement it all into one .apk file?
Note: My app is a game and does not really not contain any Strings in the UI. The UI was made using Photoshop, eg the buttons with text and so on.
If I pack all the languages into one .apk file, how do I check which language the app should use?
Update:
All my images are stored in the assets folder of my project. How would I localize them?
No, you don't need to create multiple APKs, just single APK with Localization, see this http://developer.android.com/training/basics/supporting-devices/languages.html
and this http://developer.android.com/guide/topics/resources/localization.html
before given your question answer,i tell you about multilingual in android basically in android application work in region wise means if i have device in usa -> install one application ->once it install if application was developed for multilingual support then it automatically render those string.
-> now question is how application build in multilingual for that you have to define string.xml for each language for your application will supports.
--for example : res/values <= default
--for Spanish : res/values-es
--for your question answer : if you define image with static way then it does not work.
For games that have images containing text you can use the same method as for normal strings.
Lets say, for strings you will have a strings.xml file under
values-en
values-es
values-de
values-fr
Then for images you can use (beware of the qualifiers precedence)
drawable-es-hdpi
drawable-en-hdpi
drawable-de-hdpi
drawable-fr-hdpi
However this will make your app bigger.
What I usually do is to generate the images programmatically, using a background and then rendering the text using some custom font on top of it. Even if the images are textures to be used on a 3D engine it works fine and I believe is a more reasonable approach.

Categories

Resources