-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helper to catch errors for interpolated strings
- Loading branch information
Showing
5 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createInterpolateElement } from "@wordpress/element"; | ||
import { sprintf } from "@wordpress/i18n"; | ||
|
||
/** | ||
* Create an interpolated element from a translated string and catches errors. | ||
* | ||
* @param {string} translatedString The translated string to be interpolated. | ||
* @param {[string]} args The arguments to be interpolated into the translated string. | ||
* @param {object} conversionMap The conversion map for the interpolated values. | ||
* | ||
* @returns {object} The interpolated element. | ||
*/ | ||
export const i18nCreateInterpolateElement = ( translatedString, args, conversionMap ) => { | ||
try { | ||
return createInterpolateElement( | ||
sprintf( | ||
translatedString, | ||
...args | ||
), conversionMap ); | ||
} catch ( error ) { | ||
console.error( "Error in translation for:", translatedString ); | ||
return translatedString; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters