在 macOS 上安装

硬件要求

Weblate should run on any contemporary hardware without problems, the following is the minimal configuration required to run Weblate on a single host (Weblate, database and web server):

  • 3 GB 的内存

  • 2 个 CPU 核心

  • 1 GB 的存储空间

备注

安装 Weblate 的实际要求会因其中管理的翻译规模而大不相同。

Memory usage

The more memory the better - it is used for caching on all levels (file system, database and Weblate). For hundreds of translation components, at least 4 GB of RAM is recommended.

提示

对于内存低于推荐值的系统,建议使用 单进程 Celery 设置

CPU usage

Many concurrent users increase the amount of needed CPU cores.

Storage usage

The typical database storage usage is around 300 MB per 1 million hosted words.

Storage space needed for cloned repositories varies, but Weblate tries to keep their size minimal by doing shallow clones.

Nodes

For small and medium-sized sites (millions of hosted words), all Weblate components (see 架构概览) can be run on a single node.

When you grow to hundreds of millions of hosted words, it is recommended to have a dedicated node for database (see Weblate 的数据库设置).

安装

系统要求

安装构建 Python 模块所需的依赖项(请参见 软件要求):

brew install python pango cairo gobject-introspection glib libyaml pkg-config zstd xxhash libxmlsec1
pip install virtualenv

可选地安装生产服务器运行所需要的软件,参见 运行服务器Weblate 的数据库设置使用 Celery 的后台任务。根据于您的安装所占的空间,您会想要在特定的服务器上运行这些部件。

本地安装的使用说明:

# Web server option 1: NGINX and uWSGI
brew install nginx uwsgi

# Web server option 2: Apache with ``mod_wsgi``
brew install httpd

# Caching backend: Redis
brew install redis

# Database server: PostgreSQL
brew install postgresql

# Gettext for the msgmerge add-on
brew install gettext

Python 模块

提示

我们使用 virtualenv 将 Weblate 安装在一个与您的系统分离的环境中。如果您不熟悉它,查阅 virtualenv User Guide

  1. 为 Weblate 新建 virtualenv:

    virtualenv ~/weblate-env
    
  2. 为 Weblate 激活 virtualevn :

    . ~/weblate-env/bin/activate
    
  3. 安装包含所有可选依赖项的 Weblate:

    # Install Weblate with all optional dependencies
    pip install "Weblate[all]"
    

    请查看 Python 依赖项 以了解对可选依赖关系的微调情况。

    备注

    在某些 Linux 发行版上,运行 Weblate 会出现 libffi 错误:

    ffi_prep_closure(): bad user_data (it seems that the version of the libffi library seen at runtime is different from the 'ffi.h' file seen at compile-time)
    

    这是由于通过PyPI发布的二进制包与该发行版不兼容造成的。为了解决这个问题,你需要在你的系统上重建该软件包:

    pip install --force-reinstall --no-binary :all: cffi
    

配置 Weblate

备注

以下内容假设 Weblate 使用的 virtualenv 已经激活(可以通过 . ~/weblate-env/bin/activate 来实现)。如果没有,请指定 weblate 命令的完全路径为 ~/weblate-env/bin/weblate

  1. 将文件 ~/weblate-env/lib/python3.9/site-packages/weblate/settings_example.py 复制为 ~/weblate-env/lib/python3.9/site-packages/weblate/settings.py

  2. 将新的 settings.py 文件中的值调整为您所需要的。您至少需要提供数据库凭据和Django密钥,但在生产安装中需要做更多的更改,参见: 调整配置

  3. 为 Weblate 新建数据库及其结构(示例中的设置使用 PostgreSQL,已经准备好的生产设置请查看 Weblate 的数据库设置 ):

    weblate migrate
    

    参见

    migrate

  4. 创建管理员用户账户 admin,生成账户密码并将密码复制到剪贴板;记得保存密码供日后使用:

    weblate createadmin
    

    提示

    如果你之前丢失了 admin 密码,可以使用以下命令生成一个新的 admin 密码:

    weblate createadmin --update
    

    参见

    createadmin

  5. 为你的收集 Web 服务器用的静态文件 (请参见 运行服务器为静态文件提供服务 ):

    weblate collectstatic
    
  6. 压缩 JavaScript 和 CSS 文件(可选步骤,请参见 压缩客户端资源 ):

    weblate compress
    
  7. 启动 Celery 工作进程。这对开发来说是不必要的,但强烈建议在其他场景这样做。更多信息请参见 使用 Celery 的后台任务

    ~/weblate-env/lib/python3.9/site-packages/weblate/examples/celery start
    
  8. 启动开发服务器( :ref:`server`详细说明生产设置):

    weblate runserver
    

安装后

配置,您的 Weblate 服务器现在运行了,您可以使用它来启动。

  • 您可以在 http://localhost:8000/ 访问 Weblate。

  • 使用安装期间获得的管理凭据登录或注册新用户。

  • 现在,您可以在 Weblate virtualenv 活动时使用 weblate 命令来运行 Weblate 命令。

  • 您可以使用 Ctrl+C 来停止测试的服务器。

  • 要检查你安装的潜在问题,有两个途径。一是 /manage/performance/ URL (参见 管理性能),二是使用命令:weblate check –deploy,参见 生产设置

添加翻译

  1. 打开管理界面( http://localhost:8000/create/project/ ),并新建您想要翻译的项目。更多细节请参见 项目配置

    这里所有需要您指定的只是项目名称及其网站。

  2. 新建一个部件,该部件是要翻译的实际对象——它指向版本控制系统仓库,并选择要翻译的文件。更多详细信息请参见 部件配置

    此处的重要字段为:部件名称源代码仓库 及用于寻找可翻译文件的 文件掩码。Weblate 支持多种格式,包括 GNU gettext PO (Portable Object)Android 字符串资源苹果 iOS 字符串Java 属性Stringsdict 格式Fluent 格式,更多细节见 支持的文件格式

  3. 一旦完成上面的工作(根据您 VCS 仓库的大小,以及需要翻译的信息数量,这可能是个漫长的过程),您就可以开始翻译了。