支持文件类型 (Strings)

.XML - Android 字符串

文本由 Phrase Language AI 从英语机器翻译而得。

文件扩展名 

.xml

API 扩展 

xml

导入 

导出 

复数形式支持 

描述支持 

格式选项 

这些选项可以在上传和/或下载文件时指定。根据上传/下载方法(API、CLI、Repo sync 等),它们可以在查询参数 上传下载phrase.yml 配置文件中指定。

convert_placeholder

escape_linebreaks

unescape_linebreaks

enclose_in_cdata

indent_size

indent_style

unescape_tags

include_tools_ignore

include_tools_locale_definition

escape_android_chars

unescape_android_chars

Android XML 是一种 Android 特有的 XML 变体,可用于将已翻译的内容加载到 Android 应用程序中。其根元素是 <resources>,下方嵌套有多个 <string> 元素,用于存储等待翻译的 Strings。您可以使用 Android Studio 生成这些资源文件,并使用 Phrase 管理翻译。

Android Studio 使用属性 可译的 来指示内容是否需要翻译。在 Phrase 中,此属性会被忽略。无需将这些 Strings 推送到 Phrase。如果某个字符串不应被翻译,请将其定义在包含所有非译元素 Strings 的单独资源文件中(例如 donottranslate.xml)。

格式选项

标识符 

convert_placeholder

类型 

布尔值

上传 

下载 

默认 

false

说明 

占位符将被转换为匹配格式的特定要求。示例:$s' =&gt; '$@

标识符 

escape_linebreaks

类型 

布尔值

上传 

下载 

默认 

false

说明 

所有换行符将被转义为 \\n

标识符 

unescape_linebreaks

类型 

布尔值

上传 

下载 

默认 

false

说明 

所有 \\n 都将被导入为真正的换行符

标识符 

enclose_in_cdata

类型 

布尔值

上传 

下载 

默认 

false

说明 

将包含 HTML 标记的翻译内容括在 CDATA 中

标识符 

indent_size

类型 

integer

上传 

下载 

默认 

4

说明 

指定缩进字符的数量

标识符 

indent_style

类型 

字符串

上传 

下载 

默认 

空间

说明 

指定缩进字符。允许的值为 空间选项卡

标识符 

unescape_tags

类型 

布尔值

上传 

下载 

默认 

false

说明 

所有 &lt; 字符将被取消转义为 <,所有 &gt; 字符将被取消转义为 > 以用于标记。

标识符 

include_tools_locale_definition

类型 

布尔值

上传 

下载 

默认 

false

说明 

在生成的 XML 中包含 工具:区域 属性

标识符 

include_tools_ignore

类型 

布尔值

上传 

下载 

默认 

false

说明 

在生成的 XML 中包含 工具:略过 属性

禁用时(默认),工具:略过 属性将从导出的文件中省略。这有助于保持资源文件整洁,并避免包含特定于开发的 lint 抑制属性。

标识符 

preserve_cdata

类型 

布尔值

上传 

下载 

默认 

false

说明 

如果翻译内容已包含 CDATA 标签,此开关可防止内容被额外转义。

标识符 

escape_android_chars

类型 

布尔值

上传 

下载 

默认 

false

说明 

使用反斜杠前缀转义 @?选项卡 Android 特殊字符

标识符 

unescape_android_chars

类型 

布尔值

上传 

下载 

默认 

false

说明 

取消转义 \\@\\?\\t\\uXXXX(代码为 XXXX 的 Unicode 字符)。

代码示例

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <string name="boolean_key">--- true
</string>
    <string name="empty_string_translation"/>
    <!-- 这是此键的精彩描述! -->
    <string name=\"key_with_description\">Check it out!This key has a description!(At least in some formats)</string>
    <string name=\"key_with_line-break\">This translations contains
a line-break.</string>
    <string name=\"nested.deeply.key\">嘿,此键嵌套得更深。</string>
    <string name=\"nested.key\">This key is nested inside a namespace.</string>
    <string name="null_translation"/>
    <plurals name="pluralized_key">
        <item quantity=\"one\">仅找到一个复数形式。</item>
        <item quantity=\"other\">嘿,你有 %s 个复数形式!</item>        
    </plurals>
    <string-array name="sample_collection">
        <item>第一个条目</item>
        <item>第二个条目</item>
        <item>第三个条目</item>
    </string-array>
    <string name="simple_key">只是一个带有消息的键。</string>
    <string name="unverified_key">此翻译尚未经过未验证,正在等待验证。(在某些格式中,我们也会导出此状态)</string>
</resources>

Android XML 文件的复数形式

对于复数值,请分配一个特殊的 <plurals> 标签,如下所示:

<plurals name="messages">
        <item quantity="one">收到一条消息。</item>
        <item quantity="other">收到 %s 条消息。</item>        
</plurals>
这篇文章有帮助吗?

Sorry about that! In what way was it not helpful?

The article didn’t address my problem.
I couldn’t understand the article.
The feature doesn’t do what I need.
Other reason.

Note that feedback is provided anonymously so we aren't able to reply to questions.
If you'd like to ask a question, submit a request to our Support team.
Thank you for your feedback.