アドオンの開発

アドオン は、Weblate の現地語化ワークフローをカスタマイズする方法です。

class weblate.addons.base.BaseAddon(storage: Addon)

Weblate アドオンの基本クラス。

classmethod can_install(component: Component, user: User | None)

アドオンが指定したコンポーネントと互換性があるかどうかを確認します。

component_update(component: Component) None

コンポーネント更新用のイベントハンドラ。

configure(configuration) None

設定を保存します。

daily(component: Component) None

毎日実行するイベント ハンドラー。

classmethod get_add_form(user: User | None, *, component: Component | None = None, project: Project | None = None, **kwargs)

新しいアドオンを追加するための設定フォームを返します。

get_settings_form(user: User | None, **kwargs)

このアドオンの設定フォームを返します。

post_add(translation: Translation) None

新しい翻訳が追加された後に実行するイベント ハンドラー。

post_commit(component: Component) None

変更がリポジトリにコミットされた後に実行するイベント ハンドラー。

post_push(component: Component) None

リポジトリが上流にプッシュされた後に実行するイベント ハンドラー。

post_update(component: Component, previous_head: str, skip_push: bool, child: bool) None

リポジトリが上流から更新された後に実行するイベント ハンドラー。

パラメータ:
  • previous_head (str) -- 更新前のリポジトリの HEAD、最初のクローンでは空白にできる。

  • skip_push (bool) -- アドオン操作で上流への変更のプッシュをスキップさせるどうかを指定します。通常、これは commit_and_push または commit_pending として基底クラスのメソッドに渡せます。

pre_commit(translation: Translation, author: User) None

変更がリポジトリにコミットされる前に実行するイベント ハンドラー。

pre_push(component: Component) None

リポジトリが上流にプッシュされる前に実行するイベント ハンドラー。

pre_update(component: Component) None

リポジトリが上流から更新される前に実行するイベント ハンドラー。

save_state() None

アドオンの状態を保存します。

store_post_load(translation: Unit, store: TranslationFormat) None

ファイルが解析された後に実行するイベント ハンドラー。

ファイル形式クラスのインスタンスを引数として受け取ります。

ファイル形式クラスのパラメータを変更する場合、例えばファイルをどのように保存するか設定する場合に便利です。

unit_pre_create(unit: Unit) None

新しいユニットが作成される前に実行するイベント ハンドラー。

user()

このアドオンによる変更を追跡するために使われる Weblate ユーザー。

class weblate.addons.base.Addon

アドオン用の ORM オブジェクト。

class weblate.addons.base.Component

コンポーネントの ORM オブジェクト。

class weblate.addons.base.Translation

翻訳用の ORM オブジェクト。

class weblate.addons.base.Project

プロジェクトの ORM オブジェクト。

class weblate.addons.base.Unit

ユニットの ORM オブジェクト。

class weblate.addons.base.User

ユーザー用の ORM オブジェクト。

class weblate.addons.base.TranslationFormat

翻訳ファイルのラッパー。

アドオンの例:

# 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 = (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) -> None:
        return