Android 字符串资源

用于翻译应用的 Android 特定文件格式。

Android 字符串资源是单语言的,单语言译文模版语言文件 存储在与其他文件不同的位置 – res/values/strings.xml

Weblate 遵循字符串转义:

  • 如果字符串是有效的 XML,将被作为 XML 插入翻译。

  • ? and @ are escaped with a \\ at the beginning of the string to avoid interpreting them as style or resource references.

  • 如果字符串包含多个空格,将用双引号 (")进行引用。

  • 新行被转义为 \\n,但出于稳定性考虑,也将保留实际新行。

备注

当前不支持 Android 的 string-array 架构。为了解决这个问题,可以将字符串数组分开:

<string-array name="several_strings">
    <item>First string</item>
    <item>Second string</item>
</string-array>

变为:

<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>

指向 string 元素的 string-array 应存储在不同文件中,并且不为翻译所用。

这个脚本可以帮助预处理现有的 strings.xml 文件和翻译:https://gist.github.com/paour/11291062

提示

为了避免翻译某些字符串,可以将它们标记为不可翻译。这对于字符串引用特别有用:

<string name="foobar" translatable="false">@string/foo</string>

Weblate 配置

典型的 Weblate 部件配置

文件掩码

res/values-*/strings.xml

单语言译文模版语言文件

res/values/strings.xml

新语种的翻译模版

文件格式

Android 字符串资源