1mike12
1mike12

Reputation: 3441

Having trouble getting xliff tags working in my strings.xml

I've read the official docs and seen what others have done on SO, but I can't get my strings to work after adding xliff tags. I have the xliff namespace imported

strings.xml

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="string_name">
        Your goal is maintaining your levels between 
        <xliff:g id="test1" example="130">%1$d</xliff:g>
        <xliff:g id="test2" example="mg/DL">%2$s</xliff:g>and 
        <xliff:g id="test3" example="110">%3$d</xliff:g>
        <xliff:g id="test4" example="mg/DL">%4$s</xliff:g>
</string>

code

String raw = getString(R.string.string_name);
return String.format(raw, customGoal.getGoalValueLow(), units, customGoal.getGoalValueHigh(), units);

Upvotes: 0

Views: 156

Answers (1)

Jenszcz
Jenszcz

Reputation: 547

I do not have Android Studio at hand to reproduce your issue, but here is a wild guess what could be wrong:

The XLIFF standard does not list the attribute example for <g> elements (see here). Try if removing them makes a difference. XLIFF does allow you to add your own attributes, but if you do that the attribute values should start with 'x-' (see here).

If you want to inform the translator what the placeholders stand for you can also use the ctype attribute, or choose more descriptive IDs:

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="string_name">
        Your goal is maintaining your levels between 
        <xliff:g id="maxValue" ctype="x-number">%1$d</xliff:g>
        <xliff:g id="measurementUnit" ctype="x-unit">%2$s</xliff:g>and 
        <xliff:g id="minValue" ctype="x-number">%3$d</xliff:g>
        <xliff:g id="measurementUnit" ctype="x-unit">%2$s</xliff:g>
</string>

Upvotes: 1

Related Questions