import * as PropTypes from 'prop-types' ; import * as React from 'react' ; import { i18n } from '@kbn/i18n' ; param message function translateFormattedMessageUsingPseudoLocale ( message ) { const formattedMessageDelimiter = message . match ( /@__.{10}__@/ ) ; if ( formattedMessageDelimiter !== null ) { return message . split ( formattedMessageDelimiter [ 0 ] ) . map ( ( part ) => ( part . startsWith ( 'ELEMENT-' ) ? part : i18n . translateUsingPseudoLocale ( part ) ) ) . join ( formattedMessageDelimiter [ 0 ] ) ; } return i18n . translateUsingPseudoLocale ( message ) ; } /**
 * If the locale is our pseudo locale (e.g. en-xa), we override the
 * intl.formatMessage function to display scrambled characters. We are
 * overriding the context rather than using injectI18n, because the
 * latter creates a new React component, which causes React diffs to
 * be inefficient in some cases, and can cause React hooks to lose
 * their state.
 */ export class PseudoLocaleWrapper extends React . PureComponent { public static propTypes = { children : PropTypes . element . isRequired } ; public static contextTypes = { intl : PropTypes . object . isRequired , } ; constructor ( props , context ) { super ( props , context ) ; if ( i18n . isPseudoLocale ( i18n . getLocale ( ) ) ) { const formatMessage = context . intl . formatMessage ; context . intl . formatMessage = ( ... args ) => translateFormattedMessageUsingPseudoLocale ( formatMessage ( ... args ) ) ; } } public render ( ) { return this . props . children ; } }