How to translate java code?

Asked

Viewed 589 times

1

In the Android application you can translate the xml string. How do I do this in the java code?

In this code, for example:

Toast.makeText(getApplicationContext(), "Carregando o aplicativo", Toast.LENGTH_SHORT).show();

1 answer

5


You have the file res/values/strings.xml, correct?

Then you must create a new directory values referring to the language you want to use in the APP, for example:

  • res/values-fr/strings.xml
  • res/values-ja/strings.xml

And in Toast, instead of putting the text right there, you would pull from R.string. for example

It will work according to the default language of the user’s device, if the user’s device is set to French, Java will automatically fetch the texts in res/values-fr/strings.xml

  • 1

    Very well explained. It worked, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.