GitHub Actions Integration

You can automate your localization workflow using GitHub Actions. This setup triggers Lara CLI to translate your files and commit the results back to your repository automatically on every push to the main branch.

Prerequisites

1. Configure Repository Secrets

Lara CLI authenticates with the translation API using credentials stored as GitHub Secrets.

  1. Go to your repository Settings > Secrets and variables > Actions.
  2. Click New repository secret.
  3. Add the following secrets (values available in your Lara account dashboard):
    • LARA_ACCESS_KEY_ID
    • LARA_ACCESS_KEY_SECRET

2. Configure Workflow Permissions

The action needs write access to commit translated files back to your repository.

  1. Go to Settings > Actions > General.
  2. Scroll to Workflow permissions.
  3. Select Read and write permissions.
  4. Click Save.

3. Ensure a Local Configuration Exists

Before using the GitHub Action, run lara-cli init locally and push the generated lara.yaml file to your repository. The CI workflow runs in non-interactive mode and requires this file to be present.


Workflow Configuration

Create the file .github/workflows/translate.yml in your repository with the following content:

name: Lara Translation Workflow

on:
  workflow_dispatch:
  push:
    branches:
      - main

jobs:
  translate-codebase:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'

      - name: Setup PNPM
        uses: pnpm/action-setup@v2
        with:
          version: 8

      - name: Install Lara CLI
        run: pnpm install -g @translated/lara-cli

      - name: Run Lara Translate
        env:
          LARA_ACCESS_KEY_ID: ${{ secrets.LARA_ACCESS_KEY_ID }}
          LARA_ACCESS_KEY_SECRET: ${{ secrets.LARA_ACCESS_KEY_SECRET }}
        run: lara-cli translate

      - name: Commit translations
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: "chore: update translations via Lara CLI"

How It Works

  1. Setup — The workflow installs Node.js v18 and PNPM v8.
  2. Installation — Lara CLI is installed globally from the npm registry.
  3. Translationlara-cli translate runs using the credentials stored in your GitHub Secrets. The lara.yaml configuration file in your repository controls which files are translated and into which languages.
  4. Auto-commit — Any updated translation files are automatically committed and pushed back to your main branch.