客製 Weblate¶
使用 Django 和 Python 擴充與客製。將您的變更貢獻給上游,使每人都能夠受益。這降低了您的維護成本; Weblate 中的代碼對變更內部介面或重構編碼時的情況。
提示
You can also customize Weblate look in 外觀自訂.
警告
Neither internal interfaces nor templates are considered a stable API. Please review your customizations for every upgrade, the interfaces or their semantics might change without notice.
也參考
建立 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.12/site-packages/) or in the Weblate directory, which
is also added to the interpreter search path.
提示
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 )。
Within it, create a
pyproject.tomlfile to describe the package:[build-system] requires = ["uv_build>=0.8.18,<0.9.0"] build-backend = "uv_build" [project] name = "weblate-customization" version = "0.1.0" description = "Add your description here" requires-python = ">=3.13" dependencies = []
為 Python 模組建立資料夾:
src/weblate_customization在裡面建立
__init__.py檔案來確認 Python 可以匯入模組。This package can now be installed using uv pip install -e. More info to be found in Editable packages documentation.
模組一旦安裝,就可以用在 Weblate 配置中(例如
weblate_customization.checks.FooCheck)。
您的套件結構應該看起來像這樣:
weblate_customization
├── pyproject.toml
└── src
└── weblate_customization
├── __init__.py
├── addons.py
└── checks.py
可以在 <https://github.com/WeblateOrg/customize-example> 找到客製 Weblate 範例,它涵蓋了下面描述的所有題目。
替換 logo 中¶
建立簡單的 Django 應用程式來包含想要覆寫的靜態檔案(請參閱 建立 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,來收集提供給用戶端的靜態檔案。
自訂的品質檢查、附加元件與自動修復¶
To install your code for 自訂自動修正, 撰寫自訂檢查, 自訂機器翻譯 or 編寫附加元件 in Weblate:
Place the files into your Python module containing the Weblate customization (see 建立 Python 模組 or 自訂程式碼).
Add its fully-qualified path to the Python class in the dedicated settings:
# Checks
CHECK_LIST += ("weblate_customization.checks.FooCheck",)
# Autofixes
AUTOFIX_LIST += ("weblate_customization.autofix.FooFixer",)
# Add-ons
WEBLATE_ADDONS += ("weblate_customization.addons.ExamplePreAddon",)
# Automatic suggestions
WEBLATE_MACHINERY += ("weblate_customization.machinery.SampleTranslation",)
也參考