npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

drupal-translations-webpack-plugin

v1.1.1

Published

Extract Drupal.t and Drupal.formatPlural from your webpack builds.

Downloads

562

Readme

DrupalTranslationsWebpackPlugin

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.

Install

The plugin is available on npm:

npm install --save-dev drupal-translations-webpack-plugin

How to use

Add the plugin to your webpack config

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:

https://github.com/dulnan/drupal-webpack-setup-example