升級 Weblate

Docker 鏡像升級

官方 Docker 鏡像(參見 使用 Docker 安裝 )集成了所有 Weblate 升級步驟。除了拉取最新版本外,通常不需要手動步驟。

通用的升級說明

在升級前,請檢查當前的 軟件要求,因為他們可能被更改。一旦所有的要求被安裝或升級,請調整您的 settings.py,來匹配配置中的更改(正確的值請諮詢 settings_example.py)。

在升級前總是查看 版本特定說明。在您跳過一些版本的情況下,請遵從在升級中您跳過的所有版本的指示。有時最好升級到一些中間版本,來確保平滑遷移。跨多發行版本的升級應該可以工作,但還沒有像單一版本升級一樣測試過。

備註

推薦在升級前執行全資料庫備份,使您可以在升級失敗的情況下回滾資料庫,請參見 備份和移動 Weblate

  1. 停止 WSGI 和 Celery 進程。升級可能執行資料庫的不兼容更改,因此在升級中避免舊的進程運行總是安全的。

  2. 升級 Weblate 代碼。

    對於 pip 安裝,可以通過後面的來實現:

    pip install -U "Weblate[all]==version"
    

    或者,如果您只想獲取最新發佈的版本:

    pip install -U "Weblate[all]"
    

    If you don’t want to install all of the optional dependencies do:

    pip install -U Weblate
    

    通過 Git 核實,您需要取回新的原始碼併升級您的安裝:

    cd weblate-src
    git pull
    # Update Weblate inside your virtualenv
    . ~/weblate-env/bin/pip install -e .
    # Install dependencies directly when not using virtualenv
    pip install --upgrade -r requirements.txt
    # Install optional dependencies directly when not using virtualenv
    pip install --upgrade -r requirements-optional.txt
    
  3. New Weblate release might have new 可選依賴性, please check if they cover features you want.

  4. 升級配置文件,所需的步驟請參考 settings_example.py版本特定說明

  5. Upgrade database structure:

    weblate migrate --noinput
    
  6. 收集升級的靜態文件(請參見 服務器運行中靜態檔案服務):

    weblate collectstatic --noinput --clear
    
  7. 壓縮 JavaScript 和 CSS 文件(可選步驟,請參見 壓縮客戶端素材 ):

    weblate compress
    
  8. 如果您運行來自 Git 的版本,每次升級時還應該重新生成 locale 文件。可以通過調用後面的來進行:

    weblate compilemessages
    
  9. 驗證您的設置合理(還請參見 生產設置):

    weblate check --deploy
    
  10. Restart Celery worker (see 使用 Celery 的後台任務).

版本特定說明

Upgrade from 2.x

如果從 2.x 發佈版本升級,首先總是升級到 3.0.1,然後繼續在 3.x 系列中升級。跳過這步的升級不被支持,並且會中斷。

Upgrade from 3.x

如果從 3.x 發佈版本升級,首先總是升級到 4.0.4 或 4.1.1,然後繼續在 4.x 系列中升級。跳過這步的升級不被支持,並且會中斷。

也參考

`Weblate 4.0 文件中關於從3.11 升級到4.0 <https://docs.weblate.org/en/weblate-4.0.4/admin/upgrade.html#upgrade-from-3-11-to-4-0> `_

從 4.0 升級到 4.1

請按照 通用的升級說明 來執行升級。

显著的配置与依赖性更改:

  • settings_example.py 中有几项更改,最显著的是中间件的更改,请由此调整您的设置。

  • 有幾個新的文件格式,在修改 WEBLATE_FORMATS 的情況下,您會想要將他們包括進來。

  • 有幾個新的質量檢查,在修改 CHECK_LIST 的情況下,您會想要將他們包括進來。

  • DEFAULT_THROTTLE_CLASSES 設置中有幾項更改,來允許在 API 中報告速率限制。

  • 有幾個新的且更新的要求。

  • INSTALLED_APPS 中有一些更改。

  • The MT_DEEPL_API_VERSION setting has been removed in Version 4.7. The DeepL machine translation now uses the new MT_DEEPL_API_URL instead. You might need to adjust MT_DEEPL_API_URL to match your subscription.

