We have a feed import that fails (we have no clue why).
Looking at the "Log" tab did not help much as it crashed. It uses the locale() function to display the (translated) error text which in this case throws an PDOException:

PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'source' at row 1: INSERT INTO {locales_source} (location, version, source, context, textgroup) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array ( ..[very long].. ) ) in locale() (Zeile 714 von /html/drupal/modules/locale/locale.module).

(That is line 714 in /html/drupal/modules/locale/locale.module)

It is the "else" code block "We don't have the source string, cache this as untranslated...." with a call to "db_merge()->execute" which fails.

My dirty patch is to call this "else"-block only for texts with less than 128 Bytes (mb_strlen) and calling $locale_t[$langcode][$context][$string] = TRUE; only otherwise.

It would be better to catch this kind of PDOException with SQLSTATE[22001] and probably just forget it.
The "$locale_t... = TRUE;" is needed here, too, because drupal make calls to locale() over and over otherwise.

Another question is why to try to translate an exception's message as it might hide important details. Nevertheless there'a a bug in the locale() function or the database code used by it.

Comments

tylernichols’s picture

I have the same issue.

RobLoach’s picture

Version: 7.18 » 8.x-dev
Component: language system » locale.module

The size of locale_sources' source field is too small to hold the data you're inserting. Either don't insert so much data, or make the source field take more data:

       'source' => array(
         'type' => 'text',
         'mysql_type' => 'blob',
         'size' => 'big',
         'not null' => TRUE,
         'description' => 'The original string in English.',
       ),
function locale_update_7006() {
  db_change_field('locales_source', 'source', 'source', array(
    'type' => 'text',
    'mysql_type' => 'blob',
    'size' => 'big',
    'not null' => TRUE,
    'description' => 'The original string in English.',
  ));
}

The lack of patch is because it's more seeing if this helps the Drupal 7 folk first. The fix would need to get into Drupal 8 before backporting to 7.

worldlinemine’s picture

This is in response to comment #2 only:

I believe that the potential negative performance impact of increasing the size of the blob outweighs the benefit. The purpose of the Locale module is to support translations in the interface in which case 16kb would appear to be more then sufficient. I would not recommend making the change suggested in comment #2.

kardave’s picture

Hi all,

I had this issue, and not even #2 could help me.
I had a very large string in watchdog, and dblog page failed to load because the string was forced to be saved into locales_source.source.

Not having enough time for debugging how to eliminate the large string (deleting from watchdog did not do it) I had no choice.
My only remained solution was to patch the core (I know, never ever even think of it) temporary:

if(strlen($string) > 50000) {
    return $string;
}

/modules/locale/locale.module line 671

After some time I will remove this and see if survived the large string, but now it saved me a lot of debugging time.
I Hope this helps someone someday.

Paul Broon’s picture

This still happens (of course. since it hasn't been fixed/backported yet).
During development of a module, which logs some events to watchdog I made a mistake and a complete view including 25 full nodes was var_dumped into the watchdog message. Since I was on a multilingual site and currently in another language interface than English, the "Show Recent Log Posts" page fails with the above error. It works fine when switching to English.

ressa’s picture

I am experiencing this issue now, but @kardave's temporary fix doesn't seem to work any more... Does anyone know how to fix it, also even if only temporary?

mecano’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Title: Function locale() throws PDOException for long texts not already translated » Field locales_source.source is not suitable for long texts and huge config objects
Version: 8.2.x-dev » 8.3.x-dev
Issue tags: +D8MI, +language-base, +language-config
Related issues: +#2836206: Translation of big webforms broken

This is because mysql limit for blob field is 64k
Faced with that in d8 where config object is bigger than that

BTW looks the same limit we have for translation

jrockowitz’s picture

The attached patch is port of #4 to Drupal 8. All it does is store an empty string in the 'locales_source' and 'locales_target' table if the source string is greater than 64KB.

This is only a temporary solution. The most immediate side-effect I am seeing is when translating config the source string no longer appears because it is empty.

jrockowitz’s picture

Status: Active » Needs review
FileSize
1007 bytes

Here is the patch and I am setting it to needs review just get the testbot to review it.

Status: Needs review » Needs work

The last submitted patch, 12: field-1885192-12.patch, failed testing.

jrockowitz’s picture

Status: Needs work » Needs review
FileSize
1.07 KB

Status: Needs review » Needs work

The last submitted patch, 14: field-1885192-14.patch, failed testing.

andypost’s picture

Issue tags: +sprint

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.