Problem/Motivation

This is a D10 issue from #764408: [D7] Drupal.t() does not respect locale_custom_strings.

It is possible to define locale_custom_strings_XX in settings.php to override specific string translations.

* String overrides:
*
* To override specific strings on your site with or without enabling the Locale
* module, add an entry to this list. This functionality allows you to change
* a small number of your site's default English language interface strings.

This is working for strings translated via t(), but if a string is being translated via Drupal.t() in javascript, the override is not respected and has no effect.

I think that Drupal.t() should also respect 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:

 $settings['locale_custom_strings_de'][''] = [
   'Label' => 'LabelCUSTOM',
   'Edit' => 'EditCUSTOM',
  'List additional actions' => 'Additional actions ACTIONS!',
 ];

3. Go to /de/admin/structure/types/manage/page/fields/add-field
4. You can see the "Label" and "Edit" strings are overriden correctly, but the "List additional actions" (in the dropbutton) is not, as this is coming from Drupal.t() (instead it has "Bearbeiten as a correct German translation). See the screenshot.

Proposed resolution

Drupal.t() should respect the string overrides.

Remaining tasks

Write test.
Fix the issue.

User interface changes

API changes

Data model changes

Release notes snippet

Comments

poker10 created an issue. See original summary.

poker10’s picture

Issue summary: View changes

Updated the IS.

poker10’s picture

Status: Active » Needs work
StatusFileSize
new1.01 KB

Something like this should fix the issue (based on D7 patch). But tests are still needed I think (so keeping at NW).

poker10’s picture

Status: Needs work » Needs review
Issue tags: -Need tests
StatusFileSize
new1.45 KB
new2.47 KB

Added a test for checking the custom string in the generated JS file. Uploading also test-only patch, which should hopefully fail.

The last submitted patch, 4: 3383888-4_test-only.patch, failed testing. View results

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Bug Smash Initiative

Thanks for including a test-only patch to show this is an issue!

Looking at the actual fix I don't see anything standing out that could be a problem.

Issue summary appears complete

Going to mark this.

The last submitted patch, 4: 3383888-4_test-only.patch, failed testing. View results

The last submitted patch, 4: 3383888-4_test-only.patch, failed testing. View results

The last submitted patch, 4: 3383888-4_test-only.patch, failed testing. View results

The last submitted patch, 4: 3383888-4_test-only.patch, failed testing. View results

The last submitted patch, 4: 3383888-4_test-only.patch, failed testing. View results

The last submitted patch, 4: 3383888-4_test-only.patch, failed testing. View results

  • larowlan committed a977482f on 10.1.x
    Issue #3383888 by poker10: Drupal.t() does not respect...
larowlan’s picture

Version: 11.x-dev » 10.1.x-dev
Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Tested this locally with umami install profile.

Unfortunately the steps to reproduce don't work anymore because of changes to field UI.

But you can still see it with these, so updating the issue summary:

$settings['locale_custom_strings_es'][''] = [
  'Label' => 'LabelCUSTOM',
  'Edit' => 'EditCUSTOM',
  'List additional actions' => 'Additional actions ACTIONS!',
];

Committed and pushed to 11.x
Backported to 10.0.x

Thanks folks

  • larowlan committed 0e6eec07 on 11.x
    Issue #3383888 by poker10: Drupal.t() does not respect...

Status: Fixed » Closed (fixed)

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