Android translates strings with variables
good morning,
I have an Android application with XML files in German and English. Now I want to set the and text view as follows:
"Hello user x, hello world y." Hello benutzer x, hello world y. "
For X and y, I want to set a variable. How to use dynamic variables to translate the texts of these two languages into Chinese?
resolvent:
Your problem seems unclear, but as far as I know, I'm suggesting a solution for you
If you want to pass a dynamic parameter to a string, you can do so through the following example
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
In this example, the format string has two parameters:% 1 $s is a string and% 2 $D is a decimal number. You can format the string using the parameters in the application, as follows:
Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
If you want to see more: http://developer.android.com/intl/pt-br/guide/topics/resources/string-resource.html#FormattingAndStyling