How to use the i18n-calypso.registerComponentUpdateHook function in i18n-calypso

To help you get started, we’ve selected a few i18n-calypso examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Automattic / wp-calypso / client / lib / translator-jumpstart / index.js View on Github external
if ( isMobile() ) {
			return false;
		}

		return true;
	},
};

// wrap translations from i18n
i18n.registerTranslateHook( ( translation, options ) => {
	return communityTranslatorJumpstart.wrapTranslation( options.original, translation, options );
} );

// callback when translated component changes.
// the callback is overwritten by the translator on load/unload, so we're returning it within an anonymous function.
i18n.registerComponentUpdateHook( () => {
	if ( typeof translationDataFromPage.contentChangedCallback === 'function' ) {
		return translationDataFromPage.contentChangedCallback();
	}
} );

export function trackTranslatorStatus( isTranslatorEnabled ) {
	const newSetting = isTranslatorEnabled,
		changed = _isTranslatorEnabled !== newSetting,
		tracksEvent = newSetting
			? 'calypso_community_translator_enabled'
			: 'calypso_community_translator_disabled';

	if ( changed && _isTranslatorEnabled !== undefined ) {
		debug( tracksEvent );
		analytics.tracks.recordEvent( tracksEvent, { locale: user.data.localeSlug } );
	}
github Automattic / wp-calypso / client / components / community-translator / index.jsx View on Github external
componentDidMount() {
		this.setLanguage();

		// wrap translations from i18n
		i18n.registerTranslateHook( ( translation, options ) =>
			this.wrapTranslation( options.original, translation, options )
		);

		// callback when translated component changes.
		// the callback is overwritten by the translator on load/unload, so we're returning it within an anonymous function.
		i18n.registerComponentUpdateHook( () => {} );
		i18n.on( 'change', this.refresh );
		userSettings.on( 'change', this.refresh );
	}