検査と修正¶
自動修正のカスタマイズ¶
標準の自動修正に、独自の修正も追加できます。AUTOFIX_LIST
内に記述します。
自動修正は強力ですが、翻訳を破壊することもあります; 記述するときには注意が必要です。
例えば、次の自動修正は、翻訳内のすべての文字列 foo
を bar
に置き換える:
#
# Copyright © 2012 - 2021 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
from django.utils.translation import gettext_lazy as _
from weblate.trans.autofixes.base import AutoFix
class ReplaceFooWithBar(AutoFix):
"""Replace foo with bar."""
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 クラスへの完全修飾パスを指定します。参照: 品質検査、アドオン、自動修正のカスタマイズ。
フラグを使用した動作の設定¶
Weblate の動作(主に検査)は、原文(原文の査読、参照: Additional info on source strings)、または Component configuration ( 翻訳フラグ)で詳細に設定できます。ファイル フォーマットの中には、フラグを直接フォーマットで指定できるものもあります(参照: 対応するファイル形式)。
フラグはカンマで、パラメーターはコロンで区切ります。引用符を使用して、文字列に空白または特殊文字を含めることができます。設定例:
placeholders:"special:value":"other value", regex:.*
現在、使用可能なフラグ一覧:
rst-text
テキストを reStructuredText 文書として扱う、関連項目 未翻訳の翻訳文。
md-text
テキストを Markdown 文書として扱う。
dos-eol
UNIX の代わりに DOS の改行コードを使用する(
\n
の代わりに\r\n
)。url
文字列は URL のみでなければならない。
safe-html
文字列は HTML セーフでなければならない。参照: 安全でない HTML。
read-only
文字列は読み取り専用なので Weblate で編集しないでください。参照: 編集不可の文字列。
priority:N
文字列の優先順位。優先順位の高い文字列が最初に翻訳されます。デフォルトの優先順位は 100、文字列の優先順位が高いほど、翻訳のために早く使用されます。
max-length:N
文字列の最大長を N 文字に制限する。参照: 翻訳の最大文字数。
xml-text
テキストを XML ドキュメントとして扱う、関連項目: XML 構文 および XML マークアップ。
font-family:NAME
検査結果を表示するフォントの定義。参照: フォントの管理。
font-weight:WEIGHT
検査結果を表示するフォントの太さの定義。参照: フォントの管理。
font-size:SIZE
検査結果を表示するフォント サイズの定義。参照: フォントの管理。
font-spacing:SPACING
表示確認用の文字間隔の設定。参照: フォントの管理。
placeholders:NAME:NAME2:...
翻訳にはプレースホルダー文字列が必要です。参照: プレースホルダー。
replacements:FROM:TO:FROM2:TO2...
結果のテキスト パラメータを検査するときに実行する置換(例 翻訳の文字の最大サイズ または 翻訳の最大文字数)。この一般的な使用例は、テキストが長い名前でも収まるように配置可能な場所を拡張すること、 例:
replacements:%s:"John Doe"
。variants:SOURCE
この文字列を、原文と一致する文字列の異なる表記としてマークします。参照: 文字列の異なる表記。
regex:REGEX
翻訳ファイルを照合する正規表現。参照: 正規表現。
禁止
Indicates forbidden translation in a glossary, see 翻訳禁止.
python-format
、c-format
、php-format
、python-brace-format
、javascript-format
、c-sharp-format
、java-format
、java-messageformat
、lua-format
、auto-java-messageformat
、qt-format
、qt-plural-format
、ruby-format
、vue-format
すべての文字列を書式文字列のように扱う、関連項目: 書式指定文字列, 書式指定文字列、書式指定文字列、書式指定文字列、書式指定文字列、書式指定文字列、書式指定文字列、書式指定文字列、書式指定文字列、書式指定文字列、書式指定文字列、書式指定文字列、書式指定文字列、未翻訳の翻訳文。
strict-same
「未翻訳の翻訳」には、標準搭載されたブラックリストの単語を使用しないようにする。参考 未翻訳の翻訳文。
check-glossary
「用語集に従っていない」の品質検査を有効にする。
ignore-bbcode
「BBcode マークアップ」の品質検査を無効にする。
ignore-duplicate
「重複単語の連続」の品質検査を無効にする。
ignore-check-glossary
「用語集に従っていない」の品質検査を無効にする。
ignore-double-space
「連続したスペース」の品質検査を無効にする。
ignore-angularjs-format
「AngularJS 補間文字列」の品質検査を無効にする。
ignore-c-format
「C 形式」の品質検査を無効にする。
ignore-c-sharp-format
「C# 形式」の品質検査を無効にする。
ignore-es-format
「ECMAScript テンプレート リテラル」の品質検査を無効にする。
ignore-i18next-interpolation
「i18next 補間」の品質検査を無効にする。
ignore-java-format
「Java 形式」の品質検査を無効にする。
ignore-java-messageformat
「Java MessageFormat」の品質検査を無効にする。
ignore-javascript-format
「JavaScript 形式」の品質検査を無効にする。
ignore-lua-format
「Lua 形式」の品質検査を無効にする。
ignore-percent-placeholders
「パーセントのプレースホルダー」の品質検査を無効にする。
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-vue-format
「Vue I18n 書式」の品質検査を無効にする。
ignore-translated
「翻訳済み」の品質検査を無効にする。
ignore-inconsistent
「一貫性に問題」の品質検査を無効にする。
ignore-kashida
「Kashida 文字の使用」の品質検査を無効にする。
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-question
「疑問符の不一致」の品質検査を無効にする。
ignore-end-semicolon
「セミコロンの不一致」の品質検査を無効にする。
ignore-newline-count
「改行の不一致」の品質検査を無効にする。
ignore-plurals
「複数形の不備」の品質検査を無効にする。
ignore-placeholders
「プレースホルダー」の品質検査を無効にする。
ignore-punctuation-spacing
「句読点の間隔」の品質検査を無効にする。
ignore-regex
「正規表現」の品質検査を無効にする。
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-long-untranslated
「長期にわたり未翻訳」の品質検査を無効にする。
ignore-multiple-failures
「複数の検査で不合格」の品質検査を無効にする。
ignore-unnamed-format
「複数の名前のない変数」の品質検査を無効にする。
ignore-optional-plural
「複数形の不使用」の品質検査を無効にする。
注釈
基本的に、規則は名前に ignore-*
という識別子がすべての検査に対して付いているため、独自の検査にも使用できます。
このフラグは、Component configuration 、原文ごとの設定、および翻訳ファイル自体(例: GNU gettext)の両方で認識されます。
検査の強制¶
バージョン 3.11 で追加.
Component configuration で 検査の強制 を設定することで、無効にできない検査項目を設定できます。設定した検査項目は、ユーザーインターフェイスで除外にできず、検査で不合格となった文字列は 要編集 (参照: Translation states)と設定されます。
フォントの管理¶
バージョン 3.7 で追加.
ヒント
Weblate にアップロードしたフォントは、 翻訳の文字の最大サイズ 検査のためだけに使用します。Weblate のユーザーインターフェイスには影響しません。
表示したテキストのサイズの計算に使用する 翻訳の文字の最大サイズ 検査は、フォントを Weblate に読み込み、翻訳フラグ(参照: フラグを使用した動作の設定)を使用して選択することが必要です。
翻訳プロジェクトの 管理 メニュー下の フォント にあるフォント管理ツールは、フォントのアップロードと管理のためのインターフェイスを提供します。TrueTypeとOpenTypeフォントがアップロードできるので、フォントグループを設定して検査で使用してください。
フォントグループを使用すると、言語ごとに異なるフォントを定義できます。通常、ラテン言語以外で必要です:

フォント グループは名前で識別し、名前には空白文字や特殊文字を含めることはできません。そこで、簡単に選択して使用する方法:

フォント ファミリーとスタイルは、アップロード後に自動的に認識:

Weblate に登録できる複数のフォントの設定:

文字列の長さを確認するためにフォントを使用するには、適切なフラグ(参照 フラグを使用した動作の設定)を渡します。設定が必要な項目:
max-size:500
最大幅の設定。
font-family:ubuntu
使用するフォント グループの識別子の設定。
font-size:22
フォント サイズの設定。
独自検査の記述¶
幅広い品質検査を標準搭載していますが(参照: 品質検査)、検査したい項目をすべて網羅しているとは限りません。実行する検査の内容は、CHECK_LIST
で設定できます。また、独自の検査も追加できます。
weblate.checks.Check をサブクラス化する
複数の属性を設定する。
check
(コードで複数形を扱う場合)またはcheck_single
メソッド(これはあなたに代わって実行)を実装する。
複数の例:
独自の検査を組み込むには、CHECK_LIST
に Python クラスへの完全修飾パスを指定します。参照: 品質検査、アドオン、自動修正のカスタマイズ。
翻訳テキストに「foo」が含まれていないかの確認¶
これは非常に単純な検査であり、翻訳に文字列「foo」を含まないかの検査をするだけです。
#
# Copyright © 2012 - 2021 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""Simple quality check example."""
from django.utils.translation import gettext_lazy as _
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
name = _("Foo check")
# Description for failing check
description = _("Your translation is foo")
# Real check code
def check_single(self, source, target, unit):
return "foo" in target
チェコ語の翻訳文の複数形が異なっているかの確認¶
言語情報を使用して、チェコ語の 2 つの複数形が同じでないことを検査します。
#
# Copyright © 2012 - 2021 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""Quality check example for Czech plurals."""
from django.utils.translation import gettext_lazy as _
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
name = _("Foo check")
# Description for failing check
description = _("Your translation is foo")
# Real check code
def check_target_unit(self, sources, targets, unit):
if self.is_language(unit, ("cs",)):
return targets[1] == targets[2]
return False
def check_single(self, source, target, unit):
"""We don't check target strings here."""
return False