# 从源码安装

1. 安装 Weblate 前，请先遵照用于您系统的安装说明：
   * [在 Debian 和 Ubuntu 上安装](https://docs.weblate.org/zh-cn/latest/admin/install/venv-debian.md)
   * [在 SUSE 和 openSUSE 上安装](https://docs.weblate.org/zh-cn/latest/admin/install/venv-suse.md)
   * [在 Redhat、Fedora 和 CentOS 上安装](https://docs.weblate.org/zh-cn/latest/admin/install/venv-redhat.md)
2. 使用 Git 获取最新的 Weblate 源码（或下载 tarball 包并将其解压）：
   ```sh
   git clone https://github.com/WeblateOrg/weblate.git weblate-src
   ```

   另外，您可以使用发布的压缩包。您可以从我们的网站 <[https://weblate.org/](https://weblate.org/)> 下载。这些下载是经过加密签名的，请参见 [验证发布工件](https://docs.weblate.org/zh-cn/latest/security/release-artifacts.md#verify)。
3. 将当前的 Weblate 代码安装到 Python 环境中：
   ```sh
   . ~/weblate-env/bin/activate
   uv pip install -e 'weblate-src[all]'
   ```

   如果您打算直接从源码检出目录（Source checkout）运行测试套件，请按照 [Weblate 的本地测试](https://docs.weblate.org/zh-cn/latest/contributing/tests.md#local-tests) 中的说明安装开发依赖。
4. 将 `weblate/settings_example.py` 复制为 `weblate/settings.py`。
5. 将新的 `settings.py` 文件中的值调整为您所需要的。您至少需要提供数据库凭证和 Django 密钥，但在生产安装中需要做更多的更改，参见：[调整配置](https://docs.weblate.org/zh-cn/latest/admin/install.md#configuration)。
6. 新建 Weblate 使用的数据库，参见 [Weblate 的数据库设置](https://docs.weblate.org/zh-cn/latest/admin/install.md#database-setup)。
7. 构建 Django 表、静态文件和初始数据（参见 [填满数据库](https://docs.weblate.org/zh-cn/latest/admin/install.md#tables-setup) 和 [为静态文件提供服务](https://docs.weblate.org/zh-cn/latest/admin/install.md#static-files)）：
   ```sh
   weblate migrate
   weblate collectstatic
   ```

   #### NOTE
   无论任何时候更新仓库时，都应该重复这一步骤。

<a id="distribution-packaging"></a>

## 为发行版打包 Weblate

`pyproject.toml` 中的依赖版本定义了 Weblate 项目经过测试的运行时环境。在从 PyPI 安装以及进行 Weblate 发布流程时，这些版本限制被刻意保持严格，因为 Weblate 无法验证更宽泛版本范围所涵盖的每一种依赖组合。

发行版软件包可以使用发行版软件集中的版本来替换这些 Python 软件包。此时，请针对打包后的依赖集运行 Weblate 的测试套件，并以测试是否通过作为发行版软件包的兼容性依据。

请确保与 Weblate 紧密耦合的配套软件包与 Weblate 发行版本保持同步：

* [weblate-fonts](https://pypi.org/project/weblate-fonts/)
* [weblate_schemas](https://pypi.org/project/weblate_schemas/)
* [weblate-language-data](https://pypi.org/project/weblate-language-data/)
* [translation-finder](https://pypi.org/project/translation-finder/)
* [translate-toolkit](https://pypi.org/project/translate-toolkit/)

相较于替换其他 Python 依赖的版本，这些软件包的版本不匹配更有可能在运行时或测试期间引发故障。

#### SEE ALSO
测试环境搭建和配置请参阅 [Weblate 的本地测试](https://docs.weblate.org/zh-cn/latest/contributing/tests.md#local-tests)，Weblate 的发布周期请参阅 [发行周期](https://docs.weblate.org/zh-cn/latest/security/releases.md#release-cycle)。
