Skip to content

Commit a4247a4

Browse files
Merge pull request #405 from Yoast/535-add-and-implement-safecreateinterpolateelement-in-duplicate-post
use safeCreateInterpolateElement
2 parents 60793e2 + d5b6a55 commit a4247a4

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

js/src/duplicate-post-strings.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global duplicatePostStrings */
22

3-
import { createInterpolateElement } from "@wordpress/element";
3+
import { safeCreateInterpolateElement } from "./helpers/safe-create-interpolate-element";
44
import { Button } from "@wordpress/components";
55
import { __, setLocaleData } from "@wordpress/i18n";
66
import { dispatch, subscribe } from "@wordpress/data";
@@ -34,7 +34,7 @@ const republishStrings = {
3434

3535
'Are you ready to publish?' : __( 'Are you ready to republish your post?', 'duplicate-post' ),
3636
'Double-check your settings before publishing.':
37-
createInterpolateElement(
37+
safeCreateInterpolateElement(
3838
__( 'After republishing your changes will be merged into the original post and you\'ll be redirected there.<br /><br />Do you want to compare your changes with the original version before merging?<br /><br /><button>Save changes and compare</button>',
3939
'duplicate-post' ),
4040
{
@@ -49,7 +49,7 @@ const republishStrings = {
4949

5050
'Are you ready to schedule?' : __( 'Are you ready to schedule the republishing of your post?', 'duplicate-post' ),
5151
'Your work will be published at the specified date and time.':
52-
createInterpolateElement(
52+
safeCreateInterpolateElement(
5353
__( 'You\'re about to replace the original with this rewritten post at the specified date and time.<br /><br />Do you want to compare your changes with the original version before merging?<br /><br /><button>Save changes and compare</button>',
5454
'duplicate-post' ),
5555
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createInterpolateElement } from "@wordpress/element";
2+
3+
/**
4+
* Wrapper function for `createInterpolateElement` to catch errors.
5+
*
6+
* @param {string} interpolatedString The interpolated string.
7+
* @param {Object<string, JSX.Element>} conversionMap The conversion map object.
8+
* @returns {JSX.Element|string} The interpolated element or string if it failed.
9+
*/
10+
export const safeCreateInterpolateElement = ( interpolatedString, conversionMap ) => {
11+
try {
12+
return createInterpolateElement( interpolatedString, conversionMap );
13+
} catch ( error ) {
14+
console.error( "Error in translation for:", interpolatedString, error );
15+
return interpolatedString;
16+
}
17+
};

0 commit comments

Comments
 (0)