What is the purpose of the id attribute in Android <xliff: g> tags in string resources?

The Android application developer localization checklist recommends using placeholder tags for text that should not be translated. I understand this part.

He also recommends "always add an id attribute that explains what the placeholder is for." The part I don't understand. When I look at examples from an Android open source project, I see many cases where such identifiers are used, for example:

<string name="photo_view_count"><xliff:g id="current_pos">%d</xliff:g> of <xliff:g id="count">%d</xliff:g></string> 

      

(from / frameworks / opt / photoviewer / res / values ​​/ strings.xml)

The identifiers defined on this line ("current_pos" and "count") are not referenced anywhere in the underlying Java code, however, what is the purpose? Is this just a help for translators to explain what the placeholder might be?

I could see the purpose in defining each of the placeholders with an ID if those IDs were actually specified in the code, as that would serve the purpose of allowing the translator to switch the order of the placeholders. But that doesn't happen. And the identifiers in question, even in uppercase in translated versions ("CURRENT_POS" and "COUNT"), are a function of the translation tool used in this case.

+3


source to share





All Articles