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 mechanism to translate custom page templates #28783

Closed
wants to merge 3 commits into from
Closed
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
23 changes: 13 additions & 10 deletions lib/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,19 @@ private static function get_from_file( $file_path ) {
private static function extract_paths_to_translate( $i18n_partial, $current_path = array() ) {
$result = array();
foreach ( $i18n_partial as $property => $partial_child ) {
if ( is_numeric( $property ) ) {
foreach ( $partial_child as $key => $context ) {
return array(
array(
'path' => $current_path,
'key' => $key,
'context' => $context,
),
);
}
if (
is_array( $partial_child ) &&
array_key_exists( 'key', $partial_child ) &&
array_key_exists( 'context', $partial_child )
) {
$last_key = is_numeric( $property ) ? '*' : $property;
return array(
array(
'path' => array_merge( $current_path, [ $last_key ] ),
'key' => $partial_child['key'],
'context' => $partial_child['context'],
),
);
}
$result = array_merge(
$result,
Expand Down
22 changes: 14 additions & 8 deletions lib/experimental-i18n-theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
"settings": {
"*": {
"typography": {
"fontSizes": [ { "name": "Font size name" } ],
"fontStyles": [ { "name": "Font style name" } ],
"fontWeights": [ { "name": "Font weight name" } ],
"fontFamilies": [ { "name": "Font family name" } ],
"textTransforms": [ { "name": "Text transform name" } ],
"textDecorations": [ { "name": "Text decoration name" } ]
"fontSizes": [ { "key": "name", "context": "Font size name" } ],
"fontStyles": [ { "key": "name", "context": "Font style name" } ],
"fontWeights": [ { "key": "name", "context": "Font weight name" } ],
"fontFamilies": [ { "key": "name", "context": "Font family name" } ],
"textTransforms": [ { "key": "name", "context": "Text transform name" } ],
"textDecorations": [ { "key": "name", "context": "Text decoration name" } ]
},
"color": {
"palette": [ { "name": "Color name" } ],
"gradients": [ { "name": "Gradient name" } ]
"palette": [ { "key": "name", "context": "Color name" } ],
"gradients": [ { "key": "name", "context": "Gradient name" } ]
}
}
},
"customTemplates": {
"*": {
"key": "title",
"context": "Title of the custom template"
}
}
}
21 changes: 13 additions & 8 deletions phpunit/class-wp-theme-json-resolver-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,50 @@ function test_presets_are_extracted() {

$expected = array(
array(
'path' => array( 'settings', '*', 'typography', 'fontSizes' ),
'path' => array( 'settings', '*', 'typography', 'fontSizes', '*' ),
'key' => 'name',
'context' => 'Font size name',
),
array(
'path' => array( 'settings', '*', 'typography', 'fontStyles' ),
'path' => array( 'settings', '*', 'typography', 'fontStyles', '*' ),
'key' => 'name',
'context' => 'Font style name',
),
array(
'path' => array( 'settings', '*', 'typography', 'fontWeights' ),
'path' => array( 'settings', '*', 'typography', 'fontWeights', '*' ),
'key' => 'name',
'context' => 'Font weight name',
),
array(
'path' => array( 'settings', '*', 'typography', 'fontFamilies' ),
'path' => array( 'settings', '*', 'typography', 'fontFamilies', '*' ),
'key' => 'name',
'context' => 'Font family name',
),
array(
'path' => array( 'settings', '*', 'typography', 'textTransforms' ),
'path' => array( 'settings', '*', 'typography', 'textTransforms', '*' ),
'key' => 'name',
'context' => 'Text transform name',
),
array(
'path' => array( 'settings', '*', 'typography', 'textDecorations' ),
'path' => array( 'settings', '*', 'typography', 'textDecorations', '*' ),
'key' => 'name',
'context' => 'Text decoration name',
),
array(
'path' => array( 'settings', '*', 'color', 'palette' ),
'path' => array( 'settings', '*', 'color', 'palette', '*' ),
'key' => 'name',
'context' => 'Color name',
),
array(
'path' => array( 'settings', '*', 'color', 'gradients' ),
'path' => array( 'settings', '*', 'color', 'gradients', '*' ),
'key' => 'name',
'context' => 'Gradient name',
),
array(
'path' => array( 'customTemplates', '*' ),
'key' => 'title',
'context' => 'Title of the custom template',
),
);

$this->assertEquals( $expected, $actual );
Expand Down