Android: default language of strings.xml
Asked Answered
S

3

12

I'm going to translate my application strings.xml file. Which is default language of strings.xml file? because now i need to support italian (the language with i've write strings.xml for now) and english. Should i use string.xml for english and create

res/values-it/

folder for italian, and translate "default" strings.xml in english?

Salley answered 25/3, 2014 at 10:36 Comment(2)
You can just copy that strings.xml to the values-it, and translate one in english for values :>Crenation
the default language is English. The string file is /res/values/strings.xmlOkubo
S
20

strings.xml is the default and will be used if there is no country specific file like res/values-it/strings.xml or res/values-fr/strings.xml. Read more about Localizing with Resources.

I would personally use strings.xml with english translations as a fallback as you already suggested.

Shanney answered 25/3, 2014 at 10:40 Comment(2)
I don't see any examples of using like "strings-it.xml" in the documentation mentioned above.Aconite
@DoctororDrive you are right, sorry got that wrong in my mind. I'll fix my answer.Shanney
P
5

Take a look here; as stated:

Create Locale Directories and String Files

To add support for more languages, create additional values directories inside res/ that include a hyphen and the ISO country code at the end of the directory name. For example, values-es/ is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time.

Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files. For example:

MyProject/ res/ values/ strings.xml values-es/ strings.xml values-it/ strings.xml

Add the string values for each locale into the appropriate file.

At runtime, the Android system uses the appropriate set of string resources based on the locale currently set for the user's device.

For example, the following are some different string resource files for different languages.

English (default locale), /values/strings.xml:

<?xml version="1.0" encoding="utf-8"?>
  <resources>
    <string name="title">My Application</string>
    <string name="hello_world">Hello World!</string>
</resources>

Italian, /values-it/strings.xml:

<?xml version="1.0" encoding="utf-8"?>
  <resources>
    <string name="title">la mia domanda </string>
    <string name="hello_world">ciao mondo!</string>
  </resources>

Note:You can use the locale qualifier (or any configuration qualifer) on any resource type, such as if you want to provide localized versions of your bitmap drawable. For more information, see Localization.

Pericarditis answered 25/3, 2014 at 10:47 Comment(5)
I need to localize only strings for now. But why i need to create two folders for language (values-es and values-it)? what i want is that if Locale language is italian, show italian strings, else (rest of the world) use english. Maybe i could only translate in english strings.xml, and create only values-it folderSalley
For each language you should have ALL the string resources defined, even though you might not be using some of them, they will be used by the layout and they will take the value from the default language defind. This is where those strings take their values from.Pericarditis
But if at runtime no values folder that match locale is found, system will use the default strings.xml file?Salley
Yes by default it will refers to string.xmlPericarditis
so i just need one folder for it language, then default is english. ThanksSalley
S
4

If you want to have only one strings.xml file and you would like to localize to Italian, all you need to do is add the following line to your strings.xml file.

<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="it">

locale="it" -> Italian, locale="fr" -> French, etc.

Surefire answered 23/6, 2021 at 7:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.