From d1dbd7a78c4d5bf860e43ef26fb545a8b93a9543 Mon Sep 17 00:00:00 2001 From: Yash Kukreja <55312427+vampdroid@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:22:13 +0530 Subject: [PATCH] Add text domain option while scaffolding the block in create-block (#57197) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add text domain option while scaffolding the blockin create-block * Keep slug as a default text-domain for scaffolding create block * Update CHANGELOG.md --------- Co-authored-by: Greg Ziółkowski Co-authored-by: vampdroid Co-authored-by: gziolo Co-authored-by: ryanwelcher --- packages/create-block/CHANGELOG.md | 4 ++++ packages/create-block/lib/index.js | 1 + packages/create-block/lib/prompts.js | 15 +++++++++++++++ packages/create-block/lib/scaffold.js | 3 ++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/create-block/CHANGELOG.md b/packages/create-block/CHANGELOG.md index 73522a9be0726d..d9b81d8509bcfe 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 da08bcd4ab1dc7..c84e143b1a6cac 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 12da9f892b80e6..625320b15c9d32 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 73b9f549908867..bc7cb3b8bfcd32 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, } );