Search code examples
androidlocale

Variable slots in texts coming from XML


I'd like to include localization into my app. However, I happen to see that I need to include some vars inside a text, and sometimes they are not sorted. The easiest example would be with currency texts. In English, you could find something like your current income is $40.00, keep it up!, but in Spanish, it could be like tus ingresos ascienden a 40.00$, ¡sigue así!. In that case, currency ($) and value (40.00) are external vars which depend on every user.

The problem is that I don't know how to add slots to a text coming from a locale xml. It would be cool to have something like:

<string name="income">your current income is {currency}{money}, keep it up!</string>

However, I don't know if that is possible out of the box. Do you have any clue? Thanks in advance


Solution

  • You want to use Format String resources