從 4.1 升級到 4.2

請按照 通用的升級說明 來執行升級。

显著的配置与依赖性更改:

  • 從 3.x 發佈版本升級不再支持,請首先升級到 4.0 或 4.1。

  • 有幾個新的且更新的要求。

  • settings_example.py 中有几项更改,最显著的是新中间件和更改的应用订购。

  • 基於 JSON 格式的密鑰是不再包括前導的點。在資料庫遷移過程中調整字串,但在您依賴於導出或 API 中的密鑰時,外部組件會需要調整。

  • Celery 配置更改,不再使用 memory 隊列。請調整您的啟動腳本和 CELERY_TASK_ROUTES 設置。

  • 現在在設置中配置 Weblate 域,請參見 SITE_DOMAIN`(或 :envvar:`WEBLATE_SITE_DOMAIN)。在運行 Weblate 前您將不得不配置它。

  • 使用者資料庫上的使用者名和電子郵件字段現在應該不因為大小寫敏感而不同。它之前錯誤地沒有被 PostgreSQL 強制。

從 4.2 升級到 4.3

請按照 通用的升級說明 來執行升級。

显著的配置与依赖性更改:

  • 在質量檢查中有一些更改,在您調整 CHECK_LIST 的情況下會想將他們包括進來。

  • 源語言屬性從項目移動到 API 中揭露的組件。在使用時您會需要更新 Weblate 客戶端

  • 根據翻譯的字串數量,資料庫遷移到 4.3 會花費很長時間(期望每 10 萬個字串的遷移時間大約為 1 小時)。

  • INSTALLED_APPS 中有一些更改。

  • 有個新的設置 SESSION_COOKIE_AGE_AUTHENTICATED,補充了 SESSION_COOKIE_AGE

  • 在使用 hub`或 :command:`lab`與 GitHub 或GitLab 集成的情況下,需要重新配置它,請參見 :setting:`GITHUB_CREDENTIALSGITLAB_CREDENTIALS

在 4.3.1 版本變更:

  • Celery 配置更改,加入了 memory 隊列。請調整您的啟動腳本和 CELERY_TASK_ROUTES 設置。

在 4.3.2 版本變更:

  • 附加元件的``post_update``方法現在加入額外的``skip_push``參數。

從 4.3 升級到 4.4

請按照 通用的升級說明 來執行升級。

显著的配置与依赖性更改:

  • INSTALLED_APPS 中有一處更改, 必須將 weblate.configuration 添加在那裡。

  • 現在需要 Django 3.1。

  • 在使用 MySQL 或 MariaDB 的情況下,需要的最低版本提高了,請參見 MySQL 與 MariaDB

在 4.4.1 版本變更:

  • 單語 gettext now uses both msgid and msgctxt when present. This will change identification of translation strings in such files breaking links to Weblate extended data such as screenshots or review states. Please make sure you commit pending changes in such files prior upgrading and it is recommended to force loading of affected component using loadpo.

  • 增加了 translate-toolkit 的最低需求版本,來處理幾個文件格式問題。

從 4.4 升級到 4.5

請按照 通用的升級說明 來執行升級。

显著的配置与依赖性更改:

  • 如果您有大詞彙表,遷移可能需要相當長的時間。

  • Glossaries are now stored as regular components.

  • 刪除詞彙表API,使用定期翻譯API來訪問詞彙表。

  • :setting:`django:INSTALLED_APPS`中有一處更改, - ``weblate.metrics``應被添加。

在 4.5.1 版本變更:

  • “Pyahocorasick”模塊有一個新的依賴。

從 4.5 升級到了 4.6

請按照 通用的升級說明 來執行升級。

显著的配置与依赖性更改:

  • 有幾個新的文件格式,在修改 WEBLATE_FORMATS 的情況下,您會想要將他們包括進來。

  • 創建組件的 API 現在自動使用 Weblate internal URLs,見:http:post:/api/projects/(string:project)/components/

  • 依賴關係和:設置:`django:password_hashers`更喜歡argon2以獲取密碼散列。

從 4.6 升級到了 4.7

請按照 通用的升級說明 來執行升級。

显著的配置与依赖性更改:

  • settings_example.py 中有几项更改,最显著的是中间件的更改(MIDDLEWARE),请由此调整您的设置。

  • The DeepL machine translation now has a generic MT_DEEPL_API_URL setting to adapt to different subscription models more flexibly. The MT_DEEPL_API_VERSION setting is no longer used.

  • Django 3.2 is now required.

Upgrade from 4.7 to 4.8

請按照 通用的升級說明 來執行升級。

在這次的發佈沒有額外需要升級的步驟。

Upgrade from 4.8 to 4.9

請按照 通用的升級說明 來執行升級。

  • There is a change in storing metrics, the upgrade can take long time on larger sites.

Upgrade from 4.9 to 4.10

請按照 通用的升級說明 來執行升級。

  • 這是會影響每一專案的改動,這個改動會在數千個專案上,並在網站上花點時間執行。

  • Django 4.0 has made some incompatible changes, see Backwards incompatible changes in 4.0. Weblate still supports Django 3.2 for now, in case any of these are problematic. Most notable changes which might affect Weblate:

    • Dropped support for PostgreSQL 9.6, Django 4.0 supports PostgreSQL 10 and higher.

    • Format of CSRF_TRUSTED_ORIGINS was changed.

  • The Docker container now uses Django 4.0, see above for changes.

Upgrade from 4.10 to 4.11

請按照 通用的升級說明 來執行升級。

  • Weblate now requires Python 3.7 or newer.

  • The implementation of 管理單一專案的存取控制 has changed, removing the project prefix from the group names. This affects API users.

  • Weblate now uses charset-normalizer instead of chardet module for character set detection.

  • Changed in 4.11.1: There is a change in REST_FRAMEWORK setting (removal of one of the backends in DEFAULT_AUTHENTICATION_CLASSES).

Upgrade from 4.11 to 4.12

請按照 通用的升級說明 來執行升級。

  • There are no special steps required.

Upgrade from 4.12 to 4.13

請按照 通用的升級說明 來執行升級。

  • The 語言定義 are now automatically updated on upgrade, use UPDATE_LANGUAGES to disable that.

  • Handling of context and location has been changed for Windows RC files, HTML files, IDML Format, and 文字檔 file formats. In most cases the context is now shown as location.

  • The machine translation services are now configured using the user interface, settings from the configuration file will be imported during the database migration.

Upgrade from 4.13 to 4.14

請按照 通用的升級說明 來執行升級。

  • The Java formatting checks now match GNU gettext flags. The flags set in Weblate will be automatically migrated, but third-party scripts will need to use java-printf-format instead of java-format and java-format instead of java-messageformat.

  • The jellyfish dependency has been replaced by rapidfuzz.

  • Changed in 4.14.2: Deprecated insecure configuration of VCS service API keys via _TOKEN/_USERNAME configuration instead of _CREDENTIALS list. In Docker, please add matching _HOST directive. For example see WEBLATE_GITHUB_HOST and GITHUB_CREDENTIALS.

Upgrade from 4.14 to 4.15

請按照 通用的升級說明 來執行升級。

  • Weblate now requires btree_gin extension in PostgreSQL. The migration process will install it if it has sufficient privileges. See 建立 PostgreSQL資料庫 for manual setup.

  • The Docker image no longer enables debug mode by default. In case you want it, enable it in the environment using WEBLATE_DEBUG.

  • The database migration make take hours on larger instances due to recreating some of the indexes.

  • Changed in 4.15.1: The default value for DEFAULT_PAGINATION_CLASS in rest framework settings was changed.

Upgrade from 4.15 to 4.16

請按照 通用的升級說明 來執行升級。

  • Celery beat is now storing the tasks schedule in the database, CELERY_BEAT_SCHEDULER and INSTALLED_APPS need to be changed for that.

  • The deprecated VCS setting for credentials is no longer supported, see Upgrade from 4.13 to 4.14.

  • Upgrade of django-crispy-forms requires changes in INSTALLED_APPS.

  • Integration of django-cors-headers requires changes in INSTALLED_APPS and MIDDLEWARE.

從 Python 2 升級到 Python 3

Weblate 不再支持早於 3.6 版本的 Python。確保仍運行在較早版本的情況下,請先在現有版本上執行搬遷到 Python 3,並在後面進行升級。請參見 Upgrading from Python 2 to Python 3 in the Weblate 3.11.1 documentation

從其它資料庫遷移到 PostgreSQL

If you are running Weblate on other dabatase than PostgreSQL, you should consider migrating to PostgreSQL as Weblate performs best with it. The following steps will guide you in migrating your data between the databases. Please remember to stop both web and Celery servers prior to the migration, otherwise you might end up with inconsistent data.

建立 PostgreSQL資料庫

在另一個單獨的資料庫中運行 Weblate,並將使用者賬戶分開通常是個好方法:

# If PostgreSQL was not installed before, set the main password
sudo -u postgres psql postgres -c "\password postgres"

# Create a database user called "weblate"
sudo -u postgres createuser -D -P weblate

# Create the database "weblate" owned by "weblate"
sudo -u postgres createdb -E UTF8 -O weblate weblate

使用 Django JSON 轉儲來遷移

最簡單的遷移方法是使用 Django JSON 轉儲。這對於較小的安裝工作得很好。在更大的網站,您會想要使用 pgloader 代替,請參見 使用 pgloader 遷移到 PostgreSQL

  1. 添加 PostgreSQL 作為到 :file:`settings.py`的另外的資料庫連接:

DATABASES = {
    "default": {
        # Database engine
        "ENGINE": "django.db.backends.mysql",
        # Database name
        "NAME": "weblate",
        # Database user
        "USER": "weblate",
        # Database password
        "PASSWORD": "password",
        # Set to empty string for localhost
        "HOST": "database.example.com",
        # Set to empty string for default
        "PORT": "",
        # Additional database options
        "OPTIONS": {
            # In case of using an older MySQL server, which has MyISAM as a default storage
            # 'init_command': 'SET storage_engine=INNODB',
            # Uncomment for MySQL older than 5.7:
            # 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
            # If your server supports it, see the Unicode issues above
            "charset": "utf8mb4",
            # Change connection timeout in case you get MySQL gone away error:
            "connect_timeout": 28800,
        },
    },
    "postgresql": {
        # Database engine
        "ENGINE": "django.db.backends.postgresql",
        # Database name
        "NAME": "weblate",
        # Database user
        "USER": "weblate",
        # Database password
        "PASSWORD": "password",
        # Set to empty string for localhost
        "HOST": "database.example.com",
        # Set to empty string for default
        "PORT": "",
    },
}
  1. 運行遷移,並將任何插入到表格中的數據 drop 掉:

weblate migrate --database=postgresql
weblate sqlflush --database=postgresql | weblate dbshell --database=postgresql
  1. 將遺留資料庫進行轉儲,並導入 PostgreSQL

weblate dumpdata --all --output weblate.json
weblate loaddata weblate.json --database=postgresql
  1. 調整 DATABASES 而只使用 PostgreSQL 資料庫作為預設,將遺留連接刪除掉。

現在 Weblate 應該準備好從 PostgreSQL 資料庫運行了。

使用 pgloader 遷移到 PostgreSQL

pgloader 是通用遷移工具,將數據遷移到 PostgreSQL。您可以使用它來遷移 Weblate 資料庫。

  1. 調整 settings.py 文件而將 PostgreSQL 用作資料庫。

  2. 遷移 PostgreSQL 中的模式:

    weblate migrate
    weblate sqlflush | weblate dbshell
    
  3. 運行 pgloader 來轉移數據。後面的腳本可以用於遷移資料庫,但您會想要學習更多關於 pgloader 的知識,來理解它做什麼以及調整它來匹配您的設置:

    LOAD DATABASE
         FROM      mysql://weblate:password@localhost/weblate
         INTO postgresql://weblate:password@localhost/weblate
    
    WITH include no drop, truncate, create no tables, create no indexes, no foreign keys, disable triggers, reset sequences, data only
    
    ALTER SCHEMA 'weblate' RENAME TO 'public'
    ;
    

Migrating from Pootle

因為 Weblate 開始編寫出來替換 Pootle,所以支持從 Pootle 遷移使用者賬戶。您可以將 Pootle 的使用者轉儲,並使用 importusers 將他們導入。