GitLab 集成(基于文件)

GitLab 集成允许您在 GitLab 仓库和 Crowdin 企业版项目之间同步文件。

注意:您需要在 Crowdin 账户中安装 GitLab 集成,然后才能进行设置和使用。

有两种可能的 GitLab 集成模式可供选择:

  • 源文件和翻译文件模式 – 在 GitLab 仓库和 Crowdin 企业版项目之间同步源文件和翻译文件。
  • 目标文件包模式 – 以所选格式从 Crowdin 企业版项目生成翻译文件并将其推送到您的 GitLab 仓库。 在此模式下,集成会推送翻译文件,但不会同步仓库中的源。 如果您在 Crowdin 企业版项目中执行源文本审阅并希望将更新的源文本添加到您的仓库中,您可以将源语言添加为目标语言,该语言将与翻译一起推送到您的仓库中。

在上述任一模式下,所有已翻译和批准的文件都将作为合并请求自动推送到 GitLab 仓库中的 l10n 分支。

连接 GitLab 账户

  1. 打开您的项目并转到集成
  2. 点击集成列表中的 GitLab
  3. 点击设置集成,然后从下拉列表中选择源文件和翻译文件模式目标文件包模式,以通过您的 GitLab 账户进行集成。
  4. 然后在 GitLab 端授权与 Crowdin 企业版的连接。

In case the repository you need is private, and you have limited or no access to it, please ask the repository owner to provide you with an access token.

注意:当设置一个与访问令牌的集成时,请确保您在仓库中拥有必要的维护层权限。

选择仓库

In the appeared dialog, select your repository and branches that should be translated. It’s recommended to switch Duplicate Strings to Show within a version branch, so identical strings will be hidden between branches. If your source files contain strings with apparent identifiers (keys), it’s better to use a strict version of this option. In other cases, feel free to use a regular one.

详细了解重复字符串

目标文件包模式下使用 GitLab 集成时,集成将从您的 Crowdin 企业版项目发送已完成的翻译,而无需从您的仓库中提取源文件。 因此,在选择应翻译的仓库和分支时,您可以指定集成应将生成的带有翻译的包放在何处。

详细了解为 VCS 集成配置目标文件包

当您使用私有集成(例如,与自托管 VCS 集成)时,您需要将专用的 Crowdin 企业版 IP 地址添加到白名单中,以确保其正常运行并保持安全。

阅读更多有关 IP 地址 的信息。

服务分支

当翻译完成并且您的语言准备好上线时,Crowdin 企业版会将合并请求和翻译发送到您的版本控制系统。 对于每个进行本地化的分支,Crowdin 企业版都会创建一个带有翻译的附加服务分支。 We don’t commit directly to the master branch so that you can verify translations first.

By default, l10n_ is added to the created service branch name. If necessary, you can easily change it.

同步配置

要从仓库导入现有翻译,请选择以下选项之一:

  • 分支连接后一次性导入翻译
  • 始终从仓库导入新翻译

默认情况下,选择第一个选项仅导入翻译一次。 或者,如果您不想从仓库导入翻译,则可以清除这两个选项。

By default, sources are not pushed to the repo with translations. 不过,如果您在 Crowdin 企业版项目中执行源文本审查,并希望将对 Crowdin 企业版上的源文件所做的更改推送回您的仓库,请点击编辑,在集成设置中选择推送源,然后点击保存

There are cases when it’s necessary to disable translations from being pushed to the repo temporarily. In this situation, click Edit, clear Sync Schedule in the integration settings, and click Save. When ready to sync translations with the repo, select the Sync Schedule, and click Save.

The synchronization is processed every hour automatically. If necessary, you can change the update interval in the integration settings. To configure the synchronization schedule – click Edit, scroll down to the Sync Schedule, set the preferred interval, and click Save.

不依赖于同步设置,源文件在仓库上的更改仍然会持续与 Crowdin 企业版同步。

自动同步分支

设置集成时,您可以选择要添加到 Crowdin 企业版项目的现有仓库分支。 要自动将未来的分支从 GitLab 添加到 Crowdin 企业版,请在集成设置中为分支名称创建模式。

例如,您在 GitLab 集成设置中添加*功能模式。 In this case, the future branches that contain this word at the end of the title will be added to the project.

To add a pattern for branch names, follow these steps:

  1. 点击 GitLab 集成部分中的编辑
  2. In the appeared dialog, scroll down to the Branches to Sync Automatically.
  3. In the Branches to Sync Automatically field, use wildcard selectors such as ‘*’, ‘?’, ‘[set]’, ‘' and others to identify the necessary branches.
  4. 点击 保存

默认配置文件名称

crowdin.yml is the default file name that is used for automatically synchronized branches. To change the default settings, click Edit, specify the preferred name in the Default configuration file name field in the integration settings, and click Save.

If you don’t specify your custom configuration file name for automatically synchronized branches, and the integration doesn’t find a configuration file with the default name crowdin.yml in the root of the branch, these branches will be marked in the integration settings with a red icon with an exclamation mark saying “Not Ready. Check the configuration”.

选择要同步的内容

To make integration work, you need to specify which source files should be translated and how Crowdin Enterprise should structure translated files in your repository. If you see a red icon with an exclamation mark next to the service branch name, it means that you haven’t selected any content for synchronization.

There are two ways you can specify content for synchronization:

  • Configuring online
  • Configuring manually by creating a configuration file

在线配置

This procedure is the same for all integrations with version control systems (VCS). 查看VCS 集成:在线配置,了解如何在线选择同步内容。

创建配置文件

配置文件 crowdin.yml 应与您要翻译的每个单独分支一起存储在 GitLab 仓库中,以便 Crowdin 企业版知道到底应发送哪些文件进行翻译。

It should have the same structure as required for CLI, but your project’s credentials should not be stored in the file’s header for security reasons.

阅读更多关于 创建配置文件 的信息。

Working with Multiple Repositories within One Project

If you’re working with a multi-platform product that has versions for different operating systems, you may want to connect multiple repositories that contain source files for each operating system. In this case, localization resources (e.g., TMs, Glossaries) and translations could be used more efficiently, reducing the time needed for project localization.

To add another repository, follow these steps:

  1. 打开您的项目并转到集成
  2. 点击集成列表中的 GitLab
  3. Click Add Repository.
  4. Configure the integration with the new repository according to your needs and preferences.

检查同步状态

设置集成后,所有相关信息都存储在集成 > GitLab部分。

After the integration is connected, the settings can be updated only by the project member who configured it. All project managers except the person who configured the integration will see the Edit button disabled with the following message when hovering over it: Integration was configured by {Full Name}.

By default, synchronization is processed every hour automatically. If you need to launch the synchronization immediately – click Sync Now. 或者,如果您只需要单独同步一个分支,请点击所需分支上的 并选择 同步分支

立即同步 GitLab

从仓库中上传译文

默认情况下,存储在仓库中的翻译仅在第一次同步时上传到 Crowdin 企业版。 要手动将译文上传到 Crowdin 企业版,请点击 立即同步 按钮旁边的 ,然后点击 上传译文。 该集成会将现有翻译上传至您的 Crowdin 企业版项目。

Q&A

Q: I have an application build configured to be triggered by every commit. 由于 Crowdin 在单独的提交中提交每个翻译文件,我如何避免由 Crowdin 的提交触发不必要的应用构建?
答:由于 Crowdin 中的 VCS 集成使用 API 来提交文件而不是 Git,因此每个文件都是单独提交的。

Here are a few recommendations that might help solve similar situations:

  • Use the export_languages option to skip commits from languages you’re not interested in yet. 详细了解 VCS 集成的导出语言参数
  • Use the [ci skip] tag in the commit messages to skip unnecessary builds. 详细了解 VCS 集成的提交消息参数
  • Configure the preferred sync interval using Sync Schedule (e.g., set the sync once in 24 hours).
  • Squash commits when merging a localization branch to keep the master branch history clean and uncluttered.

另请参阅

本文是否有帮助?