Android 字串資源

用於翻譯應用的Android特定文件格式。

提示

A very similar formats are Compose 多平臺資源 and Mobile Kotlin 資源.

Android string resources are monolingual, the 單語的基底語言檔 is stored in a different location from the other files -- 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.

備註

目前不支援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

提示

To avoid translating some strings, these can be marked as non-translatable. This can be especially useful for string references:

<string name="foobar" translatable="false">@string/foo</string>
支持的功能

檔案擴充

.xml

Linguality

單語言

Supports plural

Yes

支援描述

Yes

支援解釋

No

Supports context

No

Supports location

No

Supports flags

Yes

API 識別碼

aresource

Supports read-only strings

Yes

Weblate 配置

典型的 Weblate 組件配置

檔案遮罩

res/values-*/strings.xml

單語的基底語言檔

res/values/strings.xml

新翻譯的範本

檔案格式

Android字串資源