選用 Weblate 模組

您的安裝環境可使用多個選用模組。

Git 匯出器

使用 HTTP(S) 為您提供對底層 Git 儲存庫的唯讀存取。

安裝

  1. 將 weblate.gitexport 加入 settings.py 的已安裝應用程式清單:

    INSTALLED_APPS += ("weblate.gitexport",)
    
  2. 透過安裝後移轉資料庫,將現有的儲存庫匯出:

    weblate migrate
    

提示

Git 匯出器在我們的官方 Docker 映像中處於開啟狀態。要關閉它,使用:

WEBLATE_REMOVE_APPS=weblate.gitexport

使用

模組自動鉤入 Weblate,並且在 組件設定 中設定匯出儲存庫 URL。儲存庫在 Weblate URL的 /git/ 部分下是可以存取的,例如 https://example.org/git/weblate/main/。

公開可用專案的儲存庫可以被複製而無需認證:

git clone 'https://example.org/git/weblate/main/'

瀏覽採用 私人 存取控制,或啟用 REQUIRE_LOGIN 的受限儲存庫時,需要使用 API 權杖,該權杖可從 使用者個人檔案 取得:

git clone 'https://user:KEY@example.org/git/weblate/main/'

備註

Weblate 會提供 Git 存放庫本身,但不會提供 Git LFS 物件。支援的行為請參閱 Git LFS。請從上游存放庫複製使用 Git LFS 的存放庫,並將 Weblate 新增為另一個遠端。若只需要 Git 追蹤的檔案,可以設定 GIT_LFS_SKIP_SMUDGE=1 從 Weblate 複製,以略過 Git LFS 物件下載。

提示

預設情況下,使用者 群組的使用者與匿名使用者預設透過 存取儲存庫 和 高階使用者 角色存取公開專案。

帳務

這在 Hosted Weblate 上用於確定付費套餐、跟蹤發票和使用限制。

安裝

1. Add weblate.billing to installed apps in settings.py:

INSTALLED_APPS += ("weblate.billing",)
  1. 執行資料庫移轉,以選擇性安裝模組所需的額外資料庫結構:

weblate migrate

付費套餐建立和分配

您必須先建立計費方案,才能啟用計費功能。前往 管理 區段(扳手圖示)並開啟 工具 畫面,再進入 Django 管理介面。

在 Django 管理介面中找到 BILLING 區段,然後新增計費方案。例如,可以新增費用為零的 Free 方案。

若要將計費方案指派給既有專案,也可以在 Django 管理介面 中使用 Customer billings 選項完成。

最後,Django 管理介面 提供 發票 選項用於記錄您的客戶付款。

Externally managed payments

Billing records use local invoices to determine paid validity by default. An integration can explicitly set Billing.payment_mode to Billing.PaymentMode.EXTERNAL and supply an aware datetime in external_paid_until. In this mode, local invoices remain available as history but do not establish paid validity. An unset timestamp grants no paid validity. Free plans and trials retain their existing behavior.

The timestamp can be extended, shortened, or cleared. Normal model saves recalculate the paid status; bulk database updates bypass this calculation. Payment validity includes BILLING_GRACE_PERIOD, while check_payment_status(now=True) checks validity without that grace period. Expired external billings use the existing unpaid notification and removal schedule. Restoring validity for an active external billing cancels scheduled removal, including removal work already queued before renewal.

Changing payment mode does not change the plan, workspace, or billing lifecycle state. Switching back to Billing.PaymentMode.LOCAL uses local invoices again and ignores the retained external timestamp. These integration fields are not exposed in forms or REST APIs.

Merging billings is supported only when both use local payment mode. A merge involving an externally managed billing is rejected without changing either billing. External entitlement transfers require coordination by the integration.

Integrations must manage authentication, update ordering, and atomic entitlement updates. They must explicitly activate trials or reactivate terminated billings when appropriate, and exclude externally managed billings from local checkout and recurring payment processing. Local recurring payment inactivity assessment does not apply to externally managed billings.

使用

安裝後您可以在管理介面控制帳單。啟用了帳單模組的使用者將在他們的 使用者個人檔案 中看到新的 帳單 分頁。

超級使用者可在帳務詳細資料頁面查看最近 20 筆帳務稽核紀錄。在稽核紀錄區段選取檢視全部,即可使用分頁控制項瀏覽較早的紀錄。

此外,計費模組允許非超級使用者建立新專案及組件(請參閱 新增翻譯專案和組件)。必須符合下列條件:

  • 計費用量仍在設定限制內(超額使用會阻止建立專案或組件),而且已付款(如果方案費用不為零)

  • 使用者對計費方案涵蓋的工作空間具備 新增專案至工作空間 權限。

