Dezvoltarea de add-on-uri

Suplimente sunt o modalitate de a personaliza fluxul de lucru al localizării în Weblate.

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

Clasa de bază pentru add-on-urile Weblate.

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

Verifică dacă suplimentul este compatibil cu componenta dată.

component_update(component: weblate.trans.models.Component) None

Event handler for component update.

configure(configuration) None

Salvați configurația.

daily(component: weblate.trans.models.Component) None

Event handler daily.

classmethod get_add_form(user: User | None, *, component: Component | None = None, project: Project | None = None, **kwargs)

Returnează formularul de configurare pentru adăugarea unui nou add-on.

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

Returnează formularul de configurare pentru acest add-on.

post_add(translation: Translation) None

Event handler after new translation is added.

post_commit(component: weblate.trans.models.Component) None

Event handler after changes are committed to the repository.

post_push(component: weblate.trans.models.Component) None

Event handler after repository is pushed upstream.

post_update(component: weblate.trans.models.Component, previous_head: str, skip_push: bool, child: bool) None

Event handler after repository is updated from upstream.

Parametrii:
  • previous_head (str) – HEAD al depozitului înainte de actualizare, poate fi gol la clona inițială.

  • skip_push (bool) – Dacă operațiunea de adăugare trebuie să sară peste împingerea modificărilor în amonte. De obicei, puteți trece acest lucru la metodele subiacente ca commit_and_push sau commit_pending.

pre_commit(translation: Translation, author: User) None

Event handler before changes are committed to the repository.

pre_push(component: weblate.trans.models.Component) None

Event handler before repository is pushed upstream.

pre_update(component: weblate.trans.models.Component) None

Event handler before repository is updated from upstream.

save_state() None

Salvați informațiile privind starea add-on-ului.

store_post_load(translation: Unit, store: TranslationFormat) None

Event handler after a file is parsed.

Acesta primește ca argument o instanță a unei clase de format de fișier.

Acest lucru este util pentru a modifica parametrii clasei de format de fișier, de exemplu pentru a ajusta modul în care va fi salvat fișierul.

unit_pre_create(unit: Unit) None

Event handler before new unit is created.

user()

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

class weblate.addons.models.Addon

ORM object for an add-on.

class weblate.trans.models.Component

ORM object for a component.

class weblate.trans.models.Translation

ORM object for a translation.

class weblate.trans.models.Project

ORM object for a project.

class weblate.trans.models.Unit

ORM object for an unit.

class weblate.trans.models.User

ORM object for an user.

class weblate.trans.models.TranslationFormat

Translation file wrapper.

Iată un exemplu de 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 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) -> None:
        return