Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
install() {
// Watch for cookies changed through browser magic
// We could potentially run the filter server-side by pinging the server
// for the cookie instead of asking the browser.
if ( ! this.installed && typeof document !== 'undefined' ) {
debug( 'Installing Translation Scanner' );
registerTranslateHook( this.translationFilter.bind( this ) );
this.cookieWatcherInterval = setInterval( this.checkCookie.bind( this ), 1000 );
this.installed = true;
this.checkCookie();
}
return this;
}
export function enableLanguageEmpatyhMode() {
// wrap translations from i18n
i18n.registerTranslateHook( ( translation, options ) => {
const locale = i18n.getLocaleSlug();
if ( 'en' === locale ) {
return translation;
}
if ( i18n.hasTranslation( options.original ) ) {
if ( options.components ) {
translation = interpolateComponents( {
mixedString: options.original,
components: options.components,
} );
} else {
translation = options.original;
}
return translation;
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 );
}
locale[ key ] = [ plural ].concat( translations );
i18n.setLocale( locale );
},
isValidBrowser() {
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'