I'm using $conf['locale_custom_strings_xx'] in settings.php and i have no problems with translations through t() php function. But if i translate through Drupal.t() javascript function there is no string translation from $conf['locale_custom_strings_xx']. Instead I have to use locales_target database table to translate strings through Drupal.t() javascript function.

Drupal.t() should also use $conf['locale_custom_strings_xx'].

Steps to reproduce

Easiest way to reproduce is:

1. enable second language (for example German)
2. specify some string overrides in settings.php, for example:

 $conf['locale_custom_strings_de'][''] = [
   'Label' => 'LabelCUSTOM',
   'Edit' => 'EditCUSTOM',
 ];

3. Go to /de/admin/structure/types/manage/page/fields
4. You can see the "Label" strings overriden correctly, but the "Edit" (when you start to type a new machine name) is not, as this is coming from Drupal.t() (instead it has "Bearbeiten" as a correct German translation).

(optionally)
5. apply patch
6. clear cache
7. "Bearbeiten" will be changed to "EditCUSTOM" correctly

Proposed resolution

Drupal.t() should respect the string overrides.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ducdebreme’s picture

subscribing

checker’s picture

Does anyone know if this bug is in d7?

checker’s picture

checker’s picture

I reviewed the drupal core code around javascript string translations. I think the reason that it does not work with Drupal.t() is to find in function _locale_rebuild_js() @/includes/locale.inc. There is only a db query to fetch all strings and no including of custom_strings. You can see in function t() @/includes/common.inc how to invoke custom_strings.

checker’s picture

Version: 6.16 » 6.x-dev
sgtpep’s picture

Thank you @checker for hint. Here is suggested patch.

checker’s picture

Version: 6.x-dev » 7.x-dev
acrollet’s picture

Status: Active » Needs review
FileSize
645 bytes

Patch against 7.x attached.

Status: Needs review » Needs work

The last submitted patch, drupal-drupal_t_respect_locale_custom_strings-764408-8.patch, failed testing.

David_Rothstein’s picture

Issue summary: View changes
Priority: Minor » Normal
Status: Needs work » Needs review
FileSize
707 bytes

Here's a reroll that works correctly with translation context, and fixes a code style issue also.

This probably needs tests, and need to check if it affects Drupal 8 also...

checker’s picture

Patch #10 is working.

Hey, it is possible to get this fix before this issue has its 4th birthday! ;-)

bkouchi’s picture

I had a multi-site in another language with locale custom strings and Patch #10 addressed my needs.

sammuell’s picture

Status: Needs review » Reviewed & tested by the community

Patch #10 works well

poker10’s picture

Checked per #10 and if I have not missed anything, this seem to affect also D9, as the code is practically the same: https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/modules/locale/locale.module#L1248.

poker10’s picture

Title: Drupal.t() does not respect locale_custom_strings » [D7] Drupal.t() does not respect locale_custom_strings
Status: Reviewed & tested by the community » Postponed
Parent issue: » #3383888: Drupal.t() does not respect locale_custom_strings

I have created a D10 issue: #3383888: Drupal.t() does not respect locale_custom_strings. As per backport policy, I think we need to Postpone this until that one is fixed. We can probably use the similar approach in the D10 patch, but the test will be needed for sure. Thanks!

poker10’s picture

D10 issue was committed, therefore I think we are good to go here in D7 as well.

We just needed to add a new test for this (see the D10 commit: https://git.drupalcode.org/project/drupal/-/commit/0e6eec0727d1813373807...).

Uploading a test-only patch (with the new test added) and patch with fix+test.

I have also updated the IS with manual steps to reproduce this.

The last submitted patch, 16: 764408-16_test-only.patch, failed testing. View results

poker10’s picture

Issue summary: View changes
Issue tags: +Pending Drupal 7 commit
Fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC!

Straightforward fix!

  • mcdruid committed 7bfe25f6 on 7.x
    Issue #764408 by poker10, sgtpep, acrollet, David_Rothstein, checker,...
mcdruid’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit

Thanks everyone!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.