views:

498

answers:

2

Hello Folks

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.

For example:

"5 minutes ago" - english

"vor 5 Minuten" - german

So my first question is, can i do smth like this 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.

Thx in advance for your time.

+4  A: 

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>
Christopher
stupid question of me...life can be so easy.
dhesse
A: 

Note that for this particular application there's a standard library function, android.text.format.DateUtils.getRelativeTimeSpanString().

Divide