建立專案時,使用者可以選擇專案所屬的工作空間。在有計費功能的工作空間中建立的專案,會計入指派給該工作空間的計費方案。具備 編輯工作空間設定 權限的使用者可以檢視及支付計費方案;計費通知電子郵件會寄給這些使用者。詳細資訊請參閱 帳務。

頭像

頭像在伺服器端下載並快取,來減少對預設服務的網站的洩露。透過為其設定的電子郵件地址來取回頭像的內建支援,可以使用 ENABLE_AVATARS 來關閉。

Weblate 目前支援:

在地化 CDN

JavaScript 在地化 CDN 和 翻譯檔案 CDN 附加元件會將檔案寫入 LOCALIZE_CDN_PATH;Weblate 不會提供這些檔案。請將提供 LOCALIZE_CDN_URL 的網頁伺服器或 CDN 設定為公開且唯讀的靜態檔案主機。

請將每個已發佈的 CDN 檔案視為公開資料。URL 中附加元件專用的 UUID 不是存取控制機制。請勿對包含私人字串、尚未發行的產品文字、客戶資料、內部 URL、API 範例、儲存庫路徑、翻譯者註解,或不應公開的檔案格式中繼資料之組件啟用 CDN 附加元件。

翻譯檔案 CDN 附加元件會以 Weblate 支援的格式發佈原始翻譯檔案。瀏覽器或其他用戶端可能會將部分格式解讀為 HTML、SVG、XML、JavaScript、YAML 或特定應用程式的設定。請從與 Weblate 及翻譯使用端應用程式分離的專用網域提供 CDN。請勿與 CDN 網域共用驗證 Cookie。

建議的伺服器設定:

  • 只提供 LOCALIZE_CDN_PATH 所設定的目錄;請勿公開 Weblate 儲存庫、備份、媒體、設定或整個資料目錄。

  • 停用目錄列舉。

  • 拒絕存取 .kotlin-sdk-staging 及其所有內容。Kotlin SDK 附加元件會將此目錄用於暫存準備,不會用來發布內容。請在啟用附加元件前套用這項限制;即使 CDN 會從來源目錄複製檔案,也應先套用。

  • 使用 HTTPS 並使網路伺服器對 CDN 主機唯讀。

  • 傳送值為 nosniff 的 X-Content-Type-Options。

  • 採用保守的 MIME 類型設定。將未知翻譯格式以 text/plain 或 application/octet-stream 提供;只有 weblate.js 應以 JavaScript 提供。

  • 對於不應在瀏覽器中轉譯的原始翻譯格式,請考慮新增值為 attachment 的 Content-Disposition。

  • 只為需要從瀏覽器存取檔案的網站設定 Access-Control-Allow-Origin。

  • 設定符合更新需求的快取存留時間,並在過時翻譯必須迅速消失時清除 CDN 快取。

下列 nginx 程式碼片段只提供已設定的 CDN 目錄,並對原始翻譯檔案套用保守的預設值:

weblate/examples/weblate.nginx.cdn.conf
#
# nginx configuration for the Weblate localization CDN
#
# You will want to change:
#
# - server_name to match the host configured in LOCALIZE_CDN_URL
# - root to match LOCALIZE_CDN_PATH
# - Access-Control-Allow-Origin to the sites that need browser access
# - TLS configuration if HTTPS is not terminated before nginx
#
server {
    listen 80;
    server_name cdn.example.com;

    # LOCALIZE_CDN_PATH
    root /home/weblate/data/l10n-cdn;

    autoindex off;
    disable_symlinks on;

    location = / {
        return 404;
    }

    # Kotlin SDK preparation files must never be served.
    location ^~ /.kotlin-sdk-staging {
        return 404;
    }

    # The JavaScript localization add-on publishes this loader.
    location ~ "^/[0-9a-f]{32}/weblate\.js$" {
        try_files $uri =404;

        types {
            application/javascript js;
        }
        default_type application/javascript;

        add_header X-Content-Type-Options nosniff always;
        # add_header Access-Control-Allow-Origin "https://www.example.com" always;

        expires 1h;
    }

    # Content-addressed Android artifacts never change at the same URL.
    location ~ "^/[0-9a-f]{32}/artifacts/[0-9a-f]{64}\\.arsc$" {
        try_files $uri =404;
        types { }
        default_type application/octet-stream;
        add_header X-Content-Type-Options nosniff always;
        add_header Content-Disposition "attachment" always;
        add_header Cache-Control "public, max-age=31536000, immutable";
        # add_header Access-Control-Allow-Origin "https://www.example.com" always;
    }

    # Other CDN files are translation files. Serve them conservatively so raw
    # formats are not interpreted as active browser content.
    # Manifest JSON files also use this one-hour cache policy.
    location / {
        try_files $uri =404;

        types {
        }
        default_type text/plain;

        add_header X-Content-Type-Options nosniff always;
        add_header Content-Disposition "attachment" always;
        # add_header Access-Control-Allow-Origin "https://www.example.com" always;

        expires 1h;
    }
}

