I am using Drupal 9 and Laravel-mix for the front end setup.

In my JS file I tried to translate the sting with Drupal.t('the string');

The string can't be found in the Translate UI if I use yarn build. It's working properly when use yarn watch.

In the generated JS (after yarn build) Drupal.t('the string'); is converted to a=t.t('the string'); and I gueess that's why Drupal can't translate the string.

Any idea how can be resovled this issue?

package.json file

  "scripts": {
    "watch": "npm run development -- --watch",
    "build": "npm run production",
    "development": "cross-env NODE_ENV=development webpack --progress --hide-modules --config=webpack.config.js",
    "production": "cross-env NODE_ENV=production webpack --no-progress --hide-modules --config=webpack.config.js"
  "devDependencies": {
    "bootstrap-sass": "^3.4.1",
    "cross-env": "^7.0.3",
    "laravel-mix": "^5.0.5",
    "resolve-url-loader": "^3.1.0",
    "sass": "1.32.13",
    "sass-loader": "^8.0.2",
    "vue-template-compiler": "^2.6.14"
  "dependencies": {
    "slick-carousel": "^1.8.1",
    "sticky-sidebar": "^3.3.1",
    "webpack": "^5.73.0"

webpack.config.js file

const mix = require("laravel-mix/src/index")
const ComponentFactory = require("laravel-mix/src/components/ComponentFactory")
new ComponentFactory().installAll()
Mix.dispatch("init", Mix)
const WebpackConfig = require("laravel-mix/src/builder/WebpackConfig")
module.exports = new WebpackConfig().build()
  • and what is Drupal refeering to in your script ?? Drupal.t is only available if the Drupal instance serves this in a behavior. Other decoupled "frameworks" will provide other path's to Drupals translations ... You use two incompatible softwares, instead of laravel-mix you should try fe. contentful - see drupal.org/docs/develop/decoupled-drupal/… OR druxtjs.org OR gatsbyjs.com/guides/drupal OR .... a nice guide can be found here reactfordrupal.com/react-and-drupal-series
    – rémy
    Jun 23 at 18:39
  • Welcome to Drupal Answers! Outside Drupal, Drupal.t() isn't available and it doesn't work. Are you using Drupal.t() in a JavaScript file that is used in a Drupal module? If this is the case, you should show that file, or we cannot tell you what is wrong.
    – apaderno
    Jun 24 at 18:35


Browse other questions tagged or ask your own question.