アドオンの開発¶
アドオン は、Weblate の現地語化ワークフローをカスタマイズする方法です。
- class weblate.addons.base.BaseAddon(storage=None)¶
- 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)¶
リポジトリが upstream にプッシュされた後にフックが起動します。
- pre_commit(translation, author)¶
変更がリポジトリにコミットされる前にフックが起動します。
- pre_push(component)¶
リポジトリが upstream にプッシュされる前に起動するフック。
- pre_update(component)¶
リポジトリが upstream から更新される前に起動するフック。
- save_state()¶
アドオンの状態を保存します。
- stay_on_create = False¶
Weblate アドオンの基本クラス。
- store_post_load(translation, store)¶
ファイルが解析された後にフックを起動します。
It receives an instance of a file format class as a argument.
This is useful to modify file format class parameters, for example adjust how the file will be saved.
- unit_pre_create(unit)¶
新しいユニットが作成される前にフックが起動します。
アドオンの例:
#
# 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.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