使用 GnuPG 為 Git 提交簽名

所有的提交均可由 Weblate 執行個體的 GnuPG 金鑰為其簽名。

  • 開啟 WEBLATE_GPG_IDENTITY。(Weblate 將在需要時產生一個 GnuPG 金鑰,並使用它為所有的翻譯提交簽名。)

    這個特性需要安裝 GnuPG 2.1 或更新版。

    您可以在 DATA_DIR 中找到金鑰,而公開金鑰顯示在“關於”頁面上:

    ../_images/about-gpg.webp
  • 另外您還可以將現有的金鑰匯入 Weblate 中,當呼叫 pgp 時只設定 HOME=$DATA_DIR/home。

提示

Weblate 會將關鍵材料快取很長一段時間。如果您透過 WEBLATE_GPG_IDENTITY 讓 Weblate 產生一個金鑰,接著用相同身分匯入金鑰來使用現有金鑰的話,建議清空 redis 快取來檢視此類變更的效果。

備註

在多個主機間共享 DATA_DIR 時,請遵照 https://wiki.gnupg.org/NFS 說明讓 GnuPG 簽名可靠地工作。

速率限制

在 4.6 版的變更: 速率限制不再適用於已登入的超級使用者。

Weblate 的部分操作有速率限制,各範圍分別計算。在單一範圍中,RATELIMIT_WINDOW 秒內最多允許 RATELIMIT_ATTEMPTS 次嘗試,之後該範圍會封鎖 RATELIMIT_LOCKOUT 所設定的時間。Weblate 不會因此暫時封鎖該 IP 存取整個網站。超過 TRANSLATE 或 SEARCH 等單一範圍的限制,本身不會封鎖 LOGIN 或 SECOND_FACTOR 等無關範圍。另有特定範圍的設定,例如 RATELIMIT_CONTACT_ATTEMPTS 或 RATELIMIT_TRANSLATE_ATTEMPTS。下表列出所有可用範圍。

後面的操作受到速率限制:

名稱

範圍

允許的嘗試

速率限制視窗

鎖定時間

註冊

REGISTRATION

5

300

600

傳送訊息給管理員

MESSAGE

2

300

600

登入時的密碼驗證

LOGIN

5

300

600

重設密碼

PASSWORD_RESET

5

300

600

第二要素身分驗證

SECOND_FACTOR

5

300

600

網站範圍搜尋

SEARCH

6

60

60

螢幕擷圖的圖片文字建議

OCR

6

60

60

翻譯

TRANSLATE

30

60

600

新增至詞彙表

GLOSSARY

30

60

600

開始翻譯到一種新語言

LANGUAGE

2

300

600

建立新專案

PROJECT

5

600

600

連線 GitHub 帳號

GITHUB_SETUP

100

3600

600

載入組件分支

COMPONENT_BRANCHES

30

60

60

轉譯 Markdown 預覽

MARKDOWN_PREVIEW

60

60

60

每個範圍內,速率限制的依據在使用者登入時為會話,在未登入時為 IP 地址。

若要在多個同時執行的工作程序之間嚴格落實限制,快取後端必須支援不可分割的遞增和遞減操作。使用 Valkey 或 Redis 的標準設定快取設定支援這些操作。

對於已登入使用者,Weblate 會在每個有效範圍 lockout 期間,於 活動 記錄第一個遭拒的請求,包括範圍與請求路徑。同一 lockout 期間重複拒絕不會建立額外 audit-log 項目。

如果使用者沒能在 AUTH_LOCK_ATTEMPTS 的次數內登入,那麼帳號的密碼驗證將關閉,直到完成了重置密碼過程為止。

這些設定也可以在 Docker 容器中應用,在設定名稱中新增 WEBLATE_ 字首 例如 RATELIMIT_ATTEMPTS 變成 WEBLATE_RATELIMIT_ATTEMPTS。

API 具有另外的速率限制設定,請參閱 API 速率限制。