weblate/docs/formats/android.rst
Gersona 725bd96349
feat(docs): Automatically generate format features docmentation (#18106)
* initial implementation suggestion

* basic supported features snippets generation

* Add API identifiers, read-only strings and common extensions to features table

* generate doc features snippet files

* autogenerated snippets cleanup

* changelog update

* delete one file to test auto-update

* replace SUPPORTS_FUZZY with file format additional_states flag

* docs: Documentation snippets update

* fix include statetement typo

* fix incorrect monolingual attributes

* minor styling change

* docs: Documentation snippets update

* exclude snippets from being treated as standalone documents

* Set YAMLFormat as both mono/bilingual

* docs: Documentation snippets update

* fix duplicate format IDs

* only use backwards quotes for literals

---------

Co-authored-by: gersona <6675010+gersona@users.noreply.github.com>
Co-authored-by: Michal Čihař <michal@weblate.org>
2026-04-01 15:41:20 +00:00

85 lines
3.1 KiB
ReStructuredText

.. _aresource:
Android string resources
------------------------
.. index::
pair: Android; file format
pair: string resources; file format
Android specific file format for translating applications.
.. hint::
A very similar formats are :doc:`/formats/compose-multiplatform-resources`
and :doc:`/formats/moko-resources`.
Android string resources are monolingual, the :ref:`component-template` is
stored in a different location from the other files -- :file:`res/values/strings.xml`.
Weblate does following escaping of strings:
* If a strings is valid XML, it is inserted as XML to translation.
* ``?`` and ``@`` are escaped with a ``\\`` at the beginning of the string to avoid interpreting them as style or resource references.
* In case string contains multiple spaces, it is quoted with double quotes (``"``).
* Newlines are escaped as ``\\n``, but the actual newline is kept for readability as well.
.. note::
Android `string-array` structures are not currently supported. To work around this,
you can break your string arrays apart:
.. code-block:: xml
<string-array name="several_strings">
<item>First string</item>
<item>Second string</item>
</string-array>
become:
.. code-block:: xml
<string-array name="several_strings">
<item>@string/several_strings_0</item>
<item>@string/several_strings_1</item>
</string-array>
<string name="several_strings_0">First string</string>
<string name="several_strings_1">Second string</string>
The `string-array` that points to the `string` elements should be stored in a different
file, and not be made available for translation.
This script may help pre-process your existing strings.xml files and translations: https://gist.github.com/paour/11291062
.. hint::
To avoid translating some strings, these can be marked as non-translatable. This can be especially useful for string references:
.. code-block:: xml
<string name="foobar" translatable="false">@string/foo</string>
.. seealso::
* `Android string resources documentation <https://developer.android.com/guide/topics/resources/string-resource>`_
* :doc:`/formats/compose-multiplatform-resources`
* :doc:`/formats/moko-resources`
* :doc:`tt:formats/android`
.. include:: /snippets/format-features/aresource-features.rst
Weblate configuration
+++++++++++++++++++++
+-------------------------------------------------------------------+
| Typical Weblate :ref:`component` |
+================================+==================================+
| File mask | ``res/values-*/strings.xml`` |
+--------------------------------+----------------------------------+
| Monolingual base language file | ``res/values/strings.xml`` |
+--------------------------------+----------------------------------+
| Template for new translations | `Empty` |
+--------------------------------+----------------------------------+
| File format | `Android String Resource` |
+--------------------------------+----------------------------------+