是的strings.xml参数可能吗? [英] Are parameters in strings.xml possible?
问题描述
在我的Android应用我'要实现与国际化我的琴弦。因此,目前我有一个问题,语法和句子的方式建立在不同的语言。
In my Android app I'am going to implement my strings with internationalization. So currently I got a problem with the grammar and the way sentences build in different languages.
例如:
5分钟前 - 英
VOR 5 Minuten - 德国
"vor 5 Minuten" - German
我可以做这样的事情在strings.xml中以下?
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.Format()
办法。
Yes, just format your strings in the standard String.format()
way.
请参阅该方法<一href="http://developer.android.com/reference/android/content/Context.html#getString%28int,%20java.lang.Object...%29"><$c$c>Context.getString(int,对象...) 和的Android 或的Java 格式化
文档。
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>
这篇关于是的strings.xml参数可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!