支持的文件格式

Weblate 支持 translate-toolkit 理解的大多数翻译格式,但是每种格式都略有不同,可能会出现未经良好测试的格式问题。

注解

为您的应用程序选择文件格式时,最好在您使用的工具箱/平台中保留一些公认的格式。这样,您的翻译人员可以额外使用他们习惯使用的任何工具,并且更有可能为您的项目做出贡献。

双语和单语格式

支持 monolingual 和 bilingual 格式。双语格式在单个文件中存储两种语言 —— 源和翻译(典型示例是 GNU gettextXLIFFApple iOS strings 字符串)。另一方面,单语格式通过 ID 识别字符串,每个语言文件仅包含那些语言到任何给定语言(通常是 Android string resources)的映射。两种变体都使用某些文件格式,请参见下面的详细说明。

为了正确使用单语文件,Weblate 要求访问一个包含完整字符串列表的文件,以与其源一起翻译 —— 该文件在 Weblate 中称为 单语种译文模版语言文件,尽管命名方式可能会有所不同。

另外,可以利用 中间语言文件 扩展此工作流程,以包括开发人员提供的字符串,但不要在最终的字符串中使用。

自动检测

Weblate 可以自动检测几种常用的文件格式,但是这种检测会损害您的性能,并且会限制特定于给定文件格式的功能(例如,自动添加新翻译)。

翻译类型功能

所有受支持格式的功能:

格式

语言能力 1

复数 2

注释 3

语境 4

位置 5

标志 8

附加状态 6

GNU gettext

双语

yes

yes

yes

yes

yes 9

needs editing

单语 gettext

mono

yes

yes

yes

yes

yes 9

needs editing

XLIFF

both

yes

yes

yes

yes

yes 10

needs editing, approved

Java properties

both

no

yes

no

no

no

GWT properties

mono

yes

yes

no

no

no

Joomla translations

mono

no

yes

no

yes

no

Qt Linguist .ts

both

yes

yes

no

yes

yes 10

needs editing

Android string resources

mono

yes

yes 7

no

no

yes 10

Apple iOS strings

双语

no

yes

no

no

no

PHP 字符串

mono

no 11

yes

no

no

no

JSON files

mono

no

no

no

no

no

JSON i18next files

mono

yes

no

no

no

no

go-i18n JSON files

mono

yes

no

no

no

no

ARB File

mono

yes

yes

no

no

no

WebExtension JSON

mono

yes

yes

no

no

no

.XML resource files

mono

no

yes

no

no

yes 10

CSV 文件

mono

no

yes

yes

yes

no

needs editing

YAML files

mono

no

yes

no

no

no

Ruby YAML files

mono

yes

yes

no

no

no

DTD files

mono

no

no

no

no

no

Flat XML

mono

no

no

no

no

yes 10

Windows RC files

mono

no

yes

no

no

no

Excel Open XML

mono

no

yes

yes

yes

no

needs editing

应用商店元数据文件

mono

no

no

no

no

no

Subtitle files

mono

no

no

no

yes

no

HTML files

mono

no

no

no

no

no

OpenDocument Format

mono

no

no

no

no

no

IDML Format

mono

no

no

no

no

no

INI translations

mono

no

no

no

no

no

Inno Setup INI 翻译

mono

no

no

no

no

no

1

See 双语和单语格式

2

Plurals are necessary to properly localize strings with variable count.

3

Comments can be used to pass additional info about the string to translate.

4

Context is used to differentiate identical strings used in different scopes (for example Sun can be used as an abbreviated name of the day “Sunday” or as the name of our closest star).

5

Location of a string in source code might help proficient translators figure out how the string is used.

6

Additional states supported by the file format in addition to “Not translated” and “Translated”.

7

XML comment placed before the <string> element, parsed as a developer comment.

8

See 定制行为

9(1,2)

The gettext type comments are used as flags.

10(1,2,3,4,5)

The flags are extracted from the non-standard attribute weblate-flags for all XML based formats. Additionally max-length:N is supported through the maxwidth attribute as defined in the XLIFF standard, see Specifying translation flags.

11

The plurals are supported only for Laravel which uses in string syntax to define them, see Localization in Laravel.

GNU gettext

翻译自由软件的最广泛使用的格式。这是 Weblate 支持的第一种格式,至今仍获得最好的支持。

通过调整文件头或链接到相应的源文件,可以支持存储在文件中的上下文信息。

双语 gettext PO 文件通常如下所示:

#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "Monday"
msgstr "Pondělí"

#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "Tuesday"
msgstr "Úterý"

#: weblate/accounts/avatar.py:163
msgctxt "No known user"
msgid "None"
msgstr "Žádný"

典型的 Weblate Component configuration

文件掩码

po/*.po

单语种译文模版语言文件

Empty

新翻译的译文模版

po/messages.pot

文件格式

Gettext PO file

单语 gettext

一些项目决定使用 gettext 作为单语格式 —— 它们仅在源代码中编码 ID,然后将字符串翻译成所有语言,包括英语。支持此功能,尽管在将组件导入 Weblate 时必须明确选择此文件格式。

单语种的 gettext PO 文件通常如下所示:

#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "day-monday"
msgstr "Pondělí"

#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "day-tuesday"
msgstr "Úterý"

#: weblate/accounts/avatar.py:163
msgid "none-user"
msgstr "Žádný"

基本语言文件将是:

#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "day-monday"
msgstr "Monday"

#: weblate/media/js/bootstrap-datepicker.js:1421
msgid "day-tuesday"
msgstr "Tuesday"

#: weblate/accounts/avatar.py:163
msgid "none-user"
msgstr "None"

典型的 Weblate Component configuration

文件掩码

po/*.po

单语种译文模版语言文件

po/en.po

新翻译的译文模版

po/messages.pot

文件格式

Gettext PO 文件(单语)

XLIFF

创建基于 XML 的格式来标准化翻译文件,但最终它是该领域中 许多标准 之一。

XML Localization Interchange File Format (XLIFF) is usually used as bilingual, but Weblate supports it as monolingual as well.

参见

XML Localization Interchange File Format (XLIFF) specification

Translation states

在 3.3 版更改: Weblate ignored the state attribute prior to the 3.3 release.

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.

If the translation string has approved="yes", it will also be imported into Weblate as “Approved”, anything else will be imported as “Waiting for review” (which matches the XLIFF specification).

While saving, Weblate doesn’t add those attributes unless necessary:

  • The state attribute is only added in case string is marked as needing edit.

  • The approved attribute is only added in case string has been reviewed.

  • In other cases the attributes are not added, but they are updated in case they are present.

That means that when using the XLIFF format, it is strongly recommended to turn on the Weblate review process, in order to see and change the approved state of strings.

See 专门的审核者.

Similarly upon importing such files (in the upload form), you should choose Import as translated under Processing of strings needing edit.

Whitespace and newlines in XLIFF

Generally types or amounts of whitespace is not differentiated between in XML formats. If you want to keep it, you have to add the xml:space="preserve" flag to the string.

例如:

    <trans-unit id="10" approved="yes">
        <source xml:space="preserve">hello</source>
        <target xml:space="preserve">Hello, world!
</target>
    </trans-unit>

Specifying translation flags

You can specify additional translation flags (see 定制行为) by using the weblate-flags attribute. Weblate also understands maxwidth and font attributes from the XLIFF specification:

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

The font attribute is parsed for font family, size and weight, the above example shows all of that, though only font family is required. Any whitespace in the font family is converted to underscore, so Source Sans Pro becomes Source_Sans_Pro, please keep that in mind when naming the font group (see 管理字型).

Typical Weblate Component configuration for bilingual XLIFF

文件掩码

localizations/*.xliff

单语种译文模版语言文件

Empty

新翻译的译文模版

localizations/en-US.xliff

文件格式

XLIFF Translation File

Typical Weblate Component configuration for monolingual XLIFF

文件掩码

localizations/*.xliff

单语种译文模版语言文件

localizations/en-US.xliff

新翻译的译文模版

localizations/en-US.xliff

文件格式

XLIFF Translation File

Java properties

Native Java format for translations.

Java properties are usually used as monolingual translations.

Weblate supports ISO-8859-1, UTF-8 and UTF-16 variants of this format. All of them support storing all Unicode characters, it is just differently encoded. In the ISO-8859-1, the Unicode escape sequences are used (for example zkou\u0161ka), all others encode characters directly either in UTF-8 or UTF-16.

注解

Loading escape sequences works in UTF-8 mode as well, so please be careful choosing the correct encoding set to match your application needs.

典型的 Weblate Component configuration

文件掩码

src/app/Bundle_*.properties

单语种译文模版语言文件

src/app/Bundle.properties

新翻译的译文模版

Empty

文件格式

Java Properties (ISO-8859-1)

GWT properties

Native GWT format for translations.

GWT properties are usually used as monolingual translations.

典型的 Weblate Component configuration

文件掩码

src/app/Bundle_*.properties

单语种译文模版语言文件

src/app/Bundle.properties

新翻译的译文模版

Empty

文件格式

GWT Properties

INI translations

4.1 新版功能.

INI file format for translations.

INI translations are usually used as monolingual translations.

典型的 Weblate Component configuration

文件掩码

language/*.ini

单语种译文模版语言文件

language/en.ini

新翻译的译文模版

Empty

文件格式

INI File

Inno Setup INI 翻译

4.1 新版功能.

用于翻译的 Inno Setup INI 文件格式。

Inno Setup INI翻译通常用作单语种翻译。

注解

The only notable difference to INI translations is in supporting %n and %t placeholders for line break and tab.

典型的 Weblate Component configuration

文件掩码

language/*.islu

单语种译文模版语言文件

language/en.islu

新翻译的译文模版

Empty

文件格式

Inno Setup INI 文件

注解

Only Unicode files (.islu) are currently supported, ANSI variant (.isl) is currently not supported.

Joomla translations

2.12 新版功能.

Native Joomla format for translations.

Joomla translations are usually used as monolingual translations.

典型的 Weblate Component configuration

文件掩码

language/*/com_foobar.ini

单语种译文模版语言文件

language/en-GB/com_foobar.ini

新翻译的译文模版

Empty

文件格式

Joomla Language File

Qt Linguist .ts

Translation format used in Qt based applications.

Qt Linguist files are used as both bilingual and monolingual translations.

Typical Weblate Component configuration when using as bilingual

文件掩码

i18n/app.*.ts

单语种译文模版语言文件

Empty

新翻译的译文模版

i18n/app.de.ts

文件格式

Qt Linguist Translation File

Typical Weblate Component configuration when using as monolingual

文件掩码

i18n/app.*.ts

单语种译文模版语言文件

i18n/app.en.ts

新翻译的译文模版

i18n/app.en.ts

文件格式

Qt Linguist Translation File

Android string resources

Android specific file format for translating applications.

Android string resources are monolingual, the Monolingual base language file file is stored in a different location from the others res/values/strings.xml.

典型的 Weblate Component configuration

文件掩码

res/values-*/strings.xml

单语种译文模版语言文件

res/values/strings.xml

新翻译的译文模版

Empty

文件格式

Android String Resource

注解

Android string-array structures are not currently supported. To work around this, you can break your string arrays apart:

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

become:

<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

Apple iOS strings

Apple specific file format for translating applications, used for both iOS and iPhone/iPad application translations.

Apple iOS strings are usually used as bilingual translations.

典型的 Weblate Component configuration

文件掩码

Resources/*.lproj/Localizable.strings

单语种译文模版语言文件

Resources/en.lproj/Localizable.strings

新翻译的译文模版

Empty

文件格式

iOS Strings (UTF-8)

PHP 字符串

PHP translations are usually monolingual, so it is recommended to specify a base file with (what is most often the) English strings.

Example file:

<?php
$LANG['foo'] = 'bar';
$LANG['foo1'] = 'foo bar';
$LANG['foo2'] = 'foo bar baz';
$LANG['foo3'] = 'foo bar baz bag';

典型的 Weblate Component configuration

文件掩码

lang/*/texts.php

单语种译文模版语言文件

lang/en/texts.php

新翻译的译文模版

lang/en/texts.php

文件格式

PHP strings

Laravel PHP 字符串

在 4.1 版更改.

The Laravel PHP localization files are supported as well with plurals:

<?php
return [
    'apples' => 'There is one apple|There are many apples',
];

JSON files

2.0 新版功能.

在 2.16 版更改: Since Weblate 2.16 and with translate-toolkit at-least 2.2.4, nested structure JSON files are supported as well.

JSON format is used mostly for translating applications implemented in JavaScript.

Weblate currently supports several variants of JSON translations:

JSON translations are usually monolingual, so it is recommended to specify a base file with (what is most often the) English strings.

Example file:

{
  "Hello, world!\n": "Ahoj světe!\n",
  "Orangutan has %d banana.\n": "",
  "Try Weblate at https://demo.weblate.org/!\n": "",
  "Thank you for using Weblate.": ""
}

Nested files are supported as well (see above for requirements), such a file can look like:

{
  "weblate": {
    "hello": "Ahoj světe!\n",
    "orangutan": "",
    "try": "",
    "thanks": ""
  }
}

警告

Weblate currently handles nested JSON by flattening the keys. This leads to serializing issues when special chars such as . or [] are used in the actual keys, because Weblate thinks it is indication of nesting.

See <https://github.com/WeblateOrg/weblate/issues/2149>

典型的 Weblate Component configuration

文件掩码

langs/translation-*.json

单语种译文模版语言文件

langs/translation-en.json

新翻译的译文模版

Empty

文件格式

JSON nested structure file

JSON i18next files

在 2.17 版更改: Since Weblate 2.17 and with translate-toolkit at-least 2.2.5, i18next JSON files with plurals are supported as well.

i18next is an internationalization framework written in and for JavaScript. Weblate supports its localization files with features such as plurals.

i18next translations are monolingual, so it is recommended to specify a base file with (what is most often the) English strings.

注解

Weblate supports the i18next JSON v3 format. The v2 and v1 variants are mostly compatible, with exception of how plurals are handled.

Example file:

{
  "hello": "Hello",
  "apple": "I have an apple",
  "apple_plural": "I have {{count}} apples",
  "apple_negative": "I have no apples"
}

典型的 Weblate Component configuration

文件掩码

langs/*.json

单语种译文模版语言文件

langs/en.json

新翻译的译文模版

Empty

文件格式

i18next JSON file

go-i18n JSON files

4.1 新版功能.

go-i18n translations are monolingual, so it is recommended to specify a base file with (what is most often the) English strings.

注解

Weblate supports the go-i18n JSON v2 format, it does not support flat JSON files supported in v1.

典型的 Weblate Component configuration

文件掩码

langs/*.json

单语种译文模版语言文件

langs/en.json

新翻译的译文模版

Empty

文件格式

go-i18n JSON file

ARB File

4.1 新版功能.

ARB translations are monolingual, so it is recommended to specify a base file with (what is most often the) English strings.

典型的 Weblate Component configuration

文件掩码

lib/l10n/intl_*.arb

单语种译文模版语言文件

lib/l10n/intl_en.arb

新翻译的译文模版

Empty

文件格式

ARB file

WebExtension JSON

2.16 新版功能: This is supported since Weblate 2.16 and with translate-toolkit at-least 2.2.4.

File format used when translating extensions for Mozilla Firefox or Google Chromium.

注解

While this format is called JSON, its specification allows to include comments, which are not part of JSON specification. Weblate currently does not support file with comments.

Example file:

{
  "hello": {
    "message": "Ahoj světe!\n",
    "description": "Description",
    "placeholders": {
      "url": {
        "content": "$1",
        "example": "https://developer.mozilla.org"
      }
    }
  },
  "orangutan": {
    "message": "",
    "description": "Description"
  },
  "try": {
    "message": "",
    "description": "Description"
  },
  "thanks": {
    "message": "",
    "description": "Description"
  }
}

典型的 Weblate Component configuration

文件掩码

_locales/*/messages.json

单语种译文模版语言文件

_locales/en/messages.json

新翻译的译文模版

Empty

文件格式

WebExtension JSON file

.XML resource files

2.3 新版功能.

A .XML resource (.resx) file employs a monolingual XML file format used in Microsoft .NET applications. It is interchangeable with .resw, when using identical syntax to .resx.

典型的 Weblate Component configuration

文件掩码

Resources/Language.*.resx

单语种译文模版语言文件

Resources/Language.resx

新翻译的译文模版

Empty

文件格式

.NET 资源文件

CSV 文件

2.4 新版功能.

CSV 文件可以包含源和翻译的简单列表。Weblate 支持以下文件:

  • 带有标头定义字段(源,翻译,位置等)的文件。这是推荐的方法,因为它最不容易出错。

  • 具有两个字段的文件 —— 源和翻译(按此顺序),选择 简单 CSV 文件 作为文件格式

  • 具有 translate-toolkit 定义的字段的文件:location,source,target,ID,fuzzy,context,translator_comments,developer_comments

警告

CSV 格式当前会自动检测 CSV 文件的方言。在某些情况下,自动检测可能会失败,并且您会得到不同的结果。对于值中包含换行符的 CSV 文件尤其如此。作为一种解决方法,建议省略引号字符。

Example file:

Thank you for using Weblate.,Děkujeme za použití Weblate.

典型的 Weblate Component configuration

文件掩码

locale/*.csv

单语种译文模版语言文件

Empty

新翻译的译文模版

locale/en.csv

文件格式

CSV 文件

参见

CSV

YAML files

2.9 新版功能.

The plain YAML files with string keys and values. Weblate also extract strings from lists or dictionaries.

Example of a YAML file:

weblate:
  hello: ""
  orangutan": ""
  try": ""
  thanks": ""

典型的 Weblate Component configuration

文件掩码

translations/messages.*.yml

单语种译文模版语言文件

translations/messages.en.yml

新翻译的译文模版

Empty

文件格式

YAML file

Ruby YAML files

2.9 新版功能.

Ruby i18n YAML files with language as root node.

Example Ruby i18n YAML file:

cs:
  weblate:
    hello: ""
    orangutan: ""
    try: ""
    thanks: ""

典型的 Weblate Component configuration

文件掩码

translations/messages.*.yml

单语种译文模版语言文件

translations/messages.en.yml

新翻译的译文模版

Empty

文件格式

Ruby YAML file

参见

YAML, YAML files

DTD files

2.18 新版功能.

Example DTD file:

<!ENTITY hello "">
<!ENTITY orangutan "">
<!ENTITY try "">
<!ENTITY thanks "">

典型的 Weblate Component configuration

文件掩码

locale/*.dtd

单语种译文模版语言文件

locale/en.dtd

新翻译的译文模版

Empty

文件格式

DTD file

Flat XML files

3.9 新版功能.

Example of a flat XML file:

<?xml version='1.0' encoding='UTF-8'?>
<root>
  <str key="hello_world">Hello World!</str>
  <str key="resource_key">Translated value.</str>
</root>

典型的 Weblate Component configuration

文件掩码

locale/*.xml

单语种译文模版语言文件

locale/en.xml

新翻译的译文模版

Empty

文件格式

Flat XML file

参见

Flat XML

Windows RC files

在 4.1 版更改: Support for Windows RC files has been rewritten.

注解

Support for this format is currently in beta, feedback from testing is welcome.

Example Windows RC file:

LANGUAGE LANG_CZECH, SUBLANG_DEFAULT

STRINGTABLE
BEGIN
    IDS_MSG1                "Hello, world!\n"
    IDS_MSG2                "Orangutan has %d banana.\n"
    IDS_MSG3                "Try Weblate at http://demo.weblate.org/!\n"
    IDS_MSG4                "Thank you for using Weblate."
END

典型的 Weblate Component configuration

文件掩码

lang/*.rc

单语种译文模版语言文件

lang/en-US.rc

新翻译的译文模版

lang/en-US.rc

文件格式

RC file

应用商店元数据文件

3.5 新版功能.

Metadata used for publishing apps in various app stores can be translated. Currently the following tools are compatible:

The metadata consists of several textfiles, which Weblate will present as separate strings to translate.

典型的 Weblate Component configuration

文件掩码

fastlane/android/metadata/*

单语种译文模版语言文件

fastlane/android/metadata/en-US

新翻译的译文模版

fastlane/android/metadata/en-US

文件格式

App store metadata files

Subtitle files

3.7 新版功能.

Weblate 可以翻译多个字幕文件:

  • SubRip subtitle file (*.srt)

  • MicroDVD subtitle file (*.sub)

  • Advanced Substation Alpha subtitles file (*.ass)

  • Substation Alpha subtitle file (*.ssa)

典型的 Weblate Component configuration

文件掩码

path/*.srt

单语种译文模版语言文件

path/en.srt

新翻译的译文模版

path/en.srt

文件格式

SubRip subtitle file

参见

Subtitles

Excel Open XML

3.2 新版功能.

Excel Open XML (.xlsx) files can be imported and exported.

When uploading XLSX files for translation, be aware that only the active worksheet is considered, and there must be at least a column called source (which contains the source string) and a column called target (which contains the translation). Additionally there should be the column called context (which contains the context path of the translation string). If you use the XLSX download for exporting the translations into an Excel workbook, you already get a file with the correct file format.

HTML files

4.1 新版功能.

注解

Support for this format is currently in beta, feedback from testing is welcome.

The translatable content is extracted from the HTML files and offered for the translation.

参见

HTML

OpenDocument Format

4.1 新版功能.

注解

Support for this format is currently in beta, feedback from testing is welcome.

The translatable content is extracted from the OpenDocument files and offered for the translation.

IDML Format

4.1 新版功能.

注解

Support for this format is currently in beta, feedback from testing is welcome.

The translatable content is extracted from the Adobe InDesign Markup Language files and offered for the translation.

其它

Most formats supported by translate-toolkit which support serializing can be easily supported, but they did not (yet) receive any testing. In most cases some thin layer is needed in Weblate to hide differences in behavior of different translate-toolkit storages.

Adding new translations

在 2.18 版更改: In versions prior to 2.18 the behaviour of adding new translations was file format specific.

Weblate can automatically start new translation for all of the file formats.

Some formats expect to start with an empty file and only translated strings to be included (for example Android string resources), while others expect to have all keys present (for example GNU gettext). In some situations this really doesn’t depend on the format, but rather on the framework you use to handle the translation (for example with JSON files).

When you specify 新翻译的译文模版 in Component configuration, Weblate will use this file to start new translations. Any exiting translations will be removed from the file when doing so.

When Template for new translations is empty and the file format supports it, an empty file is created where new strings will be added once they are translated.

The Language code style allows you to customize language code used in generated filenames:

基于文件格式的默认值

Dependent on file format, for most of them POSIX is used.

POSIX 风格使用下划线作为分隔

Typically used by gettext and related tools, produces language codes like pt_BR.

POSIX 风格使用下划线作为分隔,包括国家/地区代码

POSIX style language code including the country code even when not necessary (for example ‘cs_CZ’).

GCP 风格使用连字符作为分隔

Typically used on web platforms, produces language codes like pt-BR.

GCP 风格使用连字符作为分隔,包括国家/地区代码

BCP style language code including the country code even when not necessary (for example ‘cs-CZ’).

Android 风格

Only used in Android apps, produces language codes like pt-rBR.

Java 风格

Used by Java—mostly BCP with legacy codes for Chinese.

注解

Weblate recognizes any of these when parsing translation files, the above settings only influences how new files are created.

只读字符串

3.10 新版功能.

Read-only strings from translation files will be included, but can not be edited in Weblate. This feature is natively supported by few formats (XLIFF and Android string resources), but can be emulated in others by adding a read-only flag, see 定制行为.