Migrate from CLI v0 to the CLI in your pipeline

Replace the CLI v0 step in GitHub Actions, GitLab CI, Buildkite or Bitbucket Pipelines with @lingo.dev/cli, keeping the translations you have.

You end with your CI pipeline translating each change with @lingo.dev/cli and committing the result.

Before you begin

  • A Lingo.dev organization with a localization engine
  • The project's i18n.lock, committed. If it is missing, restore it from git: without it, v0 cannot tell outdated translations from current ones, and --frozen passes even when they are outdated.
  • Node.js and npm
  • Access to your CI configuration and its secrets

Migrate #

  1. Finish with v0#

    Run v0 one last time

    The new CLI does not fill keys that are missing from target files that already exist, so let v0 bring every target file up to date first.

    Translate what is pending with the lingo.dev version in your package.json, or the latest 0.138.x:

    Terminal
    npx lingo.dev@0.138 run

    Then check that nothing is left:

    Terminal
    npx lingo.dev@0.138 run --frozen

    It fails with "Target file is missing translations" while any target file lacks a key, and also when a source changed since i18n.lock or a target has keys the source no longer has. Fix what it reports and run it again until it passes.

    Commit the source files, the target files and i18n.lock. Do not edit source files until the migration is done.

  2. Install the new CLI and sign in#

    Both packages install a lingo command, so remove a global v0 first:

    Terminal
    npm uninstall --global lingo.dev
    npm install --global @lingo.dev/cli
    lingo --version
    lingo login

    lingo --version prints lingo v1.26.0 or newer. In a project that keeps lingo.dev as a dependency, run npx @lingo.dev/cli in place of lingo.

  3. Convert i18n.json#

    On a new branch, from the folder that holds i18n.json, run:

    Terminal
    lingo migrate

    It writes .lingo/config.json beside i18n.json and changes no other file. If it prints settings under "Not converted", look each one up in Convert i18n.json. If the repository has more than one i18n.json, see Several i18n.json files.

  4. Link the project to your organization and engine. If lingo migrate printed a command such as lingo link --engine eng_abc123, run that one instead, because it names the engine v0 used:

    Terminal
    lingo link

    Commit .lingo/config.json.

  5. Run the first push#

    From the folder that holds .lingo/config.json:

    Terminal
    lingo push --backfill-missing --wait

    It translates only the target files that do not exist yet, keeps the ones that do, and writes .lingo/lock.json, the baseline for later pushes. The lockfile records exact source bytes, so your source files must use LF line endings; Fill missing keys shows the .gitattributes line. When the engine sends work to human review, --wait returns once only reviews remain; run lingo pull after reviewers finish.

    Review the diff, then commit the target files with .lingo/config.json and .lingo/lock.json. From then on, lingo push --wait translates what changed since the last push.

  6. Rename the API key#

    The new CLI reads only LINGO_API_KEY. Create an API key in the organization the config is linked to, and store it as LINGO_API_KEY in every CI system and secret store that held LINGODOTDEV_API_KEY. Until you rename the secret, map it in the job:

    GitHub Actions
    env:
      LINGO_API_KEY: ${{ secrets.LINGODOTDEV_API_KEY }}
  7. Replace the pipeline step#

    Delete the step or workflow that runs v0, and add a job that runs the new CLI and commits the changed target files with .lingo/lock.json. Open the job for your CI and replace locales with your target paths:

    GitHub Actions
    YAML
    name: Translate
    on:
      push:
        branches: [main]
    permissions:
      contents: write
    jobs:
      translate:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - uses: actions/setup-node@v4
            with:
              node-version: 22
          - run: npx -y @lingo.dev/cli@latest push --wait
            env:
              LINGO_API_KEY: ${{ secrets.LINGO_API_KEY }}
          - run: |
              git add -- locales .lingo/lock.json
              git diff --cached --quiet && exit 0
              git config user.name "Localization bot"
              git config user.email "localization@example.com"
              git commit -m "Update translations"
              git push
    GitLab CI
    YAML
    translate:
      image: node:22
      resource_group: lingo-translations
      rules:
        - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
      script:
        - git fetch --quiet "$CI_REPOSITORY_URL" "$CI_DEFAULT_BRANCH"
        - if [ "$(git rev-parse FETCH_HEAD)" != "$CI_COMMIT_SHA" ]; then exit 0; fi
        - npx -y @lingo.dev/cli@latest push --wait
        - git add -- locales .lingo/lock.json
        - if git diff --cached --quiet; then exit 0; fi
        - git config user.name "Localization bot"
        - git config user.email "localization@example.com"
        - git commit -m "Update translations"
        - >-
          git push --force
          -o ci.skip
          -o merge_request.create
          -o merge_request.target="$CI_DEFAULT_BRANCH"
          -o merge_request.title="Update translations"
          "https://oauth2:${GITLAB_PUSH_TOKEN}@${CI_SERVER_FQDN}/${CI_PROJECT_PATH}.git"
          "HEAD:refs/heads/lingo/translations"
    Buildkite
    YAML
    steps:
      - label: "Translate"
        if: build.branch == pipeline.default_branch && build.pull_request.id == null
        concurrency: 1
        concurrency_group: "lingo-translations"
        secrets:
          - LINGO_API_KEY
        command: |
          npx -y @lingo.dev/cli@latest push --wait
          git add -- locales .lingo/lock.json
          if git diff --cached --quiet; then exit 0; fi
          git config user.name "Localization bot"
          git config user.email "localization@example.com"
          git commit -m "[skip ci] Update translations"
          git push origin "HEAD:refs/heads/$${BUILDKITE_BRANCH}"
    Bitbucket Pipelines
    YAML
    image: node:22
    
    pipelines:
      branches:
        main:
          - step:
              name: Translate and commit
              auth:
                system:
                  scopes:
                    - read:git:bitbucket
                    - write:git:bitbucket
              script:
                - npx -y @lingo.dev/cli@latest push --wait
                - git add -- locales .lingo/lock.json
                - if git diff --cached --quiet; then exit 0; fi
                - git config user.name "Localization bot"
                - git config user.email "localization@example.com"
                - git commit -m "[skip ci] Update translations"
                - git push origin "HEAD:$BITBUCKET_BRANCH"

    Keep --wait: without it, the push returns when the run starts and writes no files. Keep committing the lockfile: without it, every run looks like a first run. The v0 Action's commit and pull request inputs become your own git steps, and working-directory moves to the step. The GitLab job pushes with a GITLAB_PUSH_TOKEN variable and opens a merge request. The GitHub Actions, GitLab CI/CD, Buildkite and Bitbucket Pipelines recipes explain each job, including pull request delivery.

  8. Check pull requests#

    Replace a --frozen check with lingo check on every pull or merge request. It needs no API key, and it fails when a source changed since .lingo/lock.json, a source was never pushed, or a target file is missing. It does not report a key missing inside a target file that exists. Open the job for your CI:

    GitHub Actions
    YAML
    name: Check translations
    on: pull_request
    jobs:
      check:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - run: npx -y @lingo.dev/cli@latest check
    GitLab CI
    YAML
    check_translations:
      image: node:22
      rules:
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      script:
        - npx -y @lingo.dev/cli@latest check
    Buildkite
    YAML
    steps:
      - label: "Check translations"
        if: build.pull_request.id != null
        command:
          - npx -y @lingo.dev/cli@latest check
    Bitbucket Pipelines
    YAML
    image: node:22
    
    pipelines:
      pull-requests:
        "**":
          - step:
              name: Check translations
              script:
                - npx -y @lingo.dev/cli@latest check

    Add it where translations are committed with the source change. When your pipeline translates after the merge to the default branch, feature pull requests change sources before translation, so the check fails them.

  9. Remove v0#

    Once the first push is committed and the new job runs, remove what is left of v0. Delete the v0 config and lockfile:

    Terminal
    git rm i18n.json i18n.lock

    Remove the LINGODOTDEV_API_KEY secret once no job reads it, and any provider keys that only v0 used. Remove lingo.dev from your dependencies unless the application imports lingo.dev/sdk:

    Terminal
    npm uninstall lingo.dev

    Then search for what is left of v0:

    Terminal
    git grep -nE 'lingo\.dev (run|i18n|ci)|lingodotdev/lingo\.dev@|LINGODOTDEV_API_KEY'

    Replace each match, such as an npm script that runs lingo.dev run, with its equivalent from Map v0 commands and flags. Only a LINGO_API_KEY mapping of the old secret may remain until you rename it.

Check it worked #

  • lingo --version prints 1.26.0 or newer, and lingo whoami shows your organization and engine, and your account when you signed in with lingo login.
  • lingo check exits 0.
  • After you change one source string, your pipeline writes the new translation to every target file, and a second lingo push --wait prints "Nothing to push".

If something fails, see Troubleshooting.

Used --target-locale, --file, your own model key, several i18n.json files or another uncommon setup? See Uncommon setups. If a step does not fit your setup, email support@lingo.dev.