Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Implement __experimentalCreateInterpolateElement for translations. (#…
Browse files Browse the repository at this point in the history
…1736)

* Improved placeholders of translatable string

* Improved one more string

* Include wordpress element package

* Implement __experimentalCreateInterpolateElement for translations

* Dump fragments

Co-authored-by: Claudio Sanches <contato@claudiosanches.com>
  • Loading branch information
mikejolley and claudiosanches committed Feb 17, 2020
1 parent f00c115 commit 5d77a1a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 38 deletions.
79 changes: 42 additions & 37 deletions assets/js/blocks/reviews/edit-utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* External dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { Fragment, RawHTML } from '@wordpress/element';
import { escapeHTML } from '@wordpress/escape-html';
import { __ } from '@wordpress/i18n';
import { __experimentalCreateInterpolateElement } from 'wordpress-element';
import {
Notice,
ToggleControl,
Expand Down Expand Up @@ -36,7 +35,7 @@ export const getBlockControls = ( editMode, setAttributes ) => (

export const getSharedReviewContentControls = ( attributes, setAttributes ) => {
return (
<Fragment>
<>
<ToggleControl
label={ __( 'Product rating', 'woo-gutenberg-products-block' ) }
checked={ attributes.showReviewRating }
Expand All @@ -51,21 +50,24 @@ export const getSharedReviewContentControls = ( attributes, setAttributes ) => {
className="wc-block-reviews__notice"
isDismissible={ false }
>
<RawHTML>
{ sprintf(
escapeHTML(
/* translators: A notice that links to WooCommerce settings. */
__(
'Product rating is disabled in your %sstore settings%s.',
'woo-gutenberg-products-block'
)
{ __experimentalCreateInterpolateElement(
__(
'Product rating is disabled in your <a>store settings</a>.',
'woo-gutenberg-products-block'
),
{
a: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
href={ getAdminLink(
'admin.php?page=wc-settings&tab=products'
) }
target="_blank"
rel="noopener noreferrer"
/>
),
`<a href="${ getAdminLink(
'admin.php?page=wc-settings&tab=products'
) }" target="_blank">`,
'</a>'
) }
</RawHTML>
}
) }
</Notice>
) }
<ToggleControl
Expand Down Expand Up @@ -105,7 +107,7 @@ export const getSharedReviewContentControls = ( attributes, setAttributes ) => {
}
/>
{ attributes.showReviewImage && (
<Fragment>
<>
<ToggleButtonControl
label={ __(
'Review image',
Expand Down Expand Up @@ -137,26 +139,29 @@ export const getSharedReviewContentControls = ( attributes, setAttributes ) => {
className="wc-block-reviews__notice"
isDismissible={ false }
>
<RawHTML>
{ sprintf(
escapeHTML(
/* translators: A notice that links to WordPress settings. */
__(
'Reviewer photo is disabled in your %ssite settings%s.',
'woo-gutenberg-products-block'
)
{ __experimentalCreateInterpolateElement(
__(
'Reviewer photo is disabled in your <a>site settings</a>.',
'woo-gutenberg-products-block'
),
{
a: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
href={ getAdminLink(
'options-discussion.php'
) }
target="_blank"
rel="noopener noreferrer"
/>
),
`<a href="${ getAdminLink(
'options-discussion.php'
) }" target="_blank">`,
'</a>'
) }
</RawHTML>
}
) }
</Notice>
) }
</Fragment>
</>
) }
</Fragment>
</>
);
};

Expand All @@ -165,7 +170,7 @@ export const getSharedReviewListControls = ( attributes, setAttributes ) => {
const maxPerPage = 20;

return (
<Fragment>
<>
<ToggleControl
label={ __( 'Order by', 'woo-gutenberg-products-block' ) }
checked={ attributes.showOrderby }
Expand Down Expand Up @@ -219,6 +224,6 @@ export const getSharedReviewListControls = ( attributes, setAttributes ) => {
min={ minPerPage }
/>
) }
</Fragment>
</>
);
};
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
"react-number-format": "4.3.1",
"trim-html": "0.1.9",
"use-debounce": "3.3.0",
"wordpress-components": "npm:@wordpress/components@8.5.0"
"wordpress-components": "npm:@wordpress/components@8.5.0",
"wordpress-element": "npm:@wordpress/element@2.11.0"
},
"husky": {
"hooks": {
Expand Down

0 comments on commit 5d77a1a

Please sign in to comment.