-
Notifications
You must be signed in to change notification settings - Fork 796
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
Fix blocks missing translations in simple sites #33190
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: fixed | ||
|
||
Fix version mismatch |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: fixed | ||
|
||
Fix version mismatch |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: bugfix | ||
|
||
Fix blocks title and description not localized |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 3, | ||
"apiVersion": 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the changes brought to |
||
"name": "jetpack/business-hours", | ||
"title": "Business Hours", | ||
"description": "Display opening hours for your business.", | ||
"keywords": ["opening hours", "closing time", "schedule", "working day"], | ||
"keywords": [ "opening hours", "closing time", "schedule", "working day" ], | ||
"version": "12.5.0", | ||
"textdomain": "jetpack", | ||
"category": "grow", | ||
|
@@ -22,7 +22,7 @@ | |
"fontSize": true, | ||
"lineHeight": true | ||
}, | ||
"align": ["wide", "full"] | ||
"align": [ "wide", "full" ] | ||
}, | ||
"attributes": { | ||
"days": { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,8 +6,11 @@ import { | |||||
} from '@automattic/jetpack-shared-extension-utils'; | ||||||
import { registerBlockType } from '@wordpress/blocks'; | ||||||
import { addFilter } from '@wordpress/hooks'; | ||||||
import { _x } from '@wordpress/i18n'; | ||||||
|
||||||
const JETPACK_PREFIX = 'jetpack/'; | ||||||
const LOCALIZED_BLOCK_PROPERTIES = [ 'title', 'description', 'keywords' ]; | ||||||
const DEFAULT_TEXTDOMAIN = 'jetpack'; | ||||||
|
||||||
/** | ||||||
* Registers a gutenberg block if the availability requirements are met. | ||||||
|
@@ -59,6 +62,24 @@ export default function registerJetpackBlock( name, settings, childBlocks = [], | |||||
return result; | ||||||
} | ||||||
|
||||||
// Localize properties passed as parameter when applicable. | ||||||
// Note: the documentation states that `registerBlockType` wraps localized properties in `_x` | ||||||
// when it is passed the metadata object as the first param. I haven't found this to be true | ||||||
// with the latest version of `@wordpress/blocks` (12.18.0) at the time of writing this. | ||||||
// https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#javascript | ||||||
const localizeBlockProperties = ( metadata, props ) => { | ||||||
const result = { ...props }; | ||||||
|
||||||
for ( const prop in props ) { | ||||||
if ( LOCALIZED_BLOCK_PROPERTIES.includes( prop ) ) { | ||||||
// eslint-disable-next-line | ||||||
result[ prop ] = _x( props[ prop ], null, metadata.textdomain || DEFAULT_TEXTDOMAIN ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (most of this is already known to the people involved via Slack discussions, but to close the loop I'll repeat it here) I think this only accidentally works if your translation files still have the translations from jetpack/projects/plugins/jetpack/extensions/blocks/business-hours/index.js Lines 76 to 77 in 427e370
WordPress intends for the translation to happen on the PHP side during block registration (here), then the already-translated texts are sent to JS via a generated call to That PHP code path is only reached when using |
||||||
} | ||||||
} | ||||||
|
||||||
return result; | ||||||
}; | ||||||
|
||||||
/** | ||||||
* Wrapper around registerJetpackBlock to register a block by specifying its metadata. | ||||||
* | ||||||
|
@@ -69,20 +90,25 @@ export default function registerJetpackBlock( name, settings, childBlocks = [], | |||||
* @returns {object|boolean} Either false if the block is not available, or the results of `registerBlockType` | ||||||
*/ | ||||||
export function registerJetpackBlockFromMetadata( metadata, settings, childBlocks, prefix ) { | ||||||
const clientSettings = { | ||||||
const mergedSettings = { | ||||||
...metadata, | ||||||
...settings, | ||||||
}; | ||||||
const processedSettings = { | ||||||
...localizeBlockProperties( metadata, mergedSettings ), | ||||||
icon: getBlockIconProp( metadata ), | ||||||
}; | ||||||
|
||||||
const { variations } = metadata; | ||||||
|
||||||
if ( Array.isArray( variations ) && variations.length > 0 ) { | ||||||
clientSettings.variations = variations.map( variation => { | ||||||
processedSettings.variations = variations.map( variation => { | ||||||
return { | ||||||
...variation, | ||||||
...localizeBlockProperties( metadata, variation ), | ||||||
icon: getBlockIconProp( variation ), | ||||||
}; | ||||||
} ); | ||||||
} | ||||||
|
||||||
return registerJetpackBlock( metadata.name, clientSettings, childBlocks, prefix ); | ||||||
return registerJetpackBlock( metadata.name, processedSettings, childBlocks, prefix ); | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: changed | ||
Comment: Updated composer.lock. | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metadata are added to settings in
registerJetpackBlockFromMetadata
anyway.