アドオン

バージョン 2.19 で追加.

アドオンを使用すると、翻訳ワークフローをカスタマイズできます。アドオンは翻訳コンポーネント画面にインストールして、バックグラウンドで動作します。アドオン管理は、管理者用の各翻訳コンポーネントの 管理アドオン メニューから実行します。

../_images/addons.png

内蔵アドオン

自動翻訳

バージョン 3.9 で追加.

自動翻訳または他のコンポーネントを使用して文字列を自動的に翻訳します。

このアドオンは、コンポーネントに新しい文字列が表示されると自動的に実行します。

JavaScript 現地語化 CDN

バージョン 4.2 で追加.

JavaScript または HTML の現地語化用に CDN を追加します。

静的な HTML ページを現地語化したり、JavaScript コードで翻訳を読み込むために使用できます。

アドオンをインストールすると、コンポーネント専用の URL が生成されます。この URL を HTML ドキュメントに含めると、コンポーネントを現地語化できます。詳細は Translating HTML and JavaScript using Weblate CDN を参照してください。

空白文字列の削除

バージョン 4.4 で追加.

翻訳ファイルから翻訳されていない文字列を削除します。

Use this if you do not want empty strings to appear in translation files (for example when your localization library displays them as empty strings instead of falling back to the source string).

翻訳ファイルのクリーンアップ

単一言語の基本ファイルに合わせてすべての翻訳ファイルを更新します。ほとんどのファイル形式で、基本ファイルに存在しない、無効な翻訳キーを削除します。

言語の一貫性

1 つのプロジェクト内のすべてのコンポーネントに、追加されたすべての言語の翻訳を適用します。

コンポーネントを追加していない言語では、空の翻訳を作成します。

存在しない言語は、24 時間ごとに 1 回、および新しい言語を Weblate に追加したときに確認します。

他のほとんどのアドオンとは異なり、このアドオンはプロジェクト全体に影響します。

ヒント

新しく追加した文字列を 自動翻訳 で自動翻訳します。

コンポーネントの検出

バージョン管理システムのファイル変更に基づいて、プロジェクトコンポーネントを自動的に追加または削除します。

これは VCS を更新するたびに起動し、その他は、import_project 管理コマンドと同じです。この方法で、1 つの VCS 内で複数の変換コンポーネントを追跡できます。

今後消える可能性が最も低いメイン コンポーネントを 1 つ作成します。他のコンポーネントは、Weblate の内部 URL を VCS 設定として使用し、その中のすべてのコンポーネントを検索するように設定します。

コンポーネントの照合は正規表現を使用するが、この場合、性能は設定の複雑さとトレードオフになります。一般的な使用例については、アドオンのヘルプ セクションを参照してください。

保存 をクリックすると、一致するコンポーネントのプレビューを表示し、設定が実際のニーズに合っているか確認できます:

../_images/addon-discovery.png

一括編集

バージョン 3.11 で追加.

文字列のフラグ、ラベル、状態を一括編集します。

新しい文字列のラベル付けを自動化すると便利です (まず NOT has:label という検索クエリから開始し、すべての文字列に適切なラベルが付けられるまで必要なラベルを追加します)。Weblate メタデータに対するその他の自動操作も実行できます。

例:

新しい文字列に自動的にラベルを追加

検索クエリ

NOT has:label

ラベルの追加

最近の

Marking all アプリ ストア メタデータ ファイル changelog entries read-only

検索クエリ

language:en AND key:changelogs/

翻訳フラグの追加

read-only

参考

一括編集

未翻訳の翻訳文に "要編集" フラグを付ける

バージョン 3.1 で追加.

VCS からインポートされた新しい翻訳可能な文字列が原文と一致するたびに、Weblate は "要編集" フラグを付けます。これは、文字列が翻訳されていない場合であっても、すべての文字列を含むファイル形式には特に便利です。

新しい原文に "要編集" フラグを付ける

新しい原文を VCS からインポートすると、Weblate は毎回 "要編集" フラグを付けます。このため、開発者が作成した原文を簡単にフィルタしたり、編集したりできます。

新しい翻訳に "要編集" フラグを付ける

新しい翻訳可能な文章を VCS からインポートすると、Weblate は毎回 "要編集" フラグを付けます。これにより、開発者が作成した翻訳文を簡単にフィルタしたり、編集したりできます。

統計データの生成

翻訳状況の詳細情報ファイルを生成します。

Django テンプレートは、ファイル名とコンテンツの両方で使用できます。マークアップの詳細については、マークアップ を参照してください。

たとえば、各翻訳の概要ファイルを生成する:

生成ファイルの名前

locale/{{ language_code }}.json

内容
{
   "language": "{{ language_code }}",
   "strings": "{{ stats.all }}",
   "translated": "{{ stats.translated }}",
   "last_changed": "{{ stats.last_changed }}",
   "last_author": "{{ stats.last_author }}",
}

コメント内の貢献者情報

PO ファイルヘッダのコメントを更新し、貢献者名と貢献年を追加します。

PO ファイル ヘッダーには、貢献者と貢献年の一覧を含みます。

# Michal Čihař <michal@cihar.com>, 2012, 2018, 2019, 2020.
# Pavel Borecki <pavel@example.com>, 2018, 2019.
# Filip Hron <filip@example.com>, 2018, 2019.
# anonymous <noreply@weblate.org>, 2019.

configure ファイルの ALL_LINGUAS 変数の更新

新しい翻訳を追加すると、configureconfigure.in、または任意の configure.ac ファイルの ALL_LINGUAS 変数を更新します。

gettext 出力のカスタマイズ

改行処理など、 gettext の出力動作をカスタマイズできます。

以下のオプションがあります:

  • Wrap lines at 77 characters and at newlines

  • 改行文字でのみ改行する

  • 改行しない

