Developing add-ons#

Add-ons 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)#

Check whether add-on is compatible with given component.

configure(settings)#

Save configuration.

daily(component)#

Hook triggered daily.

classmethod get_add_form(user, component, **kwargs)#

Return configuration form for adding new add-on.

get_settings_form(user, **kwargs)#

Return configuration form for this add-on.

post_add(translation)#

Hook triggered after new translation is added.

post_commit(component)#

Hook triggered after changes are committed to the repository.

post_push(component)#

Hook triggered after repository is pushed upstream.

post_update(component, previous_head: str, skip_push: bool)#

Hook triggered after repository is updated from upstream.

Parameters:
  • previous_head (str) – HEAD of the repository prior to update, can be blank on initial clone.

  • 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 or commit_pending.

pre_commit(translation, author)#

Hook triggered before changes are committed to the repository.

pre_push(component)#

Hook triggered before repository is pushed upstream.

pre_update(component)#

Hook triggered before repository is updated from upstream.

save_state()#

Save add-on state information.

store_post_load(translation, store)#

Hook triggered after a file is parsed.

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.

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 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 = 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):
        return