Skip to content

Instantly share code, notes, and snippets.

@dnedrow
Last active February 19, 2022 15:50
Show Gist options
  • Select an option

  • Save dnedrow/e90b29f7c2507f640e2e24a16dc04703 to your computer and use it in GitHub Desktop.

Select an option

Save dnedrow/e90b29f7c2507f640e2e24a16dc04703 to your computer and use it in GitHub Desktop.
Example of using xliff:g to mark parts of strings that shouldn't be translated
<!--
ref: https://github.com/icerockdev/moko-resources
Often strings 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 &lt;xliff:g> placeholder tag.
Here is an example tag that ensures the text "%1$s" isn't changed during translation
(otherwise it could break the message):
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.
Here are some more examples of placeholder tags:
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="countdown">
  <xliff:g example="5 days" id="time">%1$s</xliff:g> until holiday
</string>
<!-- Example placeholder for a special unicode symbol -->
<string name="star_rating">Check out our 5
   
<xliff:g id="star">\u2605</xliff:g>
</string>
<!-- Example placeholder for a for a URL -->
<string name="app_homeurl">
    Visit us at
<xliff:g
    id="application_homepage">http://my/app/home.html
</xliff:g>
</string>
<!-- Example placeholder for a name -->
<string name="prod_name">
    Learn more at <xliff:g id="prod_gamegroup">Game Group</xliff:g>
</string>
<!-- Example placeholder for a literal -->
<string name="promo_message">
    Please use the "<xliff:g id="promotion_code">ABCDEFG</xliff:g>" to get a discount.
</string>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment