檢查和修復¶
自訂自動修正¶
還可以應用除了自動修正以外自己的自動修正,並將它們包括到 AUTOFIX_LIST。
自動修復很強大,但可能導致損壞;寫指令碼的時候要小心。
例如,後面的自動修復會將每次出現的字串 foo 在翻譯中替換為 bar :
from weblate.trans.autofixes.base import AutoFix
class ReplaceFooWithBar(AutoFix):
"""Replace foo with bar."""
# Might be localized using gettext_lazy
name = "Foobar"
def fix_single_target(self, target, source, unit):
if "foo" in target:
return target.replace("foo", "bar"), True
return target, False
為了安裝客製的檢查,在 AUTOFIX_LIST 中為 Python 類提供完全合規的路徑,請參閱 自訂的品質檢查、附加元件與自動修復。
使用標誌自訂行為¶
You can fine-tune Weblate's behavior by using flags. The flags provide visual feedback to the translators and help them to improve their translation. The flags are merged from following sources:
來源字串額外旗標:
Per-string flags extracted from the file format, see 在地化檔案格式.
Translation flags (currently only
read-onlyflag for bilingual source string or when monolingual template editing is turned off).File-format specific flags.
The flags are comma-separated; if they have parameters, they are separated with colon. You can use quotes to include whitespaces or special characters in the string. For example:
placeholders:"special:value":"other value", regex:.*
單引號或是雙引號是可接受的,特殊符號就會被使用反斜線 \ 挑脫處理:
placeholders:"quoted \"string\"":'single \'quoted\''
placeholders:r"^#*"
To verify that translators do not change the heading of a Markdown document.
A failing check will be triggered if the string ### Index is translated as # Indice.
placeholders:r"\]\([^h].*?\)"
To ensure that internal links are not being translated (i.e. [test](../checks) does not become [test](../chequeos).
The flags defined on a higher level can be discarded using the
discard:NAME syntax. For example, if a component is configured to
safe-html, you can add discard:safe-html to the string flags to skip it
for this particular string.
這裡是現在能接受的標記的清單:
read-only字串應該唯讀,並且不能在 Weblate 中編輯。請參閱 唯讀字串。
terminologyUsed in 詞彙表. Copies the string into all glossary languages so it can be used consistently in all translations. Also useful in combination with
read-only, for example in product names.priority:N字串的優先順序。高優先順序的字串首先出現被翻譯。預設的優先順序是 100,字串的優先順序越高,就會越早安排翻譯。
max-length:N將字串的最大長度限制為 N 個字元,請參閱 翻譯最大長度。
xml-textfont-family:NAME定義 font-family 來提供檢查,請參閱 管理字型。
font-weight:WEIGHT定義 font-weight 來提供檢查,請參閱 管理字型。
font-size:SIZE定義 font-size 來提供檢查,請參閱 管理字型。
font-spacing:SPACING定義渲染檢查的字母間隔,請參閱 管理字型。
icu-flags:FLAGSDefine flags for customizing the behavior of the ICU MessageFormat quality check.
icu-tag-prefix:PREFIXSet a required prefix for XML tags for the ICU MessageFormat quality check.
placeholders:NAME:NAME2:...翻譯中需要的佔位字串,請參閱 佔位符號。
replacements:FROM:TO:FROM2:TO2...當檢查結果文字引數時執行替換(例如在 翻譯的最大長度 或 翻譯最大長度 中)。這一典型應用的情況拓展了非譯元素,確保匹配那些即使使用了長值的文字,例如
replacements:%s:"John Doe"。variants:SOURCE將此字串標記為具有匹配來源的字串的變體。見 字串變數。
regex:REGEX正規表達式用來比對翻譯,參閱:正規表達式 。
discard:NAMEDiscards flag defined on a higher level.
forbidden表示術語表中的禁止翻譯,請參閱 禁止的翻譯。
strict-sameMake the 未變更的翻譯 avoid using the built-in words exceptions.
strict-formatMake format checks enforce using format even for plural forms with a single value, see 格式化字串.
case-insensitiveAdjust checks behavior to be case-insensitive. Currently affects only 佔位符號 quality check.
bbcode-textTreat a text as an Bulletin Board Code (BBCode) document, affects 未變更的翻譯. Enables the BBCode 標記 quality check.
check-glossary啟用 與詞彙表不同 品質檢查。
fluent-parts啟用 Fluent 部分 品質檢查。
fluent-references啟用 Fluent 引用 品質檢查。
fluent-target-inner-html啟用 Fluent 翻譯 inner HTML 品質檢查。
fluent-target-syntax啟用 Fluent 翻譯語法 品質檢查。
angularjs-format啟用 AngularJS 插值字串 品質檢查。
automattic-components-format啟用 Automattic 組件格式設定 品質檢查。
c-format啟用 C 格式 品質檢查。
c-sharp-format啟用 C# 格式 品質檢查。
csharp-format啟用 C# 格式 品質檢查。
es-format啟用 ECMAScript 範本字面值 品質檢查。
i18next-interpolation啟用 i18next 插值 品質檢查。
icu-message-format啟用 ICU MessageFormat 和 ICU MessageFormat 語法 品質檢查。
java-printf-format啟用 Java 格式 品質檢查。
java-format啟用 Java MessageFormat 品質檢查。
auto-java-messageformatTreat a text as conditional Java MessageFormat, enabling Java MessageFormat only when the source contains Java MessageFormat placeholders. Enables the Java MessageFormat quality check.
javascript-format啟用 JavaScript 格式 品質檢查。
laravel-format啟用 Laravel 格式 品質檢查。
lua-format啟用 Lua 格式 品質檢查。
object-pascal-format啟用 Object Pascal 格式 品質檢查。
objc-format啟用 Objective-C 格式 品質檢查。
percent-placeholders啟用 百分比佔位符號 品質檢查。
perl-brace-format啟用 Perl 大括號格式 品質檢查。
perl-format啟用 Perl 格式 品質檢查。
php-format啟用 PHP 格式 品質檢查。
python-brace-format啟用 Python 大括號格式 品質檢查。
python-format啟用 Python 格式 品質檢查。
qt-format啟用 Qt 格式 品質檢查。
qt-plural-format啟用 Qt 複數格式 品質檢查。
ruby-format啟用 Ruby 格式 品質檢查。
scheme-format啟用 Scheme 格式 品質檢查。
vue-format啟用 Vue I18n 格式 品質檢查。
rst-textTreat a text as an reStructuredText document, affects 未變更的翻譯. Enables the reStructuredText 不一致 and reStructuredText 語法錯誤 quality checks.
md-textTreat a text as a Markdown document, and provide Markdown syntax highlighting on the translation text area. Enables the Markdown 連結, Markdown 參照 and Markdown 語法 quality checks.
max-length啟用 翻譯最大長度 品質檢查。
max-size啟用 翻譯的最大長度 品質檢查。
placeholders啟用 佔位符號 品質檢查。
regex啟用 正規表達式 品質檢查。
safe-html啟用 不安全的 HTML 品質檢查。
auto-safe-htmlTreat a text as conditional HTML, enabling 不安全的 HTML only for plain text or source strings that contain standard HTML markup or valid custom elements. This is useful for extended Markdown variants such as MDX, where angle-bracket syntax may not be HTML. Enables the 不安全的 HTML quality check.
urlThe string should consist of only a URL. Enables the URL quality check.
fluent-source-inner-html啟用 Fluent 來源內部 HTML 品質檢查。
fluent-source-syntax啟用 Fluent 來源語法 品質檢查。
ignore-all-checks忽略所有品質檢查。
ignore-bbcode略過 BBCode 標記 品質檢查。
ignore-xml-chars-around-tags略過 XML 標籤周圍的字元 品質檢查。
ignore-duplicate略過 連續重複單字 品質檢查。
ignore-check-glossary略過 與詞彙表不同 品質檢查。
ignore-double-space略過 兩個空白 品質檢查。
ignore-fluent-parts略過 Fluent 部分 品質檢查。
ignore-fluent-references略過 Fluent 引用 品質檢查。
ignore-fluent-target-inner-html略過 Fluent 翻譯 inner HTML 品質檢查。
ignore-fluent-target-syntax略過 Fluent 翻譯語法 品質檢查。
ignore-angularjs-format略過 AngularJS 插值字串 品質檢查。
ignore-automattic-components-format略過 Automattic 組件格式設定 品質檢查。
ignore-c-format略過 C 格式 品質檢查。
ignore-c-sharp-format略過 C# 格式 品質檢查。
ignore-es-format略過 ECMAScript 範本字面值 品質檢查。
ignore-i18next-interpolation略過 i18next 插值 品質檢查。
ignore-icu-message-format略過 ICU MessageFormat 品質檢查。
ignore-java-printf-format略過 Java 格式 品質檢查。
ignore-java-format略過 Java MessageFormat 品質檢查。
ignore-javascript-format略過 JavaScript 格式 品質檢查。
ignore-laravel-format略過 Laravel 格式 品質檢查。
ignore-lua-format略過 Lua 格式 品質檢查。
ignore-object-pascal-format略過 Object Pascal 格式 品質檢查。
ignore-objc-format略過 Objective-C 格式 品質檢查。
ignore-percent-placeholders略過 百分比佔位符號 品質檢查。
ignore-perl-brace-format略過 Perl 大括號格式 品質檢查。
ignore-perl-format略過 Perl 格式 品質檢查。
ignore-php-format略過 PHP 格式 品質檢查。
ignore-python-brace-format略過 Python 大括號格式 品質檢查。
ignore-python-format略過 Python 格式 品質檢查。
ignore-qt-format略過 Qt 格式 品質檢查。
ignore-qt-plural-format略過 Qt 複數格式 品質檢查。
ignore-ruby-format略過 Ruby 格式 品質檢查。
ignore-scheme-format略過 Scheme 格式 品質檢查。
ignore-vue-format略過 Vue I18n 格式 品質檢查。
ignore-translated略過 已經翻譯過 品質檢查。
ignore-inconsistent略過 不一致 品質檢查。
ignore-rst-references略過 reStructuredText 不一致 品質檢查。
ignore-kashida略過 使用 Kashida letter 品質檢查。
ignore-md-link略過 Markdown 連結 品質檢查。
ignore-md-reflink略過 Markdown 參照 品質檢查。
ignore-md-syntax略過 Markdown 語法 品質檢查。
ignore-max-length略過 翻譯最大長度 品質檢查。
ignore-max-size略過 翻譯的最大長度 品質檢查。
ignore-escaped-newline略過 不相配的 \n 品質檢查。
ignore-end-colon略過 冒號不相符 品質檢查。
ignore-end-ellipsis略過 刪節號不相符 品質檢查。
ignore-end-exclamation略過 驚嘆號不相符 品質檢查。
ignore-end-stop略過 句號不相符 品質檢查。
ignore-end-interrobang略過 不相配的驚歎問號 品質檢查。
ignore-end-question略過 問號不相符 品質檢查。
ignore-end-semicolon略過 分號不相符 品質檢查。
ignore-newline-count略過 斷列符不相配 品質檢查。
ignore-plurals略過 缺少複數 品質檢查。
ignore-multiple-capital略過 多個大寫字母 品質檢查。
ignore-kabyle-characters略過 非標準的柏柏爾語字元 品質檢查。
ignore-placeholders略過 佔位符號 品質檢查。
ignore-prohibited-initial-character略過 禁止的初始字元 品質檢查。
ignore-punctuation-spacing略過 標點符號間距 品質檢查。
ignore-regex略過 正規表達式 品質檢查。
ignore-rst-syntax略過 reStructuredText 語法錯誤 品質檢查。
ignore-reused略過 重複使用的翻譯 品質檢查。
ignore-same-plurals略過 相同複數 品質檢查。
ignore-begin-newline略過 開頭換行 品質檢查。
ignore-begin-space略過 開頭空格 品質檢查。
ignore-end-newline略過 後隨換行 品質檢查。
ignore-end-space略過 後隨空格 品質檢查。
ignore-same略過 未變更的翻譯 品質檢查。
ignore-safe-html略過 不安全的 HTML 品質檢查。
ignore-url略過 URL 品質檢查。
ignore-xml-tags略過 XML 標記 品質檢查。
ignore-xml-invalid略過 XML 語法 品質檢查。
ignore-zero-width-space略過 零寬度空格 品質檢查。
ignore-ellipsis略過 刪節號 品質檢查。
ignore-fluent-source-inner-html略過 Fluent 來源內部 HTML 品質檢查。
ignore-fluent-source-syntax略過 Fluent 來源語法 品質檢查。
ignore-icu-message-format略過 ICU MessageFormat 語法 品質檢查。
ignore-long-untranslated略過 長期未翻譯 品質檢查。
ignore-multiple-failures略過 多項未通過檢查 品質檢查。
ignore-unnamed-format略過 多個未命名變數 品質檢查。
ignore-optional-plural略過 未複數化 品質檢查。
備註
通常規則是,任何檢查都使用識別文字來命名 ignore-*,所以能夠將規則應用在自訂檢查中。
每個來源字串的設定,在 組件配置 設定中,並且在翻譯檔案自身中(例如在 GNU gettex 中),能夠理解這些標記。
基於位置的旗標¶
Some flags are added to strings by default, based on their locations. This means that certain checks will be automatically enabled depending on where the string is used.
rst-text: This flag is automatically added to strings in reStructuredText files, if location extension is.rst.md-text: This flag is automatically added to strings in Markdown and MDX files, if location extension is.md,.markdown, or.mdx.
強制檢查¶
The enforced checks cannot be dismissed and mark string as Needs editing (see 翻譯狀態). This prevents translators from hiding such checks.
提示
Turning on check enforcing doesn't enable it automatically. Some checks have to be turned on by adding the corresponding flag to the string or component flags.
This is best used with checks that can cause serious issues when used like checks for 格式化字串. Using for style checks like 未變更的翻譯 is not recommended because dismissal is sometimes a reasonable approach in these.
The 翻譯品質過濾器 can then be used to exclude strings needing editing from being committed to the version control.
管理字型¶
提示
上傳到Weblate的字型純粹用於 翻譯的最大長度”檢查,它們在WebLate使用者介面中沒有效果。
用於計算呈現文本需要的尺寸的 翻譯的最大長度 檢查需要字型被載入進 Weblate 並被一個翻譯標識選中 (見 使用標誌自訂行為)。
Weblate font management tool in Fonts under the Operations menu of your translation project provides interface to upload and manage fonts. TrueType or OpenType fonts can be uploaded, set up font-groups and use those in the check.
字型群組允許為不同語言確定不同字型,這是非拉丁語言中典型需要的:
字型群組透過名稱識別,名稱不能包含空白字元或特殊字元,這使它能夠容易地用在檢查定義中:
Font-family and style are automatically recognized after uploading them:
可以將幾種字型載入到 Weblate 中:
為了使用字型來檢查字串長度,將適當的標記傳遞給它 (請參閱 使用標誌自訂行為)。可能會需要後面這些:
max-size:500/max-size:300:5Defines maximal width in pixels and, optionally, the maximum number of lines (word wrapping is applied).
font-family:ubuntu確定字型群組,透過指定其識別文字來使用。
font-size:22定義字型大小(pixels)。
撰寫自訂檢查¶
Weblate 內建了很大範圍的品質檢查,(請參閱 品質檢查 ),儘管可能沒有覆寫想要檢查的所有內容。可以使用 CHECK_LIST 來調整執行檢查的清單,也可以新增客製的檢查。
weblate.checks.Check 子類別
設定一些特性。
應用
check(如果想要處理程式碼中的複數的話)或check_single方法(它將為您完成)。
一些範例:
為了安裝客製的檢查,在 CHECK_LIST 中為 Python 類提供完全合格的路徑,請參閱 自訂的品質檢查、附加元件與自動修復。
檢查翻譯文字不含有 “ foo ”¶
這是非常簡單的檢查,只檢查翻譯中是否遺失了字串“ foo ”。
"""Simple quality check example."""
from django.utils.translation import gettext_lazy
from weblate.checks.base import TargetCheck
class FooCheck(TargetCheck):
# Used as identifier for check, should be unique
# Has to be shorter than 50 characters
check_id = "foo"
# Short name used to display failing check
# Might be localized using gettext_lazy
name = "Foo check"
# Description for failing check
description = gettext_lazy("Your translation is foo")
# Real check code
def check_single(self, source, target, unit):
return "foo" in target
檢查捷克語翻譯文字的複數差異¶
使用語言資訊來驗證捷克語中的兩種複數形式並不相同。
"""Quality check example for Czech plurals."""
from django.utils.translation import gettext_lazy
from weblate.checks.base import TargetCheck
class PluralCzechCheck(TargetCheck):
# Used as identifier for check, should be unique
# Has to be shorter than 50 characters
check_id = "foo"
# Short name used to display failing check
# Might be localized using gettext_lazy
name = "Foo check"
# Description for failing check
description = gettext_lazy("Your translation is foo")
# Real check code
def check_target_unit(self, sources, targets, unit):
if unit.translation.language.is_base({"cs"}):
return targets[1] == targets[2]
return False
def check_single(self, source, target, unit) -> bool:
"""We don't check target strings here."""
return False