Extract all translatable strings from entities

Created on 14 December 2020, over 3 years ago
Updated 16 March 2023, over 1 year ago

Problem/Motivation

When you request a translation, the extraction of strings is done by Helpers::extractStringsFromNode, but this function doesn't utilise any of the TMGMT data functions.

This severely complicates the function itself and limits the number of translatable strings it extracts. In addition, the function doesn't just handle extraction for nodes, but for all entities (custom blocks, menu links, etc.) and its name should reflect that.

Steps to reproduce

Create a node with paragraphs and attempt to translate it. Only the title will be extracted.

Proposed resolution

Re-write the extraction function so that it uses the tmgmt.data service, which flattens and filters the data array for us automagically.

Completed tasks

  • Rewrite the Helpers::extractStringsFromNode function to use \Drupal::service('tmgmt.data')->filterTranslatable($data)
  • Rewrite the Helpers::parseRemoteTranslations function to use \Drupal::service('tmgmt.data')->>unflatten($translations)
  • Refactor "_" replacement in favour of the TMGMT delimiter "][".

Remaining tasks

  • Determine if the changes in key names will affect translations in progress. [Does not appear to effect existing resources]
  • Remove redundant helper functions and improve function names.
  • Update tests and write new ones to show complex fields being used.

API changes

Possibly the name of the extractStringsFromNode function should change to extractStringsFromEntity and a few redundant functions (e.g. getKeysToIgnore) need to be removed.

Data model changes

Previously the keys generated for fields followed a $fieldName . '_' $propCount pattern, but now they use the MTGMT concatenation of all nested keys. E.g. title_0 becomes title][0][value, field_body_0 becomes field_body][0][value, and as an example a previously excluded paragraph would become field_paragraph][0][entity][field_body][0][value.

✨ Feature request
Status

Needs review

Version

1.1

Component

Code

Created by

πŸ‡³πŸ‡ΏNew Zealand dieuwe Auckland, NZ

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024