String Formats
Android XML
Ditto allows Android developers to fetch the latest text as pre-formatted XML resources (.xml
) in accordance with Android strings and Android localization guidance.
If you’re fetching this format via the API, it will have an HTTP Content-Type
header of text/xml
.
Example:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="welcome_text" ditto_api_id="welcome-text">Welcome to the app!</string>
<string name="logout" ditto_api_id="logout">Logout</string>
</resources>
Instructions:
To fetch this via the API, provide the query parameter ?format=android
.
To fetch this via the CLI, specify format: android
in the config.yml
file.
Format details:
- Text items in Ditto are mapped to
<string>
tags. Each tag is given aname
property with a value that corresponds to a given text item’s Developer ID; to comply with Android requirements,-
characters in the ID are replaced with_
. An additionalditto_api_id
field is also included with the unmodified Developer ID. - Variables in Ditto are mapped to
<xliff:g>
tags. They’re givenid
andexample
properties with values that correspond to a given variable’s name and example values, respectively. - A text item with plurals will have a
<plurals>
tag generated for it, along with an<item>
for each plural form that is configured in Ditto (note:<item id="other">
will always be generated). Plural items also support variables via<xliff:g>
tags. - If this format is exported for a specific variant, two comments containing variant metadata will also be included:
<?xml version="1.0" encoding="utf-8"?>
<!-- Variant Name: French -->
<!-- Variant Description: Copy localized for native French speakers -->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="welcome_text" ditto_api_id="welcome-text">Welcome to the app!</string>
<string name="logout" ditto_api_id="logout">Logout</string>
</resources>