Customizing Weblate¶
Extend and customize using Django and Python. Contribute your changes upstream so that everybody can benefit. This reduces your maintenance costs; code in Weblate is taken care of when changing internal interfaces or refactoring the code.
警告
Neither internal interfaces nor templates are considered a stable API. Please review your own customizations for every upgrade, the interfaces or their semantics might change without notice.
参考
Creating a Python module¶
If you are not familiar with Python, you might want to look into Python For Beginners, explaining the basics and pointing to further tutorials.
To write some custom Python code (called a module), a
place to store it is needed, 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.
Better yet, turn your customization into a proper Python package:
Create a folder for your package (we will use weblate_customization).
Within it, create a
setup.py
file to describe the package:from setuptools import setup setup( name="weblate_customization", version="0.0.1", author="Your name", author_email="yourname@example.com", description="Sample Custom check for Weblate.", license="GPLv3+", keywords="Weblate check example", packages=["weblate_customization"], )
Create a folder for the Python module (also called
weblate_customization
) for the customization code.Within it, create a
__init__.py
file to make sure Python can import the module.This package can now be installed using pip install -e. More info to be found in “Editable” Installs.
Once installed, the module can be used in the Weblate configuration (for example
weblate_customization.checks.FooCheck
).
Your module structure should look like this:
weblate_customization
├── setup.py
└── weblate_customization
├── __init__.py
├── addons.py
└── checks.py
You can find an example of customizing Weblate at <https://github.com/WeblateOrg/customize-example>, it covers all the topics described below.
Changing the logo¶
上書きしたい静的ファイルを含む単純な Django アプリケーションを作成します(参照:Creating a Python module)。
Branding appears in the following files:
icons/weblate.svg
Logo shown in the navigation bar.
logo-*.png
Web icons depending on screen resolution and web-browser.
favicon.ico
Web icon used by legacy browsers.
weblate-*.png
Avatars for bots or anonymous users. Some web-browsers use these as shortcut icons.
email-logo.png
Used in notifications e-mails.
Add it to
INSTALLED_APPS
:INSTALLED_APPS = ( # Add your customization as first "weblate_customization", # Weblate apps are here… )
Run
weblate collectstatic --noinput
, to collect static files served to clients.
品質検査、アドオン、自動修正のカスタマイズ¶
自動修正のカスタマイズ、独自検査の記述、または アドオンの作成 のコードを Weblate にインストールする方法:
Weblate のカスタマイズを含む、Python モジュール内にファイルを置く(参照: Creating a Python module)。
Python クラスへの完全修飾パスを専用設定に追加する(
WEBLATE_ADDONS
、CHECK_LIST
またはAUTOFIX_LIST
):
# Checks
CHECK_LIST += ("weblate_customization.checks.FooCheck",)
# Autofixes
AUTOFIX_LIST += ("weblate_customization.autofix.FooFixer",)
# Addons
WEBLATE_ADDONS += ("weblate_customization.addons.ExamplePreAddon",)