开发附加组件¶
附加组件 是在 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)¶ 仓库推送到上游之后触发钩子。
-
pre_commit
(translation, author)¶ 更改被提交到仓库前触发钩子。
-
pre_push
(component)¶ 在仓库推送上游之前触发钩子。
-
pre_update
(component)¶ 在仓库从上游更新之前触发钩子。
-
save_state
()¶ 保存附加组件状态信息。
-
stay_on_create
= False¶ Weblate 附加组件的基础类。
-
store_post_load
(translation, store)¶ 文件解析后触发钩子。
它接收文件格式类的事件作为参数。
这对修复该文件格式类参数有用,例如,调整文件如何存储。
-
unit_pre_create
(unit)¶ 创建新的单元前触发的钩子。
-
classmethod
这里是一个插件的例子:
#
# 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 addon should receive
events = (EVENT_PRE_COMMIT,)
# Addon unique identifier
name = "weblate.example.example"
# Verbose name shown in the user interface
verbose = _("Example addon")
# Detailed addon description
description = _("This addon does nothing it is just an example.")
# Callback to implement custom behavior
def pre_commit(self, translation, author):
return