diff --git a/packages/create-block/CHANGELOG.md b/packages/create-block/CHANGELOG.md index 73522a9be0726..d9b81d8509bcf 100644 --- a/packages/create-block/CHANGELOG.md +++ b/packages/create-block/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Enhancement + +- Add support for custom `textdomain` property for the scaffolded block ([#57197](https://github.com/WordPress/gutenberg/pull/57197)). + ## 4.57.0 (2024-12-11) ### Internal diff --git a/packages/create-block/lib/index.js b/packages/create-block/lib/index.js index da08bcd4ab1dc..c84e143b1a6ca 100644 --- a/packages/create-block/lib/index.js +++ b/packages/create-block/lib/index.js @@ -159,6 +159,7 @@ program 'description', 'dashicon', 'category', + 'textdomain', ], variant ).filter( filterOptionsProvided ); diff --git a/packages/create-block/lib/prompts.js b/packages/create-block/lib/prompts.js index 12da9f892b80e..625320b15c9d3 100644 --- a/packages/create-block/lib/prompts.js +++ b/packages/create-block/lib/prompts.js @@ -79,6 +79,20 @@ const category = { choices: [ 'text', 'media', 'design', 'widgets', 'theme', 'embed' ], }; +const textdomain = { + type: 'input', + name: 'textdomain', + message: + 'The text domain used to internationalize text in the block (by default it will be same as slug):', + validate( input ) { + if ( input.length && ! /^[a-z][a-z0-9\-]*$/.test( input ) ) { + return 'Invalid text domain specified. Text domain can contain only lowercase alphanumeric characters or dashes, and start with a letter.'; + } + + return true; + }, +}; + // Plugin header fields. const pluginURI = { type: 'input', @@ -141,6 +155,7 @@ module.exports = { description, dashicon, category, + textdomain, pluginURI, version, author, diff --git a/packages/create-block/lib/scaffold.js b/packages/create-block/lib/scaffold.js index 73b9f54990886..bc7cb3b8bfcd3 100644 --- a/packages/create-block/lib/scaffold.js +++ b/packages/create-block/lib/scaffold.js @@ -26,6 +26,7 @@ module.exports = async ( description, dashicon, category, + textdomain, attributes, supports, author, @@ -95,7 +96,7 @@ module.exports = async ( customPackageJSON, customBlockJSON, example, - textdomain: slug, + textdomain: textdomain || slug, rootDirectory, } );