Android Localization structure of values folder - android

I`m still learning android development and come with one app which I want to localize to multiple languages.
But please help me a little bit with values folder structure. I have main values folder and in it I have analytics.xml, strings.xml,styles.xml,mraid_attr.xml and colors.xml.
When I make new folder for localization, eg: values-fr I must put all of these files in it or just string.xml where I have translated strings?

You can just put your translated strings in your localization folder, but Lint will warn you about non-translated strings.
So if you have configuration strings (i.e no translation needed), create a separate XMl (like config.xml) and let only your translated strings on your localization folders.

Related

How give an opportunity localize my library

Given: library, which open own frames (fragments and activities), with own text fields and strings. Library has three files strings.xml for localization regions, where speak in English, Russian and Ukrainian.
Needs: give for user opportunity localize my library. I can't keep more languages, so it must do library's user.
Variant of solution: create Java-class with all text values (I has bit strings). User can set in this class values from his strings files and it take opportunity to localize by strings.xml file. But this varian so uncomfortable for user.
Question: how give for user opportunity to localize my library's strings?
I can solved this problem. I try to create in project (where uses library) folder with name values-de and put in folder strings.xml with strings names from library, but with another values. And it worked!
So: project-library can use values from project, if then defined with same names, which they defined in library-resources.

Android localization resources

I have just finished developing an android application that I was asked to make. I had also planned to translate it in different languages; below you can see the tree of the folders/files:
Inside strings.xml there are all the values that I am using inside the classes and they are all in Italian, my language (Here you can see an example if needed). I'd like to be able to translate all those fields in English and french as well.
I have read this article -> http://developer.android.com/training/basics/supporting-devices/languages.html
From what I have understood, I'd have to create a folder called values-fr with a strings.xml inside (it will have the same values names, but different translations).
QUESTION
I would like to be able to support English and Italian as well, but I don't understand how to manage the folders. Could you please tell me which option is the correct?
Inside the folder values use strings.xml with Italian (my language) strings. Then create another folder called values-en and, like I did before, create strings.xml with English values
Inside the folder values use strings.xml with English strings. Then create another folder called values-it and then, create strings.xml with Italian values
I guess that the point 2 is the correct solution but I'm not sure. The folder values has English as default language?
Thanks for the attention.
Technically speaking both are valid. values/ is the fallback if a more specific qualifier is not found. There is no written rule that enforces you in having the English strings in values/. It just makes a little more sense to have the English as fallback since it easier to find foreigners that speak English rather than Italian

android localization resource chooser

I have an android application on eclipse it's text-views and the buttons' texts on Arabic language , I want to localize my application to both Arabic and English users .
Firstly under res folder I have created another folder and named it values-en .
I let the original folder values as is it and later I will use it for Arabic .
My first question it is necessary to create another folder (values-ar) for Arabic localization issues.
Or original values folder is just enough?.
Secondly
On values-en folder I created strings.xml file and added the following statement to it
COMTAS
I set the text of one of the textviews from resource chooser so choose application-title .
after that the textview's text converted to #string/application-title.
the project gives me the following message
NOTE: This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first.
Can someone explains to me how to make localization in simple steps.
And how I can retrieve textviews' texts either in english or arabic (reading from values folder)?
First: Leaving a strings.xml in the "values" folder will cause this language to be "default" (or rather "fallback") language.
Second: The text is read automatically from the strings.xml placed in the values-folder matching your System Locale (the locale you get when you call Locale.getDefault()), e.g. if system locale is set to english, the values are taken from values-en folder. Therefore it would be wise to place the arabic values in a values-ar folder.
I can't say anything related to your compile errors as you didn't post the code causing the error.
It's always good to follow the documentation. Here is the link for Localizing with Resources.
Create a values-ar folder for the arabic language, and let the default language as english. Why?
Whenever the application runs in a locale for which you have not provided locale-specific text, Android will load the default strings from res/values/strings.xml.
So if your application is running on a device set to Spanish language, it would still load arabic language (if it's set as default).
English is a most talked language, which would be better to let english by default, ant let the arabic language in values-ar(in my humble opinion).
Hope this helps you.

Set translated languages in application

The default language of my app is English and I translated it into German. But now if I want to export it as an signed application in Eclipse there comes many errors that all string are not translated in other languages like es, fr , it and so on.
How can I export my app as signed application with only two languages and ignore all other languages?
You don't need to translate your app if you don't want to. Just check that all strings are defined in the base values/ folder. Then you can create more values-XX/ folders with their own strings.xml with all of the strings (or just a fraction of them). Android will take the default string if it doesn't find the localised version of the string.
If you are not localising to other languages, make sure that their values folder are not defined. For example, if you are not localising to Spanish, make sure that you don't have the values-es/ folder in your res/ folder.
EDIT: Same topic solved: Lint: How to ignore "<key> is not translated in <language>" errors?

Parse an xml file depending on the current language

Is there a way to parse an xml file depending on the current language? For example, I have two countries.xml files. One in the values folder, and another one in the values-de folder. I want to parse the file specific to the current language.
The android environment parses these files for you, and you can get to the data through various accessors, like if you have a set of strings in your strings.xml, you use
getText(R.strings.my_string);
which will give you the string from the strings.xml for that locale (or the default one if none match).
Check the developer's guide on resource localization for more info.

Categories

Resources