Module generates translations even if no translated value exists

Created on 9 October 2024, 3 months ago

Problem/Motivation

The module generates translations for all available languages, whether a value is supplied for each translation or not. This makes it challenging to identify what content has been translated, since all possible translations exist.

Steps to reproduce

1. Start simplytest.me, https://master-n7ylfvxy4yaxc1nvajhpxni6uazsuye8.tugboatqa.com/ add Inline Translation module
2. Configure Languages English (default), French, Spanish.
3. Configure content translation, only for Basic Page Body field, with inline translation
4. Add Basic page, add content to Body field English tab and French tab but not Spanish tab, save.
5. Observe in /admin/content that 3 rows for Basic page exist (IMO only English and French are expected)
6. Also, in the Translate tab for the Basic page node, all 3 languages appear: IMO only English and French are expected, since no Spanish value was supplied...

Proposed resolution

Is it possible to refactor entityBuilder() so that it checks whether supported (translatable) fields have distinct values, before building a translation entity.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇳🇿New Zealand jonathan_hunt

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

Comments & Activities

  • Issue created by @jonathan_hunt
  • 🇳🇿New Zealand jonathan_hunt

    Here's a patch for discussion, that aims to avoid generating a translation if the field value is empty.
    1. In addLanguageElements() when a new language field is added, the value is defaulted to null (perhaps this should look at the default value for the field rather than defaulting in value from site default language).
    2. entityBuilder() is refactored a little to attempt to detect a non-empty field value and only add a translation if field value is non-empty. This means I can have a site with 8 possible languages, but if the user only submits values for 3 languages, only 3 translations are generated. It allows an empty value to be saved when editing a translated value, but a translation needs to be manually deleted if no values exist.

    Perhaps an improvement would be to delete a translation if no values are different to the original language entity.

    This patch works for a translated textarea field; that is sufficient for my use-case. It hasn't been tested on other field types.

Production build 0.71.5 2024