implode() error when translating views with plural variants

Created on 25 August 2022, over 2 years ago
Updated 28 March 2024, 9 months ago

Problem/Motivation

The following error occurs when translating a Search API view containing "plural variants"

The website encountered an unexpected error. Please try again later.
TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in implode() (line 76 of core/modules/config_translation/src/FormElement/PluralVariants.php).

implode('', '1 @cuenta') (Line: 76)
Drupal\config_translation\FormElement\PluralVariants->setConfig(Object, Object, '1 @cuenta', 'display.attachment_1.display_options.fields.nid.fallback_options.format_plural_string') (Line: 89)
Drupal\config_translation\FormElement\ListElement->setConfig(Object, Object, Array, 'display.attachment_1.display_options.fields.nid.fallback_options') (Line: 89)
Drupal\config_translation\FormElement\ListElement->setConfig(Object, Object, Array, 'display.attachment_1.display_options.fields.nid') (Line: 89)
Drupal\config_translation\FormElement\ListElement->setConfig(Object, Object, Array, 'display.attachment_1.display_options.fields') (Line: 89)
Drupal\config_translation\FormElement\ListElement->setConfig(Object, Object, Array, 'display.attachment_1.display_options') (Line: 89)
Drupal\config_translation\FormElement\ListElement->setConfig(Object, Object, Array, 'display.attachment_1') (Line: 89)
Drupal\config_translation\FormElement\ListElement->setConfig(Object, Object, Array, 'display') (Line: 89)
Drupal\config_translation\FormElement\ListElement->setConfig(Object, Object, Array) (Line: 290)
Drupal\tmgmt_config\Plugin\tmgmt\Source\ConfigSource->saveTranslation(Object, 'es') (Line: 874)
Drupal\tmgmt\Entity\JobItem->acceptTranslation() (Line: 362)
Drupal\tmgmt\Form\JobItemForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 592)
Drupal\Core\Form\FormBuilder->processForm('tmgmt_job_item_edit_form', Array, Object) (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
...

Plural variants seem to be associated with numeric fields in a Search API index view. When using the native translate view UI in Drupal, the plural variant appears as two separate fields to translate, a "singular form" and a "first plural form":

But when the same view is translated with Translation Management, it mistakenly attempts to combine both fields together and translate as a single field:

This leads to the above error when attempting to save the translated values in the view's configuration because it is expecting to have an array containing the two translated fields, but instead it is only given a single string.

Steps to reproduce

Using Drupal 9.4.3, Search API 1.23, Search API Solr 4.2.7, and Translation Management 1.14:

  1. Create a content type with a number field (float or integer)
  2. Create a Search API Index view that displays fields. Add the number field (from the Content datasource) to the list of displayed fields.
  3. Go to the native view translation interface for that view. Verify that the view contains a "plural variant" within the set of translatable strings defined within the numeric field. It's usually found by drilling down to [display]->fields->[numeric field name]->options for fallback handler->plural variants (or some path similar to that)
  4. Now go to the Translation Management Sources tab, select the View source, and attempt to translate the view. Note the combined plural variant field and resulting error when accepting/saving the translated strings.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs work

Version

1.14

Component

Source: Configuration

Created by

🇺🇸United States RichardDavies Portland, Oregon

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.71.5 2024