Following up on what we did last time here.
Our application started to have different audiences with different languages, so we want to localize our app.
The good thing is that we have a few texts to change and we already using a reference to the
/* file located in:: src/main/res/layout */ android:text="@string/my_button_text"
which have this value
/* file located in:: src/main/res/values/strings.xml */ <resources> ... <string name="my_button_text">Click!</string> </resources>
Update all the text inside your app to use
We also have the text we use for the toast inside our
Toast.makeText(getApplicationContext(), "Clicked!!", Toast.LENGTH_SHORT).show();
So first thing first let's use the
strings.xml instead of having the text inside the main file by doing the following update the
strings.xml to have a text for the toast
/* file located in:: src/main/res/values/strings.xml */ <resources> ... <string name="toast_text">Clicked!!</string> </resources>
and update the
MainActivity.java file to use the new text
Now we updated all the texts around our App to use the
It's time to translate our
Right-click on the
strings.xml, select the Open Translations Editor
After that, you would need to click on the globe icon, to choose the language you want to support, I'll choose Arabic
The last thing is to fill in the values for each text
And the android studio will generate a new strings.xml file for the language you just selected.
Here is the result
Congrats!! now you can support any language you want and have more audience around the globe
See you in the next part