Allow to specify glossary for Drupal langcode with no direct equivalent remote target

Created on 4 June 2025, about 1 month ago

Problem/Motivation

I have been using the glossary feature for a while and it is working well. Most langcodes in Drupal have an equivalent langcode in Google. E.g. japanese, korean. However, I'm now working on a Hong Kong site with langcode zh-hant-hk. Google does not have a based model for the Hong version of traditional Chinese. It just uses zh-TW (Taiwan) See https://cloud.google.com/translate/docs/languages.

So in my Drupal website I have setup zh-hant-hk and set the remote target to zh-TW per the docs. This means however, that due to the current code, it's not possible to set a specific glossary for zh-hant-hk, because the glossary mapping uses the remote target langcode to check if a glossary exists, not the local drupal langcode.

Our hong kong team needs to be able to setup a hong kong specific glossary for certain terms.

Steps to reproduce

Try and setup a language zh-hant-hk, map it to zh-TW and you will notice that currently the glossary won't work, because it uses getRemoteTargetLanguage for looking up the glossary.

Proposed resolution

I have cleaned up the arguments passed to executeTranslation as there are too many for yet another argument, so we now have a $translation_context array with all the meta data for the translation. A new language_to_local which represents the Drupal langcode of the translation and then the language_to_remote which is the base model that Google is going to use.

I also fixed a bug where the glossaries weren't being passed recursively with longer text.

Remaining tasks

I've tested it

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Feature request
Status

Active

Version

1.0

Component

Code

Created by

achap 🇦🇺

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