Prefix translation

Created on 2 April 2024, 9 months ago
Updated 11 September 2024, 3 months ago

Problems + Steps to reproduce

Hi !
When you want a translated node, you normaly use this kind of request, on jsonapi :

{{host}}/{{langcode}}/jsonapi/node/{{bundle}}

For example :
http://localhost:8080/it-it/jsonapi/node/article => give me all the it-it article

When i try this on your module, it only give me the translated node with the higher weight language (not the original).

My de-de has a higher weight so when i want :

http://localhost:8080/api/it-it/my-italian-article it give me my-dutch-article

Proposed resolution

A solution could be => add the langcode parameter into the function buildJsonApiPath() as below :

/**
   * Build a default JSON-API path from provided entity information
   *
   * @param array $info
   *   A list of relevant entity properties
   *
   * @return string
   *   The
   */
  protected function buildJsonApiPath($info, $langcode) {
    if (isset($info['bundle']) && $info['bundle'] !== null) {
      return '/' . $langcode . '/' . $this->jsonapiPrefix . '/' . $info['type'] . '/' . $info['bundle'] . '/' . $info['uuid'];
    } else {
      return '/' . $langcode . '/' . $this->jsonapiPrefix . '/' . $info['type'] . '/' . $info['uuid'];
    }
  }

And update the line 150 with :
$path = $this->buildJsonApiPath($info, $langcode);

What do you think about this ?

Best regards

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇫🇷France allan.ordogh

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024