Resolve entity language path if url.prefixes is configured

Created on 14 May 2025, 1 day ago

Problem/Motivation

It’s common to set the language path as a replacement of the language ID, in URL prefixes /admin/config/regional/language/detection/url, so e.g. zh-hans language ID is cn in the URL.

Currently, the @entityLanguage directive always returns the ID. This can lead to issues in some situations:

  • When using the @entityPath directive, there can be a mismatch between the path prefix and language ID used by some processes
  • If this language ID is used by SSG for manual paths creation after sourcing

A side issue is GraphQL enums. If we want to have a representation of locales with enums, we cannot use dashes.

So values like this cannot be used for enums. Example, for Swiss German:

  • Language ID is gsw-berne
  • ISO 639-1 language path is de-CH

Proposed resolution

As the @loadEntity directive uses the UrlLanguage data producer when we want to load an entity by path, it already handles the language URL prefixes. So we could use the language path for the @entityLanguage directive, fallback to the ID if it's not configured, and make sure to convert - to _ so it's GraphQL enum friendly.

The downside of doing this dash conversion is that the frontend will have to deal with reverse _ to - in some cases.

Then, we still need to check other methods to load an entity.

Another approach would be to use a GraphQL language type that can hold several values.

  • name: for a language switcher
  • translatedNames: if needed by the frontend
  • id: so it can be used for loading by ID if needed in other contexts
  • path: for manual path generation
  • weight: for e.g. ordering in a language switcher

This last approach is probably more sustainable but can also lead to extra complexity.

πŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡­Switzerland colorfield Lausanne

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