In my Android app I'am going to implement my strings with internationalization. I have a problem with the grammar and the way sentences build in different languages.
For example:
"5 minutes ago" - English
"vor 5 Minuten" - German
Can I do something like the following in strings.xml?
<string name="timeFormat">{0} minutes ago</string>
And then some magic like
getString(R.id.timeFormat, dynamicTimeValue)
This behaviour would solve the other problem with different word orders as well.
String. xml file contains all the strings which will be used frequently in Android project. String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc.
Another reason for storing strings in xml is for localization. You can store different files for each different Locale or language, and Android will grab the correct file for the phone's selected Locale or language.
Android Resources Define strings Strings are typically stored in the resource file strings. xml .
How can I write character & in the strings. xml? In android studio, you can simply press Alt+Enter and it will convert for you.
Yes, just format your strings in the standard String.format()
way.
See the method Context.getString(int, Object...)
and the Android or Java Formatter
documentation.
In your case, the string definition would be:
<string name="timeFormat">%1$d minutes ago</string>
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