How to use the i18n-calypso.configure 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 / i18n-utils / switch-locale.js View on Github external
// Note: i18n is a singleton that will be shared between all server requests!
	// Disable switching locale on the server
	if ( typeof document === 'undefined' ) {
		return;
	}

	const { langSlug: targetLocaleSlug, parentLangSlug } = language;

	// variant lang objects contain references to their parent lang, which is what we want to tell the browser we're running
	const domLocaleSlug = parentLangSlug || targetLocaleSlug;

	lastRequestedLocale = targetLocaleSlug;

	if ( isDefaultLocale( targetLocaleSlug ) ) {
		i18n.configure( { defaultLocaleSlug: targetLocaleSlug } );
		setLocaleInDOM( domLocaleSlug, !! language.rtl );
	} else {
		getLanguageFile( targetLocaleSlug ).then(
			// Success.
			body => {
				if ( body ) {
					// Handle race condition when we're requested to switch to a different
					// locale while we're in the middle of request, we should abandon result
					if ( targetLocaleSlug !== lastRequestedLocale ) {
						return;
					}

					i18n.setLocale( body );

					setLocaleInDOM( domLocaleSlug, !! language.rtl );