Tworzenie dodatków#

Dodatki are way to customize localization workflow in Weblate.

class weblate.addons.base.BaseAddon(storage: Addon)#

Base class for Weblate add-ons.

classmethod can_install(component: Component, user: User | None)#

Sprawdź, czy dodatek jest kompatybilny z danym komponentem.

component_update(component: Component)#

Hook for component update.

configure(configuration)#

Zapisz konfigurację.

daily(component: Component)#

Hook wyzwalany codziennie.

classmethod get_add_form(user: User | None, component: Component, **kwargs)#

Zwróć formularz konfiguracji dla dodania nowego dodatku.

get_settings_form(user: User | None, **kwargs)#

Zwróć formularz konfiguracji dla tego dodatku.

post_add(translation: Translation)#

Hook wyzwalany po dodaniu nowego tłumaczenia.

post_commit(component: Component)#

Hook wyzwalany po scommitowaniu zmian do repozytorium.

post_push(component: Component)#

Hook wyzwalany po wysłaniu zmian na repozytorium.

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

Hook triggered after repository is updated from upstream.

Parametry:
  • 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: Translation, author: User)#

Hook wyzwalany przed scommitowaniem zmian do repozytorium.

pre_push(component: Component)#

Hook triggered before repository is pushed upstream.

pre_update(component: Component)#

Hook triggered before repository is updated from upstream.

save_state()#

Zapisz informacje o stanie dodatku.

store_post_load(translation: Unit, store: TranslationFormat)#

Hook wyzwalany po przeparsowaniu pliku.

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: Unit)#

Hook triggered before new unit is created.

user()#

Weblate user used to track changes by this add-on.

class weblate.addons.base.Addon#

ORM object for an add-on.

class weblate.addons.base.Component#

ORM object for a component.

class weblate.addons.base.Translation#

ORM object for a translation.

class weblate.addons.base.Project#

ORM object for a project.

class weblate.addons.base.Unit#

ORM object for an unit.

class weblate.addons.base.User#

ORM object for an user.

class weblate.addons.base.TranslationFormat#

Translation file wrapper.

Oto przykładowy dodatek:

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