Skip to content

Instantly share code, notes, and snippets.

@Elendev
Last active May 15, 2018 08:47
Show Gist options
  • Select an option

  • Save Elendev/749738c59de503e6af4d16a23cf5e177 to your computer and use it in GitHub Desktop.

Select an option

Save Elendev/749738c59de503e6af4d16a23cf5e177 to your computer and use it in GitHub Desktop.
Medium : Drupal 8, Typescript, React and i18n - locale.module
/**
* Implements hook_js_alter().
*/
function locale_js_alter(&$javascript, AttachedAssetsInterface $assets) {
// ...
// Replace the placeholder file with the actual JS translation file.
$placeholder_file = 'core/modules/locale/locale.translation.js';
if (isset($javascript[$placeholder_file])) {
if ($translation_file = locale_js_translate($files)) {
$js_translation_asset = &$javascript[$placeholder_file];
$js_translation_asset['data'] = $translation_file;
// @todo Remove this when https://www.drupal.org/node/1945262 lands.
// Decrease the weight so that the translation file is loaded first.
$js_translation_asset['weight'] = $javascript['core/misc/drupal.js']['weight'] - 0.001;
}
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment