定制 Weblate
使用 Django 和 Python 擴展與定制。將您的更改貢獻給上游,使每人都能夠受益。這降低了您的維護成本; Weblate 中的代碼對更改內部界面或重構編碼時的情況。
警告
內部界面與模板都不被認為是穩定的 API。請對每次升級都複查自己的定制,接口或其語義可能未經通知就進行更改。
也參考
建立 Python 模塊
如果不熟悉 Python,您可以查看 Python For Beginners,它解釋了其基本內容並指向了高級教程。
To write a file with custom Python code (called a module), a place to store it
is needed, either in the system path (usually something like
/usr/lib/python3.9/site-packages/
) or in the Weblate directory, which
is also added to the interpreter search path.
在 3.8-5 版本新加入: When using Docker, you can place Python modules in
/app/data/python/
(see Docker 容器 volumes), so they can be loaded
by Weblate, for example from a settings override file.
更好地是,將您的定制化轉變為適當的 Python 包:
為您的包建立文件夾(我們會使用 weblate_customization )。
在裡面新建`setup.py` 文件來描述包:
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"], )
建立定制代碼的 Python 模塊( 也被成為
weblate_customization
)的文件夾。在裡面建立
__init__.py
文件來確認 Python 可以導入模塊。現在可以使用 pip install -e 安裝這個包。更多信息可以在 Editable installs 中找到。
模塊一旦安裝,就可以用在 Webalte 配置中(例如
weblate_customization.checks.FooCheck
)。
Your package structure should look like this:
weblate_customization
├── setup.py
└── weblate_customization
├── __init__.py
├── addons.py
└── checks.py
可以在 <https://github.com/WeblateOrg/customize-example> 找到定制 Weblate 的例子,它涵蓋了下面描述的所有題目。
替換 logo 中
建立簡單的 Django app 來包含想要覆蓋的靜態文件(請參見 建立 Python 模塊 )。
品牌出現在後面的文件中:
icons/weblate.svg
導航條中顯示的 Logo。
logo-*.png
根據屏幕分辨率和 web 瀏覽器的 Web 圖標。
favicon.ico
傳統瀏覽器使用的 Web 圖標。
weblate-*.png
機器人或匿名使用者使用的頭像。一些 Web 瀏覽器 使用這些作為快捷圖標。
email-logo.png
在通知電子郵件中使用。
加入到
INSTALLED_APPS
:INSTALLED_APPS = ( # Add your customization as first "weblate_customization", # Weblate apps are here… )
運行
weblate collectstatic --noinput
,來收集提供給客戶端的靜態文件。
自訂的質量檢查、附加元件和自動修復
要在 Weblate 中安裝您的 自訂自動修正,撰寫自定義查核 或 Writing add-on 代碼:
將文件放進您的包含 Weblate 定制的 Python 模塊中(請參見 建立 Python 模塊 )。
在專用設置(
WEBLATE_ADDONS
、CHECK_LIST
或AUTOFIX_LIST
)中將其完全合法的路徑添加到 Python 類中:
# Checks
CHECK_LIST += ("weblate_customization.checks.FooCheck",)
# Autofixes
AUTOFIX_LIST += ("weblate_customization.autofix.FooFixer",)
# Add-ons
WEBLATE_ADDONS += ("weblate_customization.addons.ExamplePreAddon",)