Simple string overrides of Strings passed through JavaScript Drupal.t() function does not work

Created on 29 August 2018, about 6 years ago
Updated 19 October 2023, about 1 year ago

Problem/motivation

Drupal 8's settings.php suggests that for simple string overrides the following can be added to settings.php file:

/**
 * 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.
 *
 * Remove the leading hash signs to enable.
 *
 * The "en" part of the variable name, is dynamic and can be any langcode of
 * any added language. (eg locale_custom_strings_de for german).
 */
$settings['locale_custom_strings_en'][''] = array(
   'forum'      => 'Discussion board',
   '@count min' => '@count minutes',
);

Expected behaviour

Strings passed through the PHP t() function and JavaScript Drupal.t() should respect these overrides.

Actual behaviour

PHP string passed through t() function get translated but JavaScript strings translated through Drupal.t() do not use these translations.

Reading Drupal.t() its expecting a variable called drupalTranslations to exist to store these values which seems to be permanently undefined. It seems some reference is made to this drupalTranslations variable in the locale module (through a complicated block of code starting at a hook_js_alter), but enabling or disabling this module made no difference, the string overrides specified in the settings.php did not get picked up, even after multiple cache rebuilds.

πŸ› Bug report
Status

Closed: duplicate

Version

11.0 πŸ”₯

Component
LocaleΒ  β†’

Last updated 2 days ago

Created by

πŸ‡¬πŸ‡§United Kingdom johnennew

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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