I know there is support in Android for 18n an application, but can I give parameters to such a string? In Rails, I can do something like this:
en:
hello: "Hello %{name}! You've got %{count} messages."
t("hello", name: "Klaus", count: 5)
Is there something similar in Android or do I have to do it myself?
To elaborate on Heiko's answer, and to show your specific example, if you want to have more than one string you need to number them:
<string name="hello">Hello %1$s! You've got %2$d messages.</string>
This way you can switch the order of the strings in each translation. Using it would be:
String hello = getString(R.strings.hello, "Klaus", 5);
You can do the same
In strings.xml you can put
<string name="xyz">Do you really want to report [%s] as spammer?</string>
and then in your code you put
String foo = getString(R.strings.xyz,"Joe Doe");
See Context.getString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With