注釈

By default gettext wraps lines at 77 characters and for newlines. With the --no-wrap parameter, it wraps only at newlines.

LINGUAS ファイルの更新

新しい翻訳が追加されたときに LINGUAS ファイルを更新します。

MO ファイルの生成

変更された PO ファイルごとに自動的に MO ファイルを生成します。

The location of the generated MO file can be customized and the field for it uses Template markup.

POT に一致する PO ファイルの更新 (msgmerge)

Updates all PO files (as configured by File mask) to match the POT file (as configured by 新しい翻訳のテンプレート) using msgmerge.

このアドオンは、新しい変更が upstream リポジトリから新しい変更をプルするたびに実行されます。msgmerge のコマンド ライン オプションの大部分はアドオンの設定で設定できます。

Git コミットをスカッシュ

変更をプッシュする前に、Git コミットをスカッシュします。

以下のモードを選択することができます:

バージョン 3.4 で追加.

  • すべてのコミットを 1 つにする

  • 言語別に

  • ファイル別に

バージョン 3.5 で追加.

  • 翻訳者別に

元のコミット メッセージは保持されますが、 Per author を選択するか、コミット メッセージに含めるようカスタマイズしない限り、翻訳者情報は失われます。

バージョン 4.1 で追加.

The original commit messages can optionally be overridden with a custom commit message.

Trailers (commit lines like Co-authored-by: ...) can optionally be removed from the original commit messages and appended to the end of the squashed commit message. This also generates proper Co-authored-by: credit for every translator.

JSON 出力形式のカスタマイズ

インデント処理や並べ替えなど、JSON 出力形式を調整できます。

Java プロパティ ファイルの整形

Java プロパティ ファイルをソートします。

古いコメントの削除

バージョン 3.7 で追加.

コメントを削除するまでの期間を設定します。

This can be useful to remove old comments which might have become outdated. Use with care as comment being old does not mean they have lost their importance.

古い提案の削除

バージョン 3.7 で追加.

提案を削除するまでの期間を設定します。

This can be very useful in connection with suggestion voting (see 相互評価) to remove suggestions which don't receive enough positive votes in a given timeframe.

RESX ファイルの更新

バージョン 3.9 で追加.

アップストリームの単一言語の基本ファイルに合わせて、すべての翻訳ファイルを更新します。使われていない文字列は削除し、新しい文字列は原文のコピーとして追加します。

ヒント

Use 翻訳ファイルのクリーンアップ if you only want to remove stale translation keys.

YAML 出力形式のカスタマイズ

バージョン 3.10.2 で追加.

行の長さや改行など、YAML 出力の動作を調整できます。

Customizing list of addons

The list of addons is configured by WEBLATE_ADDONS. To add another addon, simply include class absolute name in this setting.

Writing addon

You can write your own addons too, all you need to do is subclass weblate.addons.base.BaseAddon, define the addon metadata and implement a callback which will do the processing.

Executing scripts from addon

Addons can also be used to execute external scripts. This used to be integrated in Weblate, but now you have to write some code to wrap your script with an addon.

#
# Copyright © 2012 - 2020 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/>.
#
"""Example pre commit script."""


from django.utils.translation import gettext_lazy as _

from weblate.addons.events import EVENT_PRE_COMMIT
from weblate.addons.scripts import BaseScriptAddon


class ExamplePreAddon(BaseScriptAddon):
    # Event used to trigger the script
    events = (EVENT_PRE_COMMIT,)
    # Name of the addon, has to be unique
    name = "weblate.example.pre"
    # Verbose name and long descrption
    verbose = _("Execute script before commit")
    description = _("This addon executes a script.")

    # Script to execute
    script = "/bin/true"
    # File to add in commit (for pre commit event)
    # does not have to be set
    add_file = "po/{{ language_code }}.po"

For installation instructions see 品質検査、アドオン、自動修正のカスタマイズ.

The script is executed with the current directory set to the root of the VCS repository for any given component.

Additionally, the following environment variables are available:

WL_VCS

Version control system used.

WL_REPO

Upstream repository URL.

WL_PATH

Absolute path to VCS repository.

WL_BRANCH

バージョン 2.11 で追加.

Repository branch configured in the current component.

WL_FILEMASK

Filemask for current component.

WL_TEMPLATE

Filename of template for monolingual translations (can be empty).

WL_NEW_BASE

バージョン 2.14 で追加.

Filename of the file used for creating new translations (can be empty).

WL_FILE_FORMAT

Fileformat used in current component.

WL_LANGUAGE

Language of currently processed translation (not available for component level hooks).

WL_PREVIOUS_HEAD

Previous HEAD on update (available only when running post update hook).

WL_COMPONENT_SLUG

バージョン 3.9 で追加.

Component slug used to construct URL.

WL_PROJECT_SLUG

バージョン 3.9 で追加.

Project slug used to construct URL.

WL_COMPONENT_NAME

バージョン 3.9 で追加.

Component name.

WL_PROJECT_NAME

バージョン 3.9 で追加.

Project name.

WL_COMPONENT_URL

バージョン 3.9 で追加.

Component URL.

WL_ENGAGE_URL

バージョン 3.9 で追加.

Project engage URL.

Post update repository processing

Post update repository processing can be used to update translation files when the VCS upstream source changes. To achieve this, please remember that Weblate only sees files committed to the VCS, so you need to commit changes as a part of the script.

For example with Gulp you can do it using following code:

#! /bin/sh
gulp --gulpfile gulp-i18n-extract.js
git commit -m 'Update source strings' src/languages/en.lang.json

Pre commit processing of translations

Use the commit script to automatically make changes to the translation before it is committed to the repository.

It is passed as a single parameter consisting of the filename of a current translation.