PO files

AI translation for PO files with Lingo.dev CLI

What are PO files?

PO (Portable Object) files are a text-based file format used by GNU gettext for software internationalization. They store original strings alongside their translations and are widely used in open-source software projects.

For example:

msgid ""
msgstr ""
"Project-Id-Version: Example Project 1.0\n"
"Language: en\n"

msgid "Welcome"
msgstr "Welcome"

msgctxt "navigation"
msgid "Home"
msgstr "Home"

msgid "You have %d message"
msgid_plural "You have %d messages"
msgstr[0] "You have %d message"
msgstr[1] "You have %d messages"

What is Lingo.dev CLI?

Lingo.dev CLI is a free, open-source CLI for translating apps and content with AI. It's designed to replace traditional translation management software while integrating with existing pipelines.

To learn more, see Overview.

About this guide

This guide explains how to translate PO files with Lingo.dev CLI.

You'll learn how to:

  • Create a project from scratch
  • Configure a translation pipeline
  • Generate translations with AI

Prerequisites

To use Lingo.dev CLI, ensure that Node.js v18+ is installed:

❯ node -v
v22.17.0

Step 1. Set up a project

In your project's directory, create an i18n.json file:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

This file defines the behavior of the translation pipeline, including what languages to translate between and where the localizable content exists on the file system.

To learn more about the available properties, see i18n.json.

Step 2. Configure the source locale

The source locale is the original language and region that your content was written in. To configure the source locale, set the locale.source property in the i18n.json file:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

The source locale must be provided as a BCP 47 language tag.

For the complete list of the locale codes that Lingo.dev CLI supports, see Supported locale codes.

Step 3. Configure the target locales

The target locales are the languages and regions you want to translate your content into. To configure the target locales, set the locale.targets property in the i18n.json file:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

Step 4. Create the source content

If you haven't already, create one or more PO files that contain the content to be translated. These files must be located at a path that includes the source locale somewhere in the path (e.g., as a directory name like en/ or as part of the filename like messages.en.po).

Step 5. Create a bucket

  1. In the i18n.json file, add a "po" object to the buckets object:

    {
      "$schema": "https://lingo.dev/schema/i18n.json",
      "version": "1.10",
      "locale": {
        "source": "en",
        "targets": ["es"]
      },
      "buckets": {
        "po": {}
      }
    }
    
  2. In the "po" object, define an array of one or more include patterns:

    {
      "$schema": "https://lingo.dev/schema/i18n.json",
      "version": "1.10",
      "locale": {
        "source": "en",
        "targets": ["es"]
      },
      "buckets": {
        "po": {
          "include": ["./[locale]/example.po"]
        }
      }
    }
    

    These patterns define which files to translate.

    The patterns themselves:

    • must contain [locale] as a placeholder for the configured locale
    • can point to file paths (e.g., "[locale]/messages.po")
    • can use asterisks as wildcard placeholders (e.g., "[locale]/*.po")

    Recursive glob patterns (e.g., **/*.po) are not supported.

Step 6. Configure an LLM

Lingo.dev CLI uses large language models (LLMs) to translate content with AI. To use one of these models, you need an API key from a supported provider.

To get up and running as quickly as possible, we recommend using Lingo.dev Engine — our own, hosted platform that offers 10,000 tokens of free, monthly usage:

  1. Sign up for a Lingo.dev account.

  2. Run the following command:

    npx lingo.dev@latest login
    

    This will open your default browser and ask you to authenticte.

  3. Follow the prompts.

Step 7. Generate the translations

In the directory that contains the i18n.json file, run the following command:

npx lingo.dev@latest run

This command:

  1. Reads the i18n.json file.
  2. Finds the files that need to be translated.
  3. Extracts the translatable content from the files.
  4. Uses the configured LLM to translate the extracted content.
  5. Writes the translated content back to the file system.

The first time translations are generated, an i18n.lock file is created. This file keeps track of what content has been translated, preventing unnecessary retranslations on subsequent runs.

Example

en/example.po

msgid ""
msgstr ""
"Project-Id-Version: Example Project 1.0\n"
"Language: en\n"

msgid "Welcome"
msgstr "Welcome"

msgctxt "navigation"
msgid "Home"
msgstr "Home"

msgid "You have %d message"
msgid_plural "You have %d messages"
msgstr[0] "You have %d message"
msgstr[1] "You have %d messages"

msgid "Save"
msgstr "Save"

es/example.po

msgid ""
msgstr ""
"Project-Id-Version: Example Project 1.0\n"
"Language: es\n"

msgid "Welcome"
msgstr "Bienvenido"

msgctxt "navigation"
msgid "Home"
msgstr "Inicio"

msgid "You have %d message"
msgid_plural "You have %d messages"
msgstr[0] "Tienes %d mensaje"
msgstr[1] "Tienes %d mensajes"

msgid "Save"
msgstr "Guardar"

i18n.json

{
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {
    "po": {
      "include": ["./[locale]/example.po"]
    }
  },
  "$schema": "https://lingo.dev/schema/i18n.json"
}

i18n.lock

version: 1
checksums:
  cdba37b4ade3da08cf12eccfde49d625:
    Welcome/singular: 3180ad6b8de344b781637750259e0f53
    Home/singular: 104a3db3b671c04e167eafbe21e57881
    You%20have%20%25d%20message/singular: 1691abfe2c5d017cda86e298d34f3524
    You%20have%20%25d%20message/plural: 2d37831bf51cc2cf75e812c0e61c6861
    Save/singular: f7a2929f33bc420195e59ac5a8bcd454
    Cancel/singular: 2e2a849c2223911717de8caa2c71bade
    Delete/singular: 8bcf303dd10a645b5baacb02b47d72c9
    Name/singular: 9368b5a047572b6051f334af5aa76819
    Email%20Address/singular: 0ee22bbbe989a0c61a18023407d12dc2
    Message/singular: f2f72126bd244cfc534eab395e054362
    Loading.../singular: 82b4ea7ed1439094d7c4be13aaba9a66
    Success!%20Changes%20saved./singular: 906371aaeec474803e22ae959605dad8
    Error%3A%20Request%20failed./singular: cdeaab2374e34c0e396cdb2596a9824e
    Add%20to%20Cart/singular: c93a29ccf502ff71bf08924dcdea9179
    Out%20of%20Stock/singular: 6673fc95c2cee3c713e0d60c8184e289
    Price%3A%20%24%25s/singular: a860f7b395e4a9d916a48717f9f8837a