Translate external xml

150 views Asked by At

I have a XML file inside the raw folder in portuguese that gives some quotes to a cardview. What I want to do now is have some translations to this XML file. I need to parse that XML so how can I create the translation for this and how I call it on code, so that my app knows what file should be used according to the OS idiom?

EDIT

Short version of the xml file:

<tips>
    <tip>
        <tiptitle>Sabia que:</tiptitle>
        <tiptext>A Torre Eiffel fica 15 cm maior que seu tamanho original no verão.</tiptext>
        <tiptype>Tyoe</tiptype>
        <tipYear>2016</tipYear>
        <tipMonth>03</tipMonth>
        <tipDay>16</tipDay>
        <tipHour>11</tipHour>
        <tipMinute>24</tipMinute>
    </tip>
</tips>
1

There are 1 answers

1
Spirrow On

To support multiple languages, you can have a look at this. What you have to do basically is to store all your strings in different string resources. Each string resource is placed inside a values folder with a specif name (you must use the proper name for each language). For example:

 res/
   values/
       strings.xml
   values-es/
       strings.xml
   values-fr/
       strings.xml

At runtime, the Android system uses the appropriate set of string resources based on the locale currently set for the user's device, so you don't have to worry about checking the language.

So you will have to write down your text from your xml file into a string resource (one for each language).