Loading core/modules/locale/locale.module +9 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Installer\InstallerKernel; use Drupal\Core\Link; use Drupal\Core\Site\Settings; use Drupal\Core\Url; use Drupal\Core\Asset\AttachedAssetsInterface; use Drupal\Core\Form\FormStateInterface; Loading Loading @@ -1230,6 +1231,14 @@ function _locale_rebuild_js($langcode = NULL) { $translations[$data->context][$data->source] = $data->translation; } // Include custom string overrides. $custom_strings = Settings::get('locale_custom_strings_' . $language->getId(), []); foreach ($custom_strings as $context => $strings) { foreach ($strings as $source => $translation) { $translations[$context][$source] = $translation; } } // Construct the JavaScript file, if there are translations. $data_hash = NULL; $data = $status = ''; Loading core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php +13 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\locale\Functional; use Drupal\Core\Site\Settings; use Drupal\Core\Url; use Drupal\Core\Database\Database; use Drupal\language\Entity\ConfigurableLanguage; Loading Loading @@ -310,6 +311,18 @@ public function testJavaScriptTranslation() { $this->assertFileDoesNotExist($js_file); _locale_rebuild_js($langcode); $this->assertFileExists($js_file); // Test if JavaScript translation contains a custom string override. $string_override = $this->randomMachineName(); $settings = Settings::getAll(); $settings['locale_custom_strings_' . $langcode] = ['' => [$string_override => $string_override]]; // Recreate the settings static. new Settings($settings); _locale_rebuild_js($langcode); $locale_javascripts = \Drupal::state()->get('locale.translation.javascript', []); $js_file = 'public://' . $config->get('javascript.directory') . '/' . $langcode . '_' . $locale_javascripts[$langcode] . '.js'; $content = file_get_contents($js_file); $this->assertStringContainsString('"' . $string_override . '":"' . $string_override . '"', $content); } /** Loading Loading
core/modules/locale/locale.module +9 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Installer\InstallerKernel; use Drupal\Core\Link; use Drupal\Core\Site\Settings; use Drupal\Core\Url; use Drupal\Core\Asset\AttachedAssetsInterface; use Drupal\Core\Form\FormStateInterface; Loading Loading @@ -1230,6 +1231,14 @@ function _locale_rebuild_js($langcode = NULL) { $translations[$data->context][$data->source] = $data->translation; } // Include custom string overrides. $custom_strings = Settings::get('locale_custom_strings_' . $language->getId(), []); foreach ($custom_strings as $context => $strings) { foreach ($strings as $source => $translation) { $translations[$context][$source] = $translation; } } // Construct the JavaScript file, if there are translations. $data_hash = NULL; $data = $status = ''; Loading
core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php +13 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\locale\Functional; use Drupal\Core\Site\Settings; use Drupal\Core\Url; use Drupal\Core\Database\Database; use Drupal\language\Entity\ConfigurableLanguage; Loading Loading @@ -310,6 +311,18 @@ public function testJavaScriptTranslation() { $this->assertFileDoesNotExist($js_file); _locale_rebuild_js($langcode); $this->assertFileExists($js_file); // Test if JavaScript translation contains a custom string override. $string_override = $this->randomMachineName(); $settings = Settings::getAll(); $settings['locale_custom_strings_' . $langcode] = ['' => [$string_override => $string_override]]; // Recreate the settings static. new Settings($settings); _locale_rebuild_js($langcode); $locale_javascripts = \Drupal::state()->get('locale.translation.javascript', []); $js_file = 'public://' . $config->get('javascript.directory') . '/' . $langcode . '_' . $locale_javascripts[$langcode] . '.js'; $content = file_get_contents($js_file); $this->assertStringContainsString('"' . $string_override . '":"' . $string_override . '"', $content); } /** Loading