開發附加元件¶
附加元件 是在 Weblate 中自訂在地化工作流的方法。
- class weblate.addons.base.BaseAddon(storage: Addon)¶
Weblate 附加元件的基本類別。
- classmethod can_install(component: Component, user: User | None)¶
Check whether add-on is compatible with given component.
- component_update(component: weblate.trans.models.Component) None ¶
Event handler for component update.
- configure(configuration) None ¶
儲存組態。
- daily(component: weblate.trans.models.Component) None ¶
Event handler daily.
- classmethod get_add_form(user: User | None, *, component: Component | None = None, project: Project | None = None, **kwargs)¶
Return configuration form for adding new add-on.
- post_add(translation: Translation) None ¶
Event handler after new translation is added.
- post_commit(component: weblate.trans.models.Component, store_hash: bool) None ¶
Event handler after changes are committed to the repository.
- post_push(component: weblate.trans.models.Component) None ¶
Event handler after repository is pushed upstream.
- post_update(component: weblate.trans.models.Component, previous_head: str, skip_push: bool) None ¶
Event handler after repository is updated from upstream.
- 參數:
previous_head (str) – 倉儲更新前的 HEAD,在初始克隆時可以是空白的。
skip_push (bool) – Whether the add-on operation should skip pushing changes upstream. Usually you can pass this to underlying methods as
commit_and_push
orcommit_pending
.
- pre_commit(translation: Translation, author: str, store_hash: bool) None ¶
Event handler before changes are committed to the repository.
- pre_push(component: weblate.trans.models.Component) None ¶
Event handler before repository is pushed upstream.
- pre_update(component: weblate.trans.models.Component) None ¶
Event handler before repository is updated from upstream.
- save_state() None ¶
Save add-on state information.
- store_post_load(translation: Translation, store: TranslationFormat) None ¶
Event handler after a file is parsed.
它接收文件格式類的事件作為參數。
這對修復該文件格式類參數有用,例如,調整文件如何儲存。
- user()¶
Weblate user used to track changes by this add-on.
- class weblate.addons.models.Addon¶
ORM object for an add-on.
- class weblate.trans.models.Component¶
ORM object for a component.
- class weblate.trans.models.Translation¶
ORM object for a translation.
- class weblate.trans.models.Project¶
ORM object for a project.
- class weblate.trans.models.Unit¶
ORM object for an unit.
- class weblate.trans.models.User¶
ORM object for an user.
- class weblate.trans.models.TranslationFormat¶
Translation file wrapper.
Here is an example add-on:
# 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: str, store_hash: bool) -> None:
return