アドオンの開発
アドオン は、Weblate の現地語化ワークフローをカスタマイズする方法です。
- class weblate.addons.base.BaseAddon(storage=None)
Weblate アドオンの基本クラス。
- classmethod can_install(component, user)
アドオンが指定したコンポーネントと互換性があるかどうかを確認します。
- configure(settings)
設定を保存します。
- daily(component)
毎日起動するフック。
- classmethod get_add_form(user, component, **kwargs)
新しいアドオンを追加するための設定フォームを返します。
- get_settings_form(user, **kwargs)
このアドオンの設定フォームを返します。
- post_add(translation)
新しい翻訳が追加された後にフックが実行されます。
- post_commit(component)
変更がリポジトリにコミットされた後にフックが起動します。
- post_push(component)
リポジトリがアップストリームにプッシュされた後にフックが起動します。
- post_update(component, previous_head: str, skip_push: bool)
リポジトリがアップストリームから更新された後に起動するフック。
- パラメータ
previous_head (str) -- 更新前のリポジトリの HEAD、最初のクローンでは空白にできる。
skip_push (bool) -- アドオン操作でアップストリームへの変更のプッシュをスキップさせるどうかを指定します。通常、これは
commit_and_push
またはcommit_pending
として基底クラスのメソッドに渡せます。
- pre_commit(translation, author)
変更がリポジトリにコミットされる前にフックが起動します。
- pre_push(component)
リポジトリがアップストリームにプッシュされる前に起動するフック。
- pre_update(component)
リポジトリがアップストリームから更新される前に起動するフック。
- save_state()
アドオンの状態を保存します。
- store_post_load(translation, store)
ファイルが解析された後にフックを起動します。
ファイル形式クラスのインスタンスを引数として受け取ります。
ファイル形式クラスのパラメータを変更する場合、例えばファイルをどのように保存するか設定する場合に便利です。
- unit_pre_create(unit)
新しいユニットが作成される前にフックが起動します。
アドオンの例:
#
# Copyright © 2012–2022 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.addons.base import BaseAddon
from weblate.addons.events import EVENT_PRE_COMMIT
class ExampleAddon(BaseAddon):
# Filter for compatible components, every key is
# matched against property of component
compat = {"file_format": {"po", "po-mono"}}
# List of events add-on should receive
events = (EVENT_PRE_COMMIT,)
# Add-on unique identifier
name = "weblate.example.example"
# Verbose name shown in the user interface
verbose = _("Example add-on")
# Detailed add-on description
description = _("This add-on does nothing it is just an example.")
# Callback to implement custom behavior
def pre_commit(self, translation, author):
return