TypeError: Argument #2 ($string) must be of type Drupal\babel\Model\StringTranslation, int given

Created on 18 July 2025, about 1 month ago

I have tried the following:

* Install the site
* Enable babel
* Enabled a language (Greek in my case)
* Go to /el/admin/config/regional/babel
* Click Settings (Ρυθμίσεις)
* Click back to Translate (Μετάφραση)

The website breaks with TypeError: Drupal\babel\Form\BabelTranslateForm::Drupal\babel\Form\{closure}(): Argument #2 ($string) must be of type Drupal\babel\Model\StringTranslation, int given in Drupal\babel\Form\BabelTranslateForm->Drupal\babel\Form\{closure}() (line 303 of /var/www/html/src/Form/BabelTranslateForm.php).

For some reason, at some point we are messing with one of the strings and is returned as integer instead of the translatable source.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇷Greece idimopoulos

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

Comments & Activities

  • Issue created by @idimopoulos
  • 🇬🇷Greece idimopoulos

    Somehow, in BabelService, in

    foreach ($rows as $row) {
          // Pickup the first key from $ids as the source string and context.
          [$key] = explode(',', $row->keys, 2);
          [$pluginId, $id] = explode(':', $key, 2);
    
          $byPlugin[$pluginId][$id] = $row->keys;
          $status[$row->keys] = $row->status;
        }
    

    we are getting a locale: which results in an empty ID and the array_flip at the end of \Drupal\babel\BabelService::getStrings is causing it to be an integer - it tries to merge it with the $list but since there is no relevant match with locale:, it just retains the index as a value).

  • 🇬🇷Greece idimopoulos

    It seems like the culprit is because I can see in the babel_source table locale strings that do not have an ID

    | plugin | id | status | hash | sort_key                  |
    | locale |       | 1          | abcd | Announcements: |
    
  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

    Cannot reproduce. I'm going to close this issue. If you feel I'm wrong please reopen.

Production build 0.71.5 2024