Is it Possible to Localize Layout Files in Android Studio? - android

I'm designing an Android app that is to support 10 different languages/localities using Android Studio. The problem is that if I perfect the layout file for English it won't look right for other languages. For instance, some of the text might be truncated/cut off in another language because it is too long for the TextView, even if it is fine in English.
Is it possible to have language-based differences in font sizes in the layout (xml) file?

You should be able to create a layout-es folder to override the layout for the Spanish language etc. I have used it myself for drawables so I can't see why it wouldn't work for layouts too.

#darnmason's solution is correct -- locale-aware layout files do work, and to make it work, just duplicate the resource file in a layout folder with -xx, where xx is the language code. See the "639‑1" heading in this table for the language code.
So, for \res\layout\MainScreen.xml in French, the new file becomes \res\layout-fr\MainScreen.xml.
Despite Android Studio complaining that string resources should be localized into a (separate) resource file, it sometimes makes sense to use a duplicated locale-specific layout file; one such example is in the case referred to by the OP.
In general, try to do localization of text in a strings resource file. Sometimes, however, the translated text in one language would make the UI ugly in another language (compare length of "Nom d'utilisateur" with "用戶名", and the field sizes that result). In such cases, duplicate the layout file, as described above, as more than just the text (dimensions, perhaps fonts) is being localized.
The downside of using an additional layout file per language is that each time something changes (e.g. adding a button), multiple layout files need to be updated with all changes, rather than just adding the control to one layout file, and adding all translations to a separate strings resources file.

Related

what happen if do not put text files in string.xml in android?

i did not put some text in string.xml and there is a yellow alert symbol in side of Textview field. i want to know does it have problem and what happen, if do not put texts in string.xml in android?
Well, setting your text directly on your layout file can be a source of future problems and its not recommended.
Consider this scenario: You use the same string "Foo" in many layout files and then you decided to change to "Bar". If you have hardcoded that, you will need to make changes in all layout files and there might be a chance to leave some inconsistent text. But if you place it in the strings.xml file, you will have only to change in one place.
Also, if you want to add translations to your app, the Android system can handle it automatically for you if you use the strings.xml.
You might want to take a look here and here.
Nothing will happen.
string.xml used to:
localization
res/values-fr/strings.xml
res/values-ja/strings.xml
ease of editing and to save memory when reusing.
I Recommend you to put text files in string.xml
Whilst it will not cause a problem in the short term, it is not good practice and will cause you issues in the future if you decide to support multiple languages.

Landscape folder for localized layout

Due to language differences I need to have a separate landscape layout for German. How ever I created a new folder in eclipse to hold the layout but now I`m getting an error.
Is the name of the folder correct
Heres a link to a screenshot capture
https://docs.google.com/file/d/0B9OVrUvUh2stdmhkQzNFNkcxS28/edit
To support different your app in different language, you can have two options to achieve these.
A. Most Preferred way
You just need to add res/values-__/string.xml different string.xml.
To support German language you just need to add res/values-de/strings.xml which contain your string values in german which Android can display to user at runtime on the basis of their locale.
B. Increases app size as new layout created as per language.
You need to change the folder name to layout-de-land as per developer.android.com
Your link does not work but according to http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources the name should be layout-de-land
if you use multiple qualifiers for a resource directory, you must add them to the directory name in the order they are listed in the table.

compatible my layout with 29 different language

I am working on a android app which uses 29 different languages. I have created the layout according to english language in my resources folder but when the laguage changes the text views n text size changes and overlaps. Is there any way to keep the layouts constant for all laguages so that alignment of textviews and texts remain same?
yes very easy. you create for each language a values folder like values-de or values-en
in each folder you can create strings.xml
<string name="no_items">there are no items</string>
this is for the english one. create it for each language.
If you read the developer documents (here: http://developer.android.com/guide/topics/resources/localization.html#strategies), there is a good description of your problem and some ways to go about solving it. See the section "Design a flexible layout"
You can:
a) Provide different layouts per language with different layout files per language (although this can add a large amount of overhead for you to maintain your app)
or
b) Make a more flexible layout, so when long strings are passed in due to the language, everything adjusts by itself. Then you don't need to worry about which language the user is running in (or can create a lot less layouts specific to the language if some still don't look right).
you can extend TextView to adjust text size automatically to fit in.. an example of custom TextView is given in this answer https://stackoverflow.com/a/3378422/886001

android layout according to language selected

I would like to know if there is any good idea how to switch layouts according to application language selected - e.g. switch between left-to-right layout and right-to-left layout. Have different images or written text and ofcourse the position.
I thought doing it using a private member in the application that indicates the current language selected. According to this parameter I can choose the related XML and text etc.
Actualy I might create some LayoutFactory class, although I don't really think it is required.
But will have to create the realted layout XMLs.
Is there any option to put subdirectories under he layout?
Or should I name the files like en_.xml and he_.xml etc?
For values and drawable you can add folders like values-fr for French or values-ja for Japanese. The -fr indicates that if your phone is set to French localization the app will use any folder that has the -fr added to its name. I'm guessing this goes for the layout folder aswell.
You can read about Localization here .

Hebrew - english layouts selction in android application

What is the best way to provide the ability to switch between hebrew/english layouts in Android applications?
Is it commonly done - or usually just providing hebrew or english applications.
I know there is abikty to use localiztions - but is there Hebrew support for this?
Also my application should be for iPhone as well and I want to keep it the same.
How should do it in the code? Where to place the layouts?
Yoav
For orientation (right-to-left) you need: android.text.Layout.Direction
A hebrew TrueTypefont can then be called from a resource in your app by including TextView.
Instead of pushing 2 layout files you could use a class for hebrew and another for english...
or you could push the text to string values file for highest cleanliness
If it is a block of text that could be called from resource txt file (practical for prayers)
It all depends on how much text you have.

Categories

Resources