|
文档
预约演示平台
平台MCPCLIAPI工作流
指南更新日志

持续本地化

  • 工作原理
  • 设置

平台

  • GitHub App
  • GitHub
  • GitLab CI/CD
  • Bitbucket Pipelines
  • 高级实践

Bitbucket Pipelines

在 Bitbucket 中,你可以在 pipeline 步骤里运行 @lingo.dev/cli:先安装,再运行 lingo push,通过你的引擎翻译变更过的源字符串,然后提交结果,或借助 Bitbucket 自带工具发起拉取请求。

前置条件

你需要先提交 .lingo/config.json(其中包含 engineId、源区域设置和目标区域设置,以及 files 模式),并将 Lingo.dev API 密钥存储为仓库变量。创建配置可参考 CLI 快速开始。

身份认证#

CLI 通过 LINGO_API_KEY 环境变量进行身份验证。请将你的密钥添加为受保护的仓库变量,以便 pipeline 步骤可以访问:

Repository settings > Repository variables —— 添加 LINGO_API_KEY,并将其标记为受保护。

如果要将提交推回仓库或发起拉取请求,pipeline 还需要 Git 写权限。常见做法是使用仓库 SSH 密钥(Repository settings > SSH keys),或使用具备 Read & write repositories 权限范围的仓库访问令牌(PR 模式下还需 pull requests),并将其作为受保护的仓库变量保存,例如 BB_TOKEN。

工作流示例#

直接提交(默认)#

安装 CLI,运行 lingo push,然后将翻译后的文件提交回当前分支:

yaml
image: node:22

pipelines:
  branches:
    main:
      - step:
          name: Translate
          script:
            - npm install -g @lingo.dev/cli
            - lingo push
            - git config user.name "lingo-bot"
            - git config user.email "support@lingo.dev"
            - git add .
            - git diff --cached --quiet || git commit -m "chore: update translations"
            - git push origin HEAD:main

lingo push 只会翻译自上次运行以来发生变更的内容(记录在 .lingo/lock.json 中),等待运行完成后,再将输出写入磁盘。

拉取请求模式#

你也可以将翻译推送到专用分支,而不是直接提交到 main,然后借助 Bitbucket 的工具发起拉取请求:

yaml
image: node:22

pipelines:
  branches:
    main:
      - step:
          name: Translate
          script:
            - npm install -g @lingo.dev/cli
            - lingo push
            - git config user.name "lingo-bot"
            - git config user.email "support@lingo.dev"
            - git checkout -b lingo/translations
            - git add .
            - git diff --cached --quiet || git commit -m "feat: update translations"
            - git push origin lingo/translations
            # Open a PR from lingo/translations into main via the Bitbucket UI or API

单体仓库#

如果配置文件位于某个 workspace 内,请从对应子目录运行 CLI。CLI 会以当前工作目录为基准解析 .lingo/config.json:

yaml
image: node:22

pipelines:
  branches:
    main:
      - step:
          name: Translate
          script:
            - cd apps/web
            - npm install -g @lingo.dev/cli
            - lingo push

Pipeline 变量#

变量必填说明
LINGO_API_KEY是Lingo.dev API 密钥。请将其保存为受保护的仓库变量。
BB_TOKEN用于 push/PR 写权限供 Git 用于提交代码或发起拉取请求的仓库访问令牌(或 SSH 密钥)。

其他所有内容——源语言、目标语言、文件模式,以及要经过的引擎——都写在 .lingo/config.json 中,而不是 pipeline 变量里。

部署前校验#

添加一个 lingo check 步骤,当任一源字符串缺少翻译时,直接让 pipeline 失败:

yaml
- step:
          name: Check translations
          script:
            - npm install -g @lingo.dev/cli
            - lingo check

下一步#

GitHub App
在 GitHub 上实现省心的持续本地化
GitHub Actions
在 GitHub Actions 作业中运行 CLI
GitLab CI/CD
在 GitLab pipeline 中运行 CLI
高级用法
翻译检查、合并冲突、工作流选择

这个页面对你有帮助吗?

Max PrilutskiyMax Prilutskiy·已更新 23 天前·1 分钟阅读