版本控制集成

Weblate currently supports Git (with extended support for GitHub, Gerrit and Subversion) and Mercurial as version control backends.

Accessing repositories

The VCS repository you want to use has to be accessible to Weblate. With a publicly available repository you just need to enter the correct URL (for example https://github.com/WeblateOrg/weblate.git), but for private repositories or for push URLs the setup is more complex and requires authentication.

Accessing repositories from Hosted Weblate

For Hosted Weblate there is a dedicated push user registered on GitHub, Bitbucket, Codeberg and GitLab (with username weblate named Weblate push user). You need to add this user as a collaborator and give it appropriate permission to your repository (read only is okay for cloning, write is required for pushing). Depending on service and your organization settings, this happens immediately or requires confirmation from Weblate side.

The invitations on GitHub are accepted automatically within five minutes, on other services manual processing might be needed, so please be patient.

Once the weblate user is added, you can configure 源代码库 and 代码库推送 URL using SSH protocol (for example git@github.com:WeblateOrg/weblate.git).

SSH 仓库

访问私有仓库的最常用方法是基于 SSH。授权公共 Weblate SSH 密钥(请参阅 Weblate SSH 密钥)以这种方式访问上游仓库。

警告

在 GitHub 上,每个密钥只能添加到一个存储库中,请参阅 GitHub repositoriesAccessing repositories from Hosted Weblate

Weblate 还会在首次连接时存储主机密钥指纹,并且在以后进行更改时将无法连接到主机(请参阅 验证 SSH 主机密钥)。

如果需要调整,请从 Weblate 管理界面进行:

_images/ssh-keys.png

Weblate SSH 密钥

Weblate 公钥对浏览 About 页面的所有用户可见。

管理员可以在管理界面登录页面的(通过 SSH keys)生成或显示 Weblate 当前使用的公共密钥。

注解

相应的私有 SSH 密钥当前无法使用密码,因此请确保已受到良好的保护。

提示

对生成的私有 Weblate SSH 密钥进行备份。

验证 SSH 主机密钥

Weblate 会在第一次访问时自动记住 SSH 主机密钥,并记住它们以备将来使用。

如果要在连接到仓库之前对其进行验证,请在管理界面的同一部分中的 Add host key 中验证要访问的服务器的 SSH 主机密钥。输入您要访问的主机名(例如 gitlab.com),然后按 Submit。验证其指纹与您添加的服务器匹配。它们显示在确认消息中:

_images/ssh-keys-added.png

GitHub repositories

Access via SSH is possible (see SSH 仓库), but in case you need to access more than one repository, you will hit a GitHub limitation on allowed SSH key usage (since one key can be used only for one repository).

In case the 推送分支 is not set, the project is forked and changes pushed through a fork. In case it is set, changes are pushed to the upstream repository and chosen branch.

For smaller deployments, use HTTPS authentication with a personal access token and your GitHub account, see Creating an access token for command-line use.

For bigger setups, it is usually better to create a dedicated user for Weblate, assign it the public SSH key generated in Weblate (see Weblate SSH 密钥) and grant it access to all the repositories you want to translate. This approach is also used for Hosted Weblate, there is dedicated weblate user for that.

Weblate internal URLs

To share one repository between different components you can use a special URL like weblate://project/component. This way, the component will share the VCS repository configuration with the referenced component (project/component in the example).

Weblate automatically adjusts repository URL when creating component when it finds component with matching repository setup. You can override this in last step of component configuration.

Reasons to use this:

  • Saves disk space on the server, the repository is stored just once.

  • Makes the updates faster, only one repository is updated.

  • There is just single exported repository with Weblate translations (see Git exporter).

  • Some addons can operate on more components sharing single repository, for example 压缩 Git 提交.

HTTPS repositories

To access protected HTTPS repositories, include the username and password in the URL. Don’t worry, Weblate will strip this info when the URL is shown to users (if even allowed to see the repository URL at all).

For example the GitHub URL with authentication added might look like: https://user:your_access_token@github.com/WeblateOrg/weblate.git.

注解

If you username or password contains special characters, those have to be URL encoded, for example https://user%40example.com:%24password%23@bitbucket.org/….

Using proxy

If you need to access HTTP/HTTPS VCS repositories using a proxy server, configure the VCS to use it.

This can be done using the http_proxy, https_proxy, and all_proxy environment variables, (as described in the cURL documentation) or by enforcing it in the VCS configuration, for example:

git config --global http.proxy http://user:password@proxy.example.com:80

注解

The proxy configuration needs to be done under user running Weblate (see also Filesystem permissions) and with HOME=$DATA_DIR/home (see DATA_DIR), otherwise Git executed by Weblate will not use it.

Git

参见

See Accessing repositories for info on how to access different kinds of repositories.

Git 强制推送

This behaves exactly like Git itself, the only difference being that it always force pushes. This is intended only in the case of using a separate repository for translations.

警告

Use with caution, as this easily leads to lost commits in your upstream repository.

Customizing Git configuration

Weblate invokes all VCS commands with HOME=$DATA_DIR/home (see DATA_DIR), therefore editing the user configuration needs to be done in DATA_DIR/home/.git.

Git remote helpers

You can also use Git remote helpers for additionally supporting other version control systems, but be prepared to debug problems this may lead to.

At this time, helpers for Bazaar and Mercurial are available within separate repositories on GitHub: git-remote-hg and git-remote-bzr. Download them manually and put somewhere in your search path (for example ~/bin). Make sure you have the corresponding version control systems installed.

Once you have these installed, such remotes can be used to specify a repository in Weblate.

To clone the gnuhello project from Launchpad using Bazaar:

bzr::lp:gnuhello

For the hello repository from selenic.com using Mercurial:

hg::http://selenic.com/repo/hello

警告

The inconvenience of using Git remote helpers is for example with Mercurial, the remote helper sometimes creates a new tip when pushing changes back.

GitHub

2.3 新版功能.

This adds a thin layer atop Git using the hub tool to allow pushing translation changes as pull requests, instead of pushing directly to the repository.

Git pushes changes directly to a repository, while GitHub creates pull requests. The latter is not needed for merely accessing Git repositories.

Pushing changes to GitHub as pull requests

If not wanting to push translations to a GitHub repository, they can be sent as either one or many pull requests instead.

参见

GITHUB_USERNAME, Setting up hub for configuration instructions

Setting up hub

Pushing changes to GitHub as pull requests requires a configured hub installation on your server. Follow the installation instructions at https://hub.github.com/ use hub to finish the configuration, for example:

# Use DATA_DIR as configured in Weblate settings.py, it is /app/data in the Docker
HOME=${DATA_DIR}/home hub clone octocat/Spoon-Knife

The hub will ask you for your GitHub credentials, retrieve a token and store it in ~/.config/hub. This file has to be readable by the user running Weblate.

注解

Use the username you configured hub with, as GITHUB_USERNAME (WEBLATE_GITHUB_USERNAME for the Docker image).

GitLab

3.9 新版功能.

This just adds a thin layer atop Git using the lab tool to allow pushing translation changes as merge requests instead of pushing directly to the repository.

There is no need to use this access Git repositories, ordinary Git works the same, the only difference is how pushing to a repository is handled. With Git changes are pushed directly to the repository, while GitLab creates merge request.

Pushing changes to GitLab as merge requests

If not wanting to push translations to a GitLab repository, they can be sent as either one or many merge requests instead.

Configure the lab command line tool and set GITLAB_USERNAME for this to work.

参见

GITLAB_USERNAME, Setting up Lab for configuration instructions

Setting up Lab

Pushing changes to GitLab as merge requests requires a configured lab installation on your server. Follow the installation instructions at lab and run it without any arguments to finish the configuration, for example:

# Use DATA_DIR as configured in Weblate settings.py, it is /app/data in the Docker
$ HOME=${DATA_DIR}/home lab
Enter GitLab host (default: https://gitlab.com):
Create a token here: https://gitlab.com/profile/personal_access_tokens
Enter default GitLab token (scope: api):
(Config is saved to ~/.config/lab.hcl)

The lab will ask you for your GitLab access token, retrieve it and store it in ~/.config/lab.hcl. The file has to be readable by the user running Weblate.

注解

Use the username you configured lab with, as GITLAB_USERNAME (WEBLATE_GITLAB_USERNAME for the Docker image).

Gerrit

2.2 新版功能.

Adds a thin layer atop Git using the git-review tool to allow pushing translation changes as Gerrit review requests, instead of pushing a directory to the repository.

The Gerrit documentation has the details on the configuration necessary to set up such repositories.

Mercurial

2.1 新版功能.

Mercurial is another VCS you can use directly in Weblate.

注解

It should work with any Mercurial version, but there are sometimes incompatible changes to the command-line interface which breaks Weblate integration.

参见

See Accessing repositories for info on how to access different kinds of repositories.

Subversion

2.8 新版功能.

Weblate uses git-svn to interact with subversion repositories. It is a Perl script that lets subversion be used by a Git client, enabling users to maintain a full clone of the internal repository and commit locally.

注解

Weblate tries to detect Subversion repository layout automatically - it supports both direct URLs for branch or repositories with standard layout (branches/, tags/ and trunk/). More info about this is to be foud in the git-svn documentation. If your repository does not have a standard layout and you encounter errors, try including the branch name in the repository URL and leaving branch empty.

在 2.19 版更改: Before this, there was only support for standard layout repositories.

Subversion credentials

Weblate expects you to have accepted the certificate up-front and if needed, your credentials. It will look to insert them into the DATA_DIR directory. Accept the certificate by using svn once with the $HOME environment variable set to the DATA_DIR:

# Use DATA_DIR as configured in Weblate settings.py, it is /app/data in the Docker
HOME=${DATA_DIR}/home svn co https://svn.example.com/example

参见

DATA_DIR

Local files

3.8 新版功能.

Weblate can also operate without a remote VCS. The initial translations are imported by uploading them. Later you can replace individual files by file upload, or add translation strings directly from Weblate (currently available only for monolingual translations).

In the background Weblate creates a Git repository for you and all changes are tracked in. In case you later decide to use a VCS to store the translations, you already have a repository within Weblate can base your integration on.