-
Notifications
You must be signed in to change notification settings - Fork 52
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
Extract translatable strings from block.json files #163
Comments
I have just closed WordPress/gutenberg#16088 where we all agreed that Re-sharing comment from @swissspidy:
I explored building Babel plugin which takes care of converting const translatableProperties = [
'title',
'description',
'keywords',
'styles',
]; function wrapTranslatableProperty( node, name, textDomain, types ) {
if ( node.type === 'StringLiteral' && node.value ) {
node = types.callExpression(
types.identifier( '__x' ),
[
node,
types.stringLiteral( `block ${ name }` ),
textDomain !== 'default' && types.stringLiteral( textDomain ),
].filter( Boolean )
);
} else if ( node.type === 'ArrayExpression' ) {
node.elements = node.elements.map(
( elementNode ) => wrapTranslatableProperty(
elementNode,
name,
textDomain,
types
)
);
} else if ( node.type === 'ObjectExpression' ) {
node.properties.forEach( ( propertyNode ) => {
if ( propertyNode.key.name === 'label' ) {
propertyNode.value = wrapTranslatableProperty(
propertyNode.value,
name,
textDomain,
types
);
}
} );
}
return node;
} The gist of it is:
|
@gziolo Thanks for the update! How often do you think the list of translatable properties would change? It might be safer to have * What about |
The whitelist approach is perfectly fine. I don't expect to change it frequently. Only if we decide to add new fields but I don't see any reasons for that as of today. |
Thanks for the quick response! Sounds like a relatively easy thing to implement then :-) |
@swissspidy – it seems to be one of the last blockers for making |
Feature Request
Describe your use case and the problem you are facing
For supporting the next iteration of Gutenberg block development, we need to extract strings from
block.json
files.Describe the solution you'd like
wp i18n make-pot
should parseblock.json
files and extract all strings it finds with the additional context.For more information, check out:
The text was updated successfully, but these errors were encountered: