
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
drupal-translations-webpack-plugin
Advanced tools
Extract Drupal.t and Drupal.formatPlural from your webpack builds.
Extract Drupal.t and Drupal.formatPlural calls from your webpack bundles.
The plugin will gather all those calls in one single file and emit them. Then you can add this file to your Drupal theme library. Drupal will pick it up and run its regex over it, so that those translations end up in the Frontend.
Compatible with Webpack 4 and 5.
The plugin is available on npm:
npm install --save-dev drupal-translations-webpack-plugin
const DrupalTranslationsWebpackPlugin = require('drupal-translations-webpack-plugin')
plugins: [
new DrupalTranslationsWebpackPlugin({
output: 'drupal-translations.js'
})
]
You can use both translation functions everywhere. But maybe you need to declare that Drupal is a global object. It worked for me without, in another project it didn't.
webpack.config.js
plugins: [
new webpack.ProvidePlugin({
'Drupal': 'window.Drupal'
})
]
Also, if you use ESLint, you want to declare Drupal a global object:
.eslintrc.js
globals: {
'Drupal': true
}
It's important that you use the functions like normal, e.g. not write window.Drupal.t
or otherwise wrap them in your own function, etc. The plugin is rather "dumb"; it will
just go through all JS files and parse out the actual "string" where the function is
called.
For a detailled example on how to use this plugin, check out this Drupal webpack example:
FAQs
Extract Drupal.t and Drupal.formatPlural from your webpack builds.
We found that drupal-translations-webpack-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.