Customizing Weblate¶
Weblate can be extended or customized using standard Django and Python ways. Always please consider contributing changes upstream so that everybody can benefit from your additions. Including your changes in Weblate itself will also reduce your maintenance costs - code in Weblate is taken care of when changing internal interfaces or refactoring the code.
Предупреждение
Neither internal interfaces or templates are considered as stable API. Please review your customizations on every upgrade, the interface or their semantics might change without notice.
См.также
Creating Python module¶
If you are not familiar with Python, you might want to look into Python For Beginners which explains the basics and will point you to further tutorials.
We’re about to write some custom Python code (called a module) and we need a
place to store it - either in the system path (usually something like
/usr/lib/python3.7/site-packages/
) or in the Weblate directory, which
is also added to the interpreter search path.
The best approach is to create a proper Python package out of your customization:
Create a folder for your package (we will use weblate_customization).
Inside, create a
setup.py
file to describe the package:from setuptools import setup setup( name = "weblate_customization", version = "0.0.1", author = "Michal Cihar", author_email = "michal@cihar.com", description = "Sample Custom check for Weblate.", license = "BSD", keywords = "weblate check example", packages=['weblate_customization'], )
Create a folder for the Python module (also called weblate_customization).
To make sure Python can import the module, add an
__init__.py
file inside the module folder. Put the rest of the customization code in this folder.Now it’s possible to install this package using pip install -e .
Once installed, the module can be used in the Weblate configuration (for example
weblate_customization.checks.FooCheck
).
Overall your module structure should look like:
weblate_customization
├── setup.py
└── weblate_customization
├── __init__.py
├── addons.py
└── checks.py
You can find example application for custimizing Weblate at <https://github.com/WeblateOrg/customize-example>, it covers all topics described below.
Changing logo¶
To change logo you need to create simple Django app which will contain static
files which you want to overwrite (see Creating Python module). Then you add it
into INSTALLED_APPS
:
INSTALLED_APPS = (
# Add your customization as first
'weblate_customization',
# Weblate apps are here...
)
To adjust branding, you will most likely want to override following files:
icons/weblate.svg
- Logo shown in the navigation bar.
logo-*.png
- Web icons depending on screen resolution and browser.
favicon.ico
- Web icon used by legacy browsers.
weblate-*.png
- In application avatars for bot or anonymous users. Also used by some browsers as a shortcut icon.
email-logo.png
- Used in notifications emails.
And then execute ./manage.py collectstatic --noinput
, this will collect
static files served to clients.
Custom quality checks and auto fixes¶
You have implemented code for Custom automatic fixups or Customizing behavior and
now it’s time to install it into Weblate. First place them into your Python
module with Weblate customization (see Creating Python module). Then enabled it
is just matter of adding its fully-qualified path to Python class to
appropriate settings (CHECK_LIST
or AUTOFIX_LIST
):
CHECK_LIST = (
'weblate_customization.checks.FooCheck',
)
См.также
Custom addons¶
First place them into your Python module with Weblate customization (see
Creating Python module). Then enabled it is just matter of adding its
fully-qualified path to Python class to appropriate settings
(WEBLATE_ADDONS
):
WEBLATE_ADDONS = (
'weblate_customization.addons.ExamplePreAddon',
)
См.также