What's “msgid” and “xliff” in strings.xml file?

爱⌒轻易说出口 提交于 2019-12-10 23:51:58

问题


Background

Sometimes I see some weird attributes on the "strings.xml" file made by Google's samples, for example, on the chips example (code available here), I can find this strings file of "res/values-en-rGB" (for English-Britain) :

<resources xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <string name="more_string" msgid="8495478259330621990">"+<xliff:g id="COUNT">%1$s</xliff:g>"</string>
    <string name="copy_email" msgid="7869435992461603532">"Copy email address"</string>
    <string name="copy_number" msgid="530057841276106843">"Copy phone number"</string>
    <string name="done" msgid="2356320650733788862">"Return"</string>
</resources>

I think both are used only for localized strings, as I never saw them inside "res/values" folder.

The question

What do those attributes mean?

What does the value of "xliff" mean?

When should you use them and what should you put there?

Are they even needed?

Is there any documentation about those things?


回答1:


On Android Developers Localise your app page, search for xliff in the section named "Mark message parts that should not be translated".

The explanation is as follows:

Often strings contain contain text that should not be translated into other languages. Common examples might be a piece of code, a placeholder for a value, a special symbol, or a name. As you prepare your strings for translation, look for and mark text that should remain as-is, without translation, so that the translator doesn't change it.

To mark text that should not be translated, use an placeholder tag.

The suggestion is that text within the <xliff:g></xliff:g> tags should not be translated. These tags can also provide metadata about the non-translated text.

When you declare a placeholder tag, always add an id attribute that explains what the placeholder is for. If your apps later replace the placeholder value, be sure to provide an example attribute to clarify the expected use.


For more information on the actual xliff tool, rather than how it relates to Android strings, check out the related question:

  • What does this mean "xmlns:xliff"? XML.


来源:https://stackoverflow.com/questions/22891172/whats-msgid-and-xliff-in-strings-xml-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!