DEV Community

ahandsel
ahandsel

Posted on • Edited on • Originally published at github.com

1

Phrase CLI Debug locale_mapping Error

The locale_mapping parameter is required when using the phrase push command to upload a CSV file to update a Phrase Strings project.

Table of Contents

Problem

When using the phrase push command to upload a CSV file to update a Phrase Strings project, I kept encountering the following error:

API response: {"message":"Validation failed","errors":[{"resource":"Upload","field":"locale_mapping","message":"You must provide a locale_mapping parameter."}]}
ERROR: 422 Unprocessable Entity
Enter fullscreen mode Exit fullscreen mode

Solution

Contrary to what the Phrase Strings Upload a new file API documentation suggests, the locale_mapping parameter is mandatory when using the phrase push command with a CSV file.

Here is the correct configuration for the .phrase.yml file:

phrase:
  access_token: #access_token
  project_id: #project_id
  file_format: csv
  push:
    sources:
      - file: ./upload-translations.csv
        params:
          file_format: csv
          locale_mapping: {"en": "2"}
  pull:
    targets:
      - file: ./<locale_name>-translations.csv
Enter fullscreen mode Exit fullscreen mode

How to Configure locale_mapping Parameter

Below is a snippet from the .phrase.yml template file:

locale_mapping: {"LANGUAGE_CODE": "COLUMN"} (object) #Optional, format specific (Excel, CSV) mapping between locale names and the columns the translations to those locales are contained in.
Enter fullscreen mode Exit fullscreen mode

In my case, I had to map the en locale to the 2 column in the CSV file.

locale_mapping: {"en": "2"}
Enter fullscreen mode Exit fullscreen mode

If you need to map multiple locales, you can configure it as follows:

locale_mapping: {"en": "2", "ja": "3"}
Enter fullscreen mode Exit fullscreen mode

Warning - Plural Forms

⚠️ Warning: If you are working with plural forms, ensure you use the correct plural suffixes for each language specified in the locale_mapping parameter.

For example, English and Japanese have different plural forms:

  • For English, use zero, one, and other.
  • For Japanese, use zero and other.

Adding a Japanese translation for the one plural form generates a new key instead of updating the existing key for the other plural form.

Background & Environment

  • Phrase CLI version: 2.23.2
  • Device:
    • ProductName: macOS
    • ProductVersion: 14.4.1
    • BuildVersion: 23E224

Imagine monitoring actually built for developers

Billboard image

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay