Разработка надстроек¶
Надстройки — это способ внести изменений в ваш рабочий процесс локализации с помощью Weblate.
- class weblate.addons.base.BaseAddon(storage: Addon)¶
Базовый класс для всех надстроек Weblate.
- classmethod can_install(*, component: Component | None = None, project: Project | None = None) bool¶
Проверяет, совместима ли надстройка с указанным компонентом.
- change_event(change: Change, activity_log_id: int | None = None) dict | None¶
Event handler for change event.
- check_change_action(change: Change) bool¶
Early filtering of Change actions before triggering change_event callback.
- component_update(component: weblate.trans.models.Component, activity_log_id: int | None = None) dict | None¶
Event handler for component update.
- configure(configuration: dict[str, Any]) None¶
Сохранение конфигурации.
- daily(component: weblate.trans.models.Component, activity_log_id: int | None = None) dict | None¶
Event handler daily.
- 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, activity_log_id: int | None = None) dict | None¶
Event handler after new translation is added.
- post_commit(component: weblate.trans.models.Component, store_hash: bool, activity_log_id: int | None = None) dict | None¶
Event handler after changes are committed to the repository.
- post_install(component: weblate.trans.models.Component, store_hash: bool, activity_log_id: int | None = None) dict | None¶
Event handler after add-on is installed.
- post_push(component: weblate.trans.models.Component, activity_log_id: int | None = None) dict | None¶
Event handler after repository is pushed upstream.
- post_update(component: weblate.trans.models.Component, previous_head: str, skip_push: bool, activity_log_id: int | None = None) dict | None¶
Event handler after repository is updated from upstream.
- Параметры:
previous_head (str) – Текущее состояние репозитория (HEAD) перед обновлением; может быть пустым, если этот репозиторий только что склонирован.
skip_push (bool) – Определяет, должна ли надстройка пропустить собственно отправку изменений в вышестоящий репозиторий. Обычно этот параметр просто передаётся в конкретные методы реализации, как
commit_and_pushилиcommit_pending.
- pre_commit(translation: Translation, author: str, store_hash: bool, activity_log_id: int | None = None) dict | None¶
Event handler before changes are committed to the repository.
- pre_push(component: weblate.trans.models.Component, activity_log_id: int | None = None) dict | None¶
Event handler before repository is pushed upstream.
- pre_update(component: weblate.trans.models.Component, activity_log_id: int | None = None) dict | None¶
Event handler before repository is updated from upstream.
- save_state() None¶
Сохранить информацию о состоянии надстройки.
- class weblate.addons.models.Addon¶
ORM-объект для дополнения.
- class weblate.trans.models.Component¶
ORM object for a component.
- class weblate.trans.models.Translation¶
ORM-объект для перевода.
- class weblate.trans.models.Project¶
ORM object for a project.
- class weblate.trans.models.Unit¶
ORM object for an unit.
- class weblate.trans.models.Change¶
ORM object for an change.
- class weblate.trans.models.User¶
ORM object for an user.
- class weblate.trans.models.TranslationFormat¶
Обёртка файла перевода.
- class weblate.trans.models.BaseAddonForm¶
Базовая форма для конфигурирования надстроек.
Вот пример надстройки:
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import annotations
from typing import TYPE_CHECKING, ClassVar
from django.utils.translation import gettext_lazy
from weblate.addons.base import BaseAddon
from weblate.addons.events import AddonEvent
if TYPE_CHECKING:
from weblate.addons.base import CompatDict
class ExampleAddon(BaseAddon):
# Filter for compatible components, every key is
# matched against property of component
compat: ClassVar[CompatDict] = {
"file_format": {"po", "po-mono"},
}
# List of events add-on should receive
events: ClassVar[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,
activity_log_id: int | None = None,
) -> None:
return