XLIFF 1.1 與 1.2¶
備註
XLIFF 2.0 是個不同的格式並且不向下相容於 XLIFF 1.2。
建立基於 XML 的格式來標準化翻譯文件,但最終它是該領域中 許多標準 之一。
XML Localization Interchange File Format (XLIFF) 通常用作雙語言格式,但 Weblate 也支援其作為單語言格式。
Weblate supports XLIFF in several variants:
- XLIFF 1.2 翻譯檔案
Simple XLIFF file where content of the elements is stored as plain text (all XML elements being escaped).
- XLIFF 1.2 with placeables support
Standard XLIFF supporting placeables and other XML elements.
- XLIFF 1.2 with gettext extensions
XLIFF enriched by XLIFF 1.2 Representation Guide for Gettext PO to support plurals.
- XLIFF 1.2 with Apple extensions
XLIFF enriched by Apple to support plurals.
也參考
翻譯狀態¶
The state attribute in the file is partially processed and mapped to the
"Needs edit" state in Weblate (the following states are used to flag the string as
needing edit if there is a target present: new, needs-translation,
needs-adaptation, needs-l10n). Should the state attribute be
missing, a string is considered translated as soon as a <target> element
exists.
如果翻譯字串具有 approved="yes" ,那麼它還將被匯入Weblate 作為"Approved"(同意的),任何其它內容被匯入作為"Waiting for review" (等待複核,這與XLIFF 規範匹配)。
當儲存時,Weblate 如無必要不會新增其它屬性:
state屬性只在字串標記為需要編輯的情況下新增。approved屬性只在字串已經被複查的情況下新增。在其它情況下不新增屬性,但在它們出現的情況下更新。
這表示當使用 XLIFF 格式時,強烈推薦打開 Weblate 審查過程,從而能看到並變更字串的檢閱狀態。
相似地在匯入這樣的文件時(在上傳表格中),應該選擇 Processing of strings needing edit 之下的 Import as translated。
也參考
XLIFF 中的空白字元和新行符¶
在 XML 格式中不區分通常類型或量的空白字元。如果想要保留,必須將 xml:space="preserve" 標記新增到字串中。
例如:
<trans-unit id="10" approved="yes">
<source xml:space="preserve">hello</source>
<target xml:space="preserve">Hello, world!
</target>
</trans-unit>
指定翻譯旗標¶
還可以通過使用 weblate-flags 屬性指定附加的翻譯標記(請參閱 使用旗標自訂行為)。 Weblate 還理解來自 XLIFF 規範的 maxwidth 和 font 屬性:
<trans-unit id="10" maxwidth="100" size-unit="pixel" font="ubuntu;22;bold">
<source>Hello %s</source>
</trans-unit>
<trans-unit id="20" maxwidth="100" size-unit="char" weblate-flags="c-format">
<source>Hello %s</source>
</trans-unit>
解析 font 屬性用於字型集、尺寸和粗細,上面的範例顯示了全部,儘管只需要字元集。字元集中的任何空白字元被轉換為下劃線,所以 Source Sans Pro 變成 Source_Sans_Pro,當命名字元集時請記住這些請參閱 管理字型)。
字串金鑰¶
Weblate 通過 resname 屬性在它出線的情況下識別 XLIFF 文件中的單元,並退回到 id (如果出現的話與 file 標籤一起)。
resname 屬性被認為是人類友好的單元識別碼,對 Weblate 比 id 更適於顯示。在整個 XLIFF 文件中 resname 具有一致性。這是 Weblate 需要的,並且不被 XLIFF 標準覆寫——它不在這個屬性上放入任何獨特性限制。
範例檔案¶
範例 XLIFF 檔案:
<?xml version='1.0' encoding='UTF-8'?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.1">
<file>
<body>
<trans-unit weblate-flags="c-format, max-length:100">
<source xml:space="preserve">Hello, world!
</source>
</trans-unit>
<trans-unit>
<source xml:space="preserve">Orangutan has %d banana.
</source>
</trans-unit>
<trans-unit>
<source xml:space="preserve">Try Weblate at <https://demo.weblate.org/>!
</source>
</trans-unit>
<trans-unit>
<source>Thank you for using Weblate.</source>
</trans-unit>
</body>
</file>
</xliff>
Weblate 配置¶
用於雙語言 XLIFF 的典型 Weblate 組件配置 |
|
|---|---|
檔案遮罩 |
|
單語言基底語言檔案 |
空白 |
新翻譯的範本 |
|
檔案格式 |
XLIFF 翻譯文件 |
用於單語言 XLIFF 的典型 Weblate 組件配置 |
|
|---|---|
檔案遮罩 |
|
單語言基底語言檔案 |
|
新翻譯的範本 |
|
檔案格式 |
XLIFF 翻譯文件 |