1

I want to translate this code:

List.add("  Temperature: " + matrix[1][2] + " ºC");

I want to translate the word "Temperature:" but I don`t know how to put it on Strings.xml

EDIT: I want to know how to add Temperature on Strings.xml and then make a translation

1 Answers1

2

To put it on Strings.xml you have to add this :

<string name="Temperature">Temperature: </string>

Then if you want to use it from Strings.xml you do this as follows :

List.add(getString(R.string.Temperature) + matrice[1][2] + " ºC");

To translate it you'll have to create different values directories for the language with the suffix of the language code.

See the documents

EDIT(parameters String)

Adding the parameters as @trooper said, would be like this :

Your Strings.xml should be

<string name="Temperature">Temperature: %1$s ºC</string>

Then in your java code you have to use this :

List.add(String.format(getString(R.string.Temperature), matrice[1][2]));
Community
  • 1
  • 1
Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148
  • Thanks so much, I did it but it works without the "" List.add(getString(R.string.Temperature) + matrice[1][2] + " ºC"); – Manumarigle Nov 16 '15 at 20:04
  • Woops, my bad misstyped :P, glad to hear that... mark this answer as a correct if it helped to you :D – Skizo-ozᴉʞS ツ Nov 16 '15 at 20:04
  • 2
    @Manumarigle also consider parameterizing your string: http://stackoverflow.com/questions/2397613/are-parameters-in-strings-xml-possible – trooper Nov 16 '15 at 20:07