துணை நிரல்களை உருவாக்குதல்

துணை நிரல்கள் என்பது வலைபெயர்ப்பு இல் உள்ளூர்மயமாக்கல் பணிப்பாய்வுகளைத் தனிப்பயனாக்குவதற்கான ஒரு வழியாகும்.

class weblate.addons.base.BaseAddon(storage)

Base class for Weblate add-ons.

classmethod can_install(*, component=None, category=None, project=None) bool

Check whether add-on is compatible with given component.

change_event(change, activity_log_id: int | None = None) dict | None

Event handler for change event.

check_change_action(change) bool

Early filtering of Change actions before triggering change_event callback.

component_update(component, activity_log_id: int | None = None) dict | None

Event handler for component update.

configure(configuration) None

Save configuration.

daily(component=None, category=None, project=None, activity_log_id: int | None = None) dict | None

Scope-aware daily entry point.

Override this for project-level logic, or override daily_component() for per-component logic.

daily_component(component, activity_log_id: int | None = None) dict | None

Per-component daily processing. Override this for component-level logic.

classmethod get_add_form(user, *, component=None, category=None, project=None, **kwargs)

Return configuration form for adding new add-on.

get_settings_form(user, **kwargs)

Return configuration form for this add-on.

manual(component=None, category=None, project=None, activity_log_id: int | None = None) dict | None

Scope-aware manual entry point.

By default this mirrors the daily handler and lets add-ons opt in explicitly by subscribing to the manual event.

manual_component(component, activity_log_id: int | None = None) dict | None

Per-component manual processing.

post_add(translation, activity_log_id: int | None = None) dict | None

Event handler after new translation is added.

post_commit(component, store_hash: bool, activity_log_id: int | None = None) dict | None

Event handler after changes are committed to the repository.

post_install(component, store_hash: bool, activity_log_id: int | None = None) dict | None

Event handler after add-on is installed.

post_push(component, activity_log_id: int | None = None) dict | None

Event handler after repository is pushed upstream.

post_remove(translation, activity_log_id: int | None = None) dict | None

Event handler after a translation is removed.

post_update(component, previous_head: str, skip_push: bool, changed_files: list[str], parse_after_update: bool = False, activity_log_id: int | None = None) dict | None

Event handler after repository is updated from upstream.

அளவுருக்கள்:
  • 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.

  • changed_files (list[str]) -- Files changed by the repository update.

pre_commit(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, activity_log_id: int | None = None) dict | None

Event handler before repository is pushed upstream.

pre_update(component, activity_log_id: int | None = None) dict | None

Event handler before repository is updated from upstream.

resolve_components(*, component=None, category=None, project=None)

Resolve scope to components iterator.

save_state() None

Save add-on state information.

unit_pre_create(unit, activity_log_id: int | None = None) dict | None

Event handler before new unit is created.

update_component_state(component, updater: Callable[[dict[str, object]], None]) None

Atomically merge component-scoped add-on state into the shared JSON field.

user()

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

Add-on hooks receive ORM objects from the weblate.*.models modules, including Addon, Component, Translation, Category, Project, Unit, Change, and User. Add-on configuration forms should subclass weblate.addons.forms.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

டைப்பிங் ஆட்-ஆன் உள்ளமைவு

ஆட்-ஆன் உள்ளமைவு Addon.configuration சாதொபொகு புலத்தில் சேமிக்கப்படுகிறது, எனவே மாதிரியானது நிலையான தரவை சாதொபொகு ஆக வைத்திருக்கும். கூடுதல் செயலாக்கங்கள் BaseAddon மற்றும் BaseAddonForm ஆகியவற்றை அளவுருவாக்குவதன் மூலம் அவற்றின் சொந்த உள்ளமைவைத் தட்டச்சு செய்யலாம்.

சேமிக்கப்பட்ட சாதொபொகு இயக்க நேர வடிவத்திலிருந்து வேறுபடும் போது இரண்டு TypedDict வகுப்புகளைப் பயன்படுத்தவும்: இசைவு, பொதுவாக total=False, மரபு அல்லது விடுபட்ட மதிப்புகளுக்கான சேமிக்கப்பட்ட உள்ளமைவு மற்றும் normalize_configuration() மூலம் வழங்கப்படும் மொத்த இயக்க நேர உள்ளமைவு. இயக்க நேர ஆட்-ஆன் குறியீடு self.configuration அல்லது self.get_configuration() எனப் படிக்க வேண்டும், எனவே இது raw persisted JSONக்குப் பதிலாக இயல்பாக்கப்பட்ட இயல்புநிலைகளைக் காணும்.

சேமிக்கப்பட்ட மற்றும் இயக்க நேர வடிவங்கள் ஒரே மாதிரியாக இருக்கும் எளிய துணை நிரல்களுக்கு, ஒற்றை TypedDict ஐ வரையறுத்து, BaseAddon வகை அளவுருக்கள் இரண்டிற்கும் அதைப் பயன்படுத்தவும். படிவத்தின் serialize_form() திரும்பும் வகையை சேமிக்கப்பட்ட உள்ளமைவு வகையுடன் சீரமைத்து வைக்கவும்.