Розробка додатків¶
За допомогою можливості Доповнення ви можете налаштувати процедуру локалізації у Weblate.
-
class
weblate.addons.base.
BaseAddon
(storage=None)¶ -
classmethod
can_install
(component, user)¶ Перевірка, чи сумісний додаток із вказаним складником.
-
configure
(settings)¶ Збереження налаштувань.
-
daily
(component)¶ Скрипт обробки, який вмикається щодня.
-
classmethod
get_add_form
(user, component, **kwargs)¶ Повернення форми налаштовування для додавання нового додатка.
-
get_settings_form
(user, **kwargs)¶ Повернення форми налаштовування для цього додатка.
-
post_add
(translation)¶ Скрипт обробки, який вмикається після додавання нового перекладу.
-
post_commit
(component)¶ Скрипт, який вмикається після того, як зміни буде внесено до сховища.
-
post_push
(component)¶ Скрипт, який вмикається після запису до сховища основної гілки розробки.
-
post_update
(component, previous_head: str, skip_push: bool)¶ Скрипт обробки, який вмикається після оновлення сховища у основній гілці розробки.
- Параметри
-
pre_commit
(translation, author)¶ Сценарій, який вмикається, перш ніж зміни буде внесено до сховища.
-
pre_push
(component)¶ Скрипт, який вмикається перед записом із сховища до основної гілки розробки.
-
pre_update
(component)¶ Скрипт, який вмикається перед оновленням сховища з основної гілки розробки.
-
save_state
()¶ Збереження відомостей щодо стану додатка.
-
stay_on_create
= False¶ Базовий клас для додатків Weblate.
-
store_post_load
(translation, store)¶ Скрипт обробки, який вмикається після обробки файла.
Отримує як аргумент екземпляр класу форматування файлів.
Корисний для внесення змін до класу форматування файлів, наприклад, для коригування способу зберігання файла.
-
unit_pre_create
(unit)¶ Скрипт обробки, який вмикається до створення нового модуля.
-
classmethod
Ось приклад додатка:
#
# Copyright © 2012 - 2021 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 addon should receive
events = (EVENT_PRE_COMMIT,)
# Addon unique identifier
name = "weblate.example.example"
# Verbose name shown in the user interface
verbose = _("Example addon")
# Detailed addon description
description = _("This addon does nothing it is just an example.")
# Callback to implement custom behavior
def pre_commit(self, translation, author):
return