How to do translation in java code?

0

In the Android application you have to 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();
    
asked by anonymous 03.11.2016 / 14:56

1 answer

5

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

Then you should create a new values directory for 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'd pull R.string.charging for example

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

    
03.11.2016 / 15:00