Domanda

In Android strings.xml file I have a string resource with two parameters like this:

<string name="menu_greeting_loggged_in">Hello %1$s %2$s</string>

The problem is that I have a Android lint warning saying:

Placeholder name is missing.

Explain issue shows nothing.

How to fix this warning and what does it mean? How can I add the placeholder name required?

È stato utile?

Soluzione

I accidentally stumbled upon what I think may be the solution. Just add <xliff:g> tags around the placeholder parameter, like this:

<xliff:g id="HOURS" example="2 hours">%1$s</xliff:g>

So for your example above, replace the string definition with e.g.:

<string name="menu_greeting_loggged_in">Hello
  <xliff:g id="first_name" example="Jane">%1$s</xliff:g>
  <xliff:g id="last_name" example="Doe">%2$s</xliff:g>
</string>

The use of <xliff:g> placeholder tags is explained in the Android Localization Checklist (look under the section "Mark message parts that should not be translated").

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top