2

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?

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • xliff is a namespace identifier for use on the xml attributes (e.g. `xliff:d` (from your ref'd doc). The attribute meanings come from the respective namespace. Some standard attribute names exist, but I don't know of a list. –  Apr 06 '14 at 07:33
  • I know it's a namespace attribute, but what does it mean, why is it used here (or actually just written), what does its value mean...? I don't get anything about this. – android developer Apr 06 '14 at 07:58
  • It's for validation. When compiling, the attributes are matched against the namespace declaration to make sure they are valid (exist, type, etc). XML is very generic, so it's not an absolute necessity, but Android uses this to help keep structure. –  Apr 06 '14 at 08:01
  • validation of what? it's not used in the xml other than just declaring it... – android developer Apr 06 '14 at 09:21
  • It isn't in what you've pasted, but from the link you reference, I see `"+%1$s"` which does use it. The namespaces define a set of characteristics for conforming documents. –  Apr 06 '14 at 09:26
  • https://android.googlesource.com/platform/frameworks/ex/+/android-sdk-support_r11/chips/res/values-en-rGB/strings.xml is where I got that, btw. Also, it is possible that copy-and-paste coding included unnecessary xmlns declarations. :) –  Apr 06 '14 at 09:26
  • You are correct. maybe I copied it from the wrong place. but how come it's used inside the value of the string tag? isn't it supposed to be inside the tag itself and not in its content? Also, I still don't get what it all mean. what's "g" for example? – android developer Apr 06 '14 at 09:50
  • That's not a string, actually. Think of HTML. Characters can be inside of tags and tags can be nested. Xmlns are kind of like allowing multiple XML langs in one document. The g is defined for that XML Lang (idk it). –  Apr 06 '14 at 09:55
  • Also, this is not Android specific. XML namespaces are a standard. –  Apr 06 '14 at 09:57
  • ok, but what does it all mean? can you please explain the meaning of what is written here? maybe give an example of when and how to use the attribute and the namespace ? – android developer Apr 06 '14 at 10:10
  • possible duplicate of [What does this mean "xmlns:xliff"? XML](http://stackoverflow.com/questions/6158157/what-does-this-mean-xmlnsxliff-xml) – CommonsWare Apr 06 '14 at 10:29
  • Also a search for `android xliff` in a major search engine turns up various other SO questions, Google Groups discussions, etc. – CommonsWare Apr 06 '14 at 10:30
  • And maybe http://www.xml.com/pub/a/1999/01/namespaces.html will help as an intro to namespaces. –  Apr 06 '14 at 16:23
  • @CommonsWare all they say is that it's for "localization purposes" but don't show its uses. Also, they don't tell anything about "msgid". even the website is quite confusing: https://www.oasis-open.org/committees/xliff/faq.php . is there maybe a video? a lecture about this? Can I also safely ignore it ? – android developer Apr 06 '14 at 18:42
  • @CommonsWare Can you tell me for example what the "more_string" value mean? – android developer Apr 07 '14 at 08:25

1 Answers1

2

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:

Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
  • So it's used to explain the translators the meaning of the placeholders? Can it be used to the root of the XML file, so that it's like setting `translatable="false"` to each of the strings within ? And what's "msgid" ? – android developer May 08 '18 at 13:27
  • 1
    This I do not know. I came across your very old question while looking for answers. The suggested "duplicate" is not very useful at all. I then found my link and thought to leave at least some level of answer for anyone who comes along next. To me this is more helpful than the rest of the info that doesn't really relate to Android at all. Who knows, maybe this will spark someone who really knows to post an updated answer - for me, now, I'm happy I can see how it fits in, and what Google was trying to do with it. for what that's worth... – Richard Le Mesurier May 08 '18 at 15:36
  • Ok thank you. I've given you +1 for the effort, especially for answering such an old question. – android developer May 08 '18 at 17:36
  • Always frustrating to find that the top result on Google asks about exactly what I was wondering, and then it has no answers. At least this way there is _something_ for future searchers... Some of our old questions really just sit and gather dust on here. – Richard Le Mesurier May 09 '18 at 10:21