Developing add-ons
Erweiterungen are way to customize localization workflow in Weblate.
- class weblate.addons.base.BaseAddon(storage=None)
Base class for Weblate add-ons.
- classmethod can_install(component, user)
Überprüfen Sie, ob die Erweiterung mit der angegebenen Komponente kompatibel ist.
- configure(settings)
Konfiguration speichern.
- daily(component)
Hook triggered daily.
- classmethod get_add_form(user, component, **kwargs)
Konfigurationsformular zum Hinzufügen einer neuen Erweiterung zurückgeben.
- get_settings_form(user, **kwargs)
Konfigurationsformular für diese Erweiterung zurückgeben.
- post_add(translation)
Hook wird ausgelöst, nachdem eine neue Übersetzung hinzugefügt wurde.
- post_commit(component)
Hook wird ausgelöst, nachdem Änderungen an das Repository übergeben wurden.
- post_push(component)
Hook wird ausgelöst, nachdem das Repository Upstream gepusht wurde.
- post_update(component, previous_head: str, skip_push: bool)
Hook triggered after repository is updated from upstream.
- Parameter
previous_head (str) – HEAD of the repository prior to update, can be blank on initial clone.
skip_push (bool) – Ob die Erweiterungsoperation das Pushen von Änderungen im Upstream überspringen soll. Normalerweise können Sie dies den zugrunde liegenden Methoden als
commit_and_push
odercommit_pending
übergeben.
- pre_commit(translation, author)
Hook wird ausgelöst, bevor Änderungen an das Repository übergeben werden.
- pre_push(component)
Hook triggered before repository is pushed upstream.
- pre_update(component)
Hook triggered before repository is updated from upstream.
- save_state()
Speichern Sie Informationen über den Zustand der Erweiterung.
- store_post_load(translation, store)
Hook wird ausgelöst, nachdem eine Datei analysiert wurde.
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)
Hook triggered before new unit is created.
Hier ein Beispiel für eine Erweiterung:
#
# Copyright © 2012–2022 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