CI templates

Updated

Copy-paste pipelines for Bitbucket Pipelines and Azure Pipelines. They run the Translatize CLI, so they work with every file format. On GitHub use the Action; on GitLab the component.

What they do

  • On a pull request: translatize status --fail-on-missing fails the build when a language is missing translations, then translatize qa fails it on quality errors. Add --fail-on warning to qa to be stricter.
  • On a merge to main: translatize push sends new source keys. It never deletes keys.

Setup

  1. Create an API token bound to your main branch (Project Settings → Integrations) and keep it secret. The CLI reads it from TRANSLATIZE_API_TOKEN.
  2. Commit translatize.config.json. npx @translatize/cli init writes one, and --preset picks the format for your platform – see File formats and presets.
  3. Copy the file for your platform to the repository root and store the token:
    • Bitbucket: Repository settings → Pipelines → Repository variables, name TRANSLATIZE_API_TOKEN, tick Secured.
    • Azure: pipeline Variables, name TRANSLATIZE_API_TOKEN, tick Keep this value secret. Azure does not pass secret variables to scripts on their own, so the template maps it in env:.

Bitbucket Pipelines

Save as bitbucket-pipelines.yml in the repository root. The secured repository variable reaches the steps as an environment variable, with no mapping.

bitbucket-pipelines.yml
# Translatize on Bitbucket Pipelines.
# Add TRANSLATIZE_API_TOKEN under Repository settings > Pipelines > Repository
# variables and tick "Secured". Needs translatize.config.json in the repo root.

image: node:24-alpine

pipelines:
  pull-requests:
    '**':
      - step:
          name: Translations
          max-time: 10
          script:
            - export TRANSLATIZE_CLI_VERSION="${TRANSLATIZE_CLI_VERSION:-latest}"
            - npx --yes "@translatize/cli@$TRANSLATIZE_CLI_VERSION" status --fail-on-missing
            - npx --yes "@translatize/cli@$TRANSLATIZE_CLI_VERSION" qa

  branches:
    main:
      - step:
          name: Push source keys
          max-time: 10
          script:
            - export TRANSLATIZE_CLI_VERSION="${TRANSLATIZE_CLI_VERSION:-latest}"
            - npx --yes "@translatize/cli@$TRANSLATIZE_CLI_VERSION" push

Azure Pipelines

Save as azure-pipelines.yml and create a pipeline from it. The Check stage runs for pull requests, the Push stage for builds of main.

azure-pipelines.yml
# Translatize on Azure Pipelines.
# Add TRANSLATIZE_API_TOKEN as a secret pipeline variable (Pipelines > Edit >
# Variables, tick "Keep this value secret"). Needs translatize.config.json in
# the repo root.
#
# Azure Repos Git ignores the pr: block below. For Azure Repos, add this
# pipeline as a Build validation policy on main (Repos > Branches > Branch
# policies). On GitHub and Bitbucket Cloud repos the pr: block works.

trigger:
  branches:
    include:
      - main

pr:
  branches:
    include:
      - main

variables:
  # "latest" or an exact version, same as the GitLab template.
  translatizeCliVersion: latest

pool:
  vmImage: ubuntu-latest

stages:
  - stage: Check
    displayName: Translations
    condition: eq(variables['Build.Reason'], 'PullRequest')
    jobs:
      - job: check
        steps:
          - task: NodeTool@0
            inputs:
              versionSpec: '24.x'
          - script: npx --yes "@translatize/cli@$(translatizeCliVersion)" status --fail-on-missing
            displayName: Missing translations
            env:
              TRANSLATIZE_API_TOKEN: $(TRANSLATIZE_API_TOKEN)
          - script: npx --yes "@translatize/cli@$(translatizeCliVersion)" qa
            displayName: QA
            env:
              TRANSLATIZE_API_TOKEN: $(TRANSLATIZE_API_TOKEN)

  - stage: Push
    displayName: Push source keys
    condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
    jobs:
      - job: push
        steps:
          - task: NodeTool@0
            inputs:
              versionSpec: '24.x'
          - script: npx --yes "@translatize/cli@$(translatizeCliVersion)" push
            displayName: Push
            env:
              TRANSLATIZE_API_TOKEN: $(TRANSLATIZE_API_TOKEN)
Azure Repos needs a branch policy
For Azure Repos Git, a pr: block in YAML has no effect. Pull request runs come from branch policies: open Repos → Branches → main → Branch policies → Build validation, and add this pipeline. The Check stage runs when the build reason is a pull request, and draft pull requests do not trigger it. The pr: block stays in the file for repositories on GitHub or Bitbucket Cloud that are built from Azure Pipelines.

Pinning the CLI

Both files run npx @translatize/cli@<version>, and the version is latest. Replace it with an exact version, for example 0.2.0, to pin it. On Bitbucket set a TRANSLATIZE_CLI_VERSION repository variable; on Azure edit translatizeCliVersion.

Good to know

  • Do not expose a token for main to builds from untrusted forks. Check what your platform passes to fork builds and leave secrets out of them.
  • Pull request builds need the token to read branch data, so the token must be allowed to act on the branch you compare against.
  • The templates need translatize.config.json in the repository, because status and push read your translation files.