Documentation

Welcome, and great to see you here! If you run into any questions, just reach out to us at hi@localhero.ai.

Quick Start

Sign up and follow these steps to integrate translation management with LocalHero.ai into your project.

1. Initialize Your Project

This will ask for your API key and create a localhero.json file in your project root,
and setup the GitHub Action to automatically translate your i18n files. You find your API key in the API Keys page.
$ npx @localheroai/cli init

2. Configure Your Project

Check the generated localhero.json file and see if you need any adjustments.
{:projectId=>"your-project-id", :sourceLocale=>"en", :targetLocales=>["es", "fr", "de"], :files=>["config/locales/*.yml", "app/javascript/locales/*.json"]}

3. Commit and Push

Commit and push your changes to your repository.
$ git switch -c add-localhero
$ git add localhero.json .github/workflows/localhero-translate.yml
$ git commit -m "Add translation management with LocalHero"
$ git push origin add-localhero

CLI Commands

$ localhero translate

Translate missing keys in your project, it will also check if there are any new keys
that have been added in API that are missing locally.

This is the command that will be run by the GitHub Action.

$ localhero init

Setup your project for LocalHero.ai, it will check if you have a API key setup
and create a localhero.json file in your project root.

$ localhero login

Authenticate with the API using your API key. This will save your API key to .localhero_key
and add the file to .gitignore if needed. You can also set your API key in the
LOCALHERO_API_KEY environment variable.

$ localhero pull

Pull the latest translation updates from LocalHero.ai to your local files. This command will
download any new or modified translations from the service to your local files.

Use --verbose to see detailed progress information.

$ localhero push

Push updates from your local translation files to LocalHero.ai. This command will upload any
new or modified translations from your local files to the service.

Use --verbose for detailed progress information and --yes to skip the confirmation prompt.

GitHub Action

Automate translations in your CI/CD pipeline with our GitHub Action.

The GitHub action requires that the LOCALHERO_API_KEY repository secret is set.
You set the secret in the repository settings under Settings > Secrets and variables > Actions.

name: Localhero.ai - I18n translation

on:
  pull_request:
    paths:
      - 'config/locales/**'

jobs:
  translate:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write

    steps:
    - name: Checkout code
      uses: actions/checkout@v4
      with:
        ref: ${{ github.head_ref }}
        fetch-depth: 0

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

    - name: Run LocalHero CLI
      env:
        LOCALHERO_API_KEY: ${{ secrets.LOCALHERO_API_KEY }}
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: npx @localheroai/cli translate