Manumarigle
Manumarigle

Reputation: 27

Translate String AndroidStudio

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

Upvotes: 1

Views: 2548

Answers (1)

Skizo-ozᴉʞS ツ
Skizo-ozᴉʞS ツ

Reputation: 20626

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]));

Upvotes: 2

Related Questions