Skip to content

Commit

Permalink
Add text domain option while scaffolding the block in create-block (W…
Browse files Browse the repository at this point in the history
…ordPress#57197)

* 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 <[email protected]>

Co-authored-by: vampdroid <[email protected]>
Co-authored-by: gziolo <[email protected]>
Co-authored-by: ryanwelcher <[email protected]>
  • Loading branch information
4 people authored Dec 18, 2024
1 parent 5bc7972 commit d1dbd7a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/create-block/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ program
'description',
'dashicon',
'category',
'textdomain',
],
variant
).filter( filterOptionsProvided );
Expand Down
15 changes: 15 additions & 0 deletions packages/create-block/lib/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -141,6 +155,7 @@ module.exports = {
description,
dashicon,
category,
textdomain,
pluginURI,
version,
author,
Expand Down
3 changes: 2 additions & 1 deletion packages/create-block/lib/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = async (
description,
dashicon,
category,
textdomain,
attributes,
supports,
author,
Expand Down Expand Up @@ -95,7 +96,7 @@ module.exports = async (
customPackageJSON,
customBlockJSON,
example,
textdomain: slug,
textdomain: textdomain || slug,
rootDirectory,
} );

Expand Down

0 comments on commit d1dbd7a

Please sign in to comment.