アドオンの開発¶
アドオン は、Weblate の現地語化ワークフローをカスタマイズする方法です。
- class weblate.addons.base.BaseAddon(storage: Addon)¶
Weblate アドオンの基本クラス。
- classmethod can_install(component: Component, user: User | None) bool ¶
アドオンが指定したコンポーネントと互換性があるかどうかを確認します。
- component_update(component: weblate.trans.models.Component) None ¶
コンポーネント更新用のイベントハンドラ。
- configure(configuration: dict[str, Any]) None ¶
設定を保存します。
- daily(component: weblate.trans.models.Component) None ¶
毎日実行するイベント ハンドラー。
- classmethod get_add_form(user: User | None, *, component: Component | None = None, project: Project | None = None, **kwargs) BaseAddonForm | None ¶
新しいアドオンを追加するための設定フォームを返します。
- get_settings_form(user: User | None, **kwargs) BaseAddonForm | None ¶
このアドオンの設定フォームを返します。
- post_add(translation: Translation) None ¶
新しい翻訳が追加された後に実行するイベント ハンドラー。
- post_commit(component: weblate.trans.models.Component, store_hash: bool) None ¶
変更がリポジトリにコミットされた後に実行するイベント ハンドラー。
- post_push(component: weblate.trans.models.Component) None ¶
リポジトリが上流にプッシュされた後に実行するイベント ハンドラー。
- post_update(component: weblate.trans.models.Component, previous_head: str, skip_push: bool) None ¶
リポジトリが上流から更新された後に実行するイベント ハンドラー。
- パラメータ:
previous_head (str) -- 更新前のリポジトリの HEAD、最初のクローンでは空白にできる。
skip_push (bool) -- アドオン操作で上流への変更のプッシュをスキップさせるどうかを指定します。通常、これは
commit_and_push
またはcommit_pending
として基底クラスのメソッドに渡せます。
- pre_commit(translation: Translation, author: str, store_hash: bool) None ¶
変更がリポジトリにコミットされる前に実行するイベント ハンドラー。
- pre_push(component: weblate.trans.models.Component) None ¶
リポジトリが上流にプッシュされる前に実行するイベント ハンドラー。
- pre_update(component: weblate.trans.models.Component) None ¶
リポジトリが上流から更新される前に実行するイベント ハンドラー。
- save_state() None ¶
アドオンの状態を保存します。
- store_post_load(translation: Translation, store: TranslationFormat) None ¶
ファイルが解析された後に実行するイベント ハンドラー。
ファイル形式クラスのインスタンスを引数として受け取ります。
ファイル形式クラスのパラメータを変更する場合、例えばファイルをどのように保存するか設定する場合に便利です。
- class weblate.addons.models.Addon¶
アドオン用の ORM オブジェクト。
- class weblate.trans.models.Component¶
コンポーネントの ORM オブジェクト。
- class weblate.trans.models.Translation¶
翻訳用の ORM オブジェクト。
- class weblate.trans.models.Project¶
プロジェクトの ORM オブジェクト。
- class weblate.trans.models.Unit¶
ユニットの ORM オブジェクト。
- class weblate.trans.models.User¶
ユーザー用の ORM オブジェクト。
- class weblate.trans.models.TranslationFormat¶
翻訳ファイルのラッパー。
- class weblate.trans.models.BaseAddonForm¶
Base form for configuring add-ons.
アドオンの例:
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
from django.utils.translation import gettext_lazy
from weblate.addons.base import BaseAddon
from weblate.addons.events import AddonEvent
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: set[AddonEvent] = {
AddonEvent.EVENT_PRE_COMMIT,
}
# Add-on unique identifier
name = "weblate.example.example"
# Verbose name shown in the user interface
verbose = gettext_lazy("Example add-on")
# Detailed add-on description
description = gettext_lazy("This add-on does nothing it is just an example.")
# Callback to implement custom behavior
def pre_commit(self, translation, author: str, store_hash: bool) -> None:
return