How to use one language resource file for multiple languages? [duplicate] - android

This question already has answers here:
Android localization values-** folder names
(3 answers)
Closed 3 years ago.
I created an Android app that is provided in several countries (no surprise so far ;-)). But I want to use the resource file, that contains German strings in Germany, Swiss and Austria. Do have to copy the file two times or is there better way how to handle this?

You put language specific files(string, images, styles, etc) to language specific values folder. For instance for German, create a folder named values-de, can also use country specific codes too. values-pt for Portuguese, and values-pt-rBR for Brazilian.
You can find the codes for languages or use Translation Editor of Android Studio which creates folders for you. Another thing with Translation Editor it helps you to filter for text and has some other extra cool features.

You can use the translation editor (open your "string.xml" and click on "Open editor" at the top right corner). It will manage the other files for you.

Related

It is about reading XML file in android studio

If I have XML file and it was wrote in Arabic, but my application supports 2 languages (Arabic & English), is there any way to change the sentences in XML file to English when the user changes the language of the app?
I think Official Documentation is written in pretty well methodology -
So here I'm providing you that links -
Let me entitle it as -
Thing to be taken care of while you are developing an App with muti-language support
Localization Checklist
Writing style
XLIFF - XML Localisation Interchange File Format
Ps, First link is the parent of all, Go there - Its pretty interestring stuffs out there!
Everything you need is explained in the official Android Documentation.
You should create strings.xml for Arabic and English languages
You can create different XML files for different languages. The app/android will choose in condition to the system language which XML too choose.
You just have to create a new folder called values-ar in res/ where you put your Arabic strings.xml

Which is Better use or don't use string.xml? [duplicate]

This question already has answers here:
Why to use strings.xml?
(3 answers)
Closed 7 years ago.
Commonly android programmer use string.xml because it recommended by ADT android like android studio or eclipse (at least that what I thought) , but lately I think using string.xml is waste of resources ... we can directly named the text on layout widget or app name directly instead of declare it on string.xml and call it on layout later ...
Can any one explain that my thought is right or wrong ?
Thank you
It's possible to directly name your text. But resources are really helpful when your text have to change depending of your users' configurations, such as language. That's why it is recommanded to do it this way.
It is also a way to avoid having too many informations to manage in one file for the developper so he can focus on the way he wants his layout to look like. Android IDEs make string resources easy to use for you. I would recommand you keep using them.
There is a reason you use strings.xml and that is to support multiple locale just to provide one point. Also its easily extensible as compared to hardcoding your strings...
One of its use that You can use multiple languages for your app using string.xml
So in the folder values you would have strings.xml with this content:
<string name="hello">Hello</string>
In values-fr a strings.xml with this content:
<string name="hello">Bonjour</string>
It will automatically pick up your default language selected.
and other is, suppose you are using same string multiple places. so in XML, it would be easy to change by changing in only one place.
If you use string.xml you will have a global access to the all string variables used in the application .
If you hard-code the string values in the xml resources , you will have slight improvement in UI rendering

Convert android project to multi-language

I have an Android project that I developed one year ago. I didn't think in do the project multi-language and now I need support it.
There are any easy way to detect all strings and generate the XML file? Or I need modify the project string for string?
The project is developed in Eclipse.
Android provides a very simple way to localize apps: string resources.
You need to provide several strings.xml files.
Each in a directory called /res/values-xy, where xy is the language (i.e.: es, fr, en, de, it, ...).
Then just refer these strings in your project, like R.string.my_string_name (in Java) or #string/my_string_name (in xml)
For reference: http://developer.android.com/training/basics/supporting-devices/languages.html
[EDIT]
Same goes for arrays: just use /res/values-xy/arrays.xml
Note: the names strings.xml and arrays.xml are just conventional ones can be changed to anything you like better.
AFAIK You need to modify the strings in your project manually. If you have hard-coded strings in your layouts then you can use Lint to find out all the hard-coded strings. Put them then into values/strings and the translation should go to the respective folder of each language.
EDIT:
If you're running Eclipse you can use the search feature to help you track all your hard-coded String. Check this topic

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!

Using the same values folder for different (specific) languages in Android

My default app language is English so strings.xml is located under res\values.
My app should also support Hebrew, so I put a Hebrew copy of strings.xml under res\values-he.
My problem is that on some devices, Hebrew is defined as "iw" (instead of "he").
Is there a way to save me the trouble of another copy of strings.xml under res\values-iw, but to have one folder to handle he,iw and use the default values folder for all the rest?
It's a known issue and already answered here:
CyanogenMod: Translate a Project
So if you want full support on all devices, you have to include both versions.
It's just copy & paste, where's the trouble? :)

Categories

Resources