Translation is broken for languages with locale or dialect

Created on 20 September 2023, over 1 year ago
Updated 25 January 2024, 11 months ago

Problem/Motivation

Language code can have two parts, like en-GB or zh-hans. We want to support this format

Steps to reproduce

1. Enable a language with dialect, e.g. zh-hans
2. Make translations for a node
3. Query the node with a specific translation, example query below

query MyQuery {
  entityQuery(
    entityType: NODE
    filter: {conditions: {field: "type", value: "article"}}
  ) {
    items {
      ... on NodeArticle {
        id
        translation(langcode: ZH_HANS) {
          label
        }
      }
    }
  }
}

Notice the language ENUM `ZH_HANS`, it was defined with the underscore. This underscore isn't converted back to hyphen when the server receives the query.

Therefore, you cannot get this specific translation

Proposed resolution

Correctly convert the language ENUM back to the code used by Drupal

Remaining tasks

Make a patch

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇨🇳China skyredwang Shanghai

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024