開始為 Weblate 貢獻代碼

要理解 Weblate 來源碼,請瀏覽 Weblate 來源碼Weblate 前端Weblate 內部

Starting with the codebase

要讓您自己熟悉 Weblate 代碼庫,那麼請查看標記為 good first issue 的那些 bug。

You are welcome to start working on these issues without asking. Just announce that in the issue, so that it's clear that somebody is working on that issue.

本地執行 Weblate

The most comfortable approach to get started with Weblate development is to follow 從來源碼中安裝. It will get you a Python environment with editable Weblate sources.

  1. 複製 Weblate 來源碼:

    git clone https://github.com/WeblateOrg/weblate.git
    cd weblate
    
  2. Create a Python environment:

    uv venv .venv
    source .venv/bin/activate
    
  3. Install Weblate (for this you need some system dependencies, see 從來源碼中安裝) and all dependencies useful for development:

    uv pip install -e '.[dev]'
    
  1. Start a development server:

    weblate runserver
    
  2. 取決於組態,您也許想啟動 Celery workers:

    ./weblate/examples/celery start
    
  3. 要執行測試 (更多細節見 Local testing of Weblate):

    . scripts/test-database.sh
    pytest
    

在 Docker 中本地執行 Weblate

If you have Docker and the docker-compose-plugin installed, you need an additional tool called jq which you can install through your favorite package manager. Then, you can spin up the development environment by simply running:

./rundev.sh

它將新建 Docker 影響並啟動它。 Weblate 執行在 <http://127.0.0.1:8080/> 上,並且您可以以 admin 為使用者名, admin 為密碼來登入。新的安裝是空的,所以您會想要以 新增翻譯項目和組件 來繼續。

Weblate is configured to use maildev container as a e-mail server. The delivered e-mails can be seen at <http://127.0.0.1:1080/>.

The Dockerfile and docker-compose.yml for this are located in the dev-docker directory. For easier access to the database during development, the container running PostgreSQL is exposed on port 5433.

The script also accepts some parameters, to execute tests, run it with the test parameter and then specify any test parameters, for example running only tests in the weblate.machine module:

./rundev.sh test --exitfirst weblate/machine

備註

小心在執行測試前您的 Docker 容易活動並執行。您可以通過執行 docker ps 命令來檢查。

To display the logs:

./rundev.sh logs

為了停止後台容器,執行:

./rundev.sh stop

執行沒有任何參數的腳本將重建 Docker 容器並重啟動它。

警告

This container is not suitable for production use. Security is sacrificed to make the development easier.

Bootstrapping your devel instance

You might want to use import_demo to create demo translations and createadmin to make an admin user.

If you have 帳單 installed as well, you can use billing_demo to create a demo billing project.

使用 PyCharm 為 Weblate 編寫代碼

PyCharm 是 Python 的著名 IDE,這裡有一些幫助您在其中建立您的 Weblate 項目的指南。

考慮到您剛剛將 GitHub 儲存庫複製到一個資料夾中,只需使用 PyCharm 開啟它。一旦 IDE 開啟,第一步要做的是指定您想要使用的直譯器:

../_images/pycharm-1.png

You can either choose to let PyCharm create the Python environment for you, or select an already existing one:

../_images/pycharm-2.png

Don't forget to install the dependencies once the interpreter is set: Either through the console (the console from the IDE will directly use your Python environment by default), or through the interface when you get a warning about missing dependencies.

第二步是設定正確的資訊來在 PyCharm 中原生使用 Django:理念是能夠立即觸發 IDE 中的單元測試。為此,您需要指定該 Django 項目的根路徑及其設定路徑:

../_images/pycharm-3.png

Be careful, the Django project root is the actual root of the repository, not the Weblate sub-directory. About the settings, you could use the weblate/settings_test.py from the repository, but you could create your own setting and set it there.

最後一步是執行伺服器,並將斷點放置在代碼中而能夠調試它。這通過新建新的 Django Server 組態來完成:

../_images/pycharm-4.png ../_images/pycharm-5.png

提示

小心被稱為 No reload 的屬性:如果您修改文件,它會阻止伺服器被實時重新載入。這允許保留現有的調試器斷點,而它們通常會在重新載入伺服器時被丟棄。