Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add text domain option while scaffolding the block in create-block #57197

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
gziolo marked this conversation as resolved.
Show resolved Hide resolved
],
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
Loading