How to use the i18n-calypso.setLocale 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 / delphin / client / index.js View on Github external
function init() {
	if ( window.Raven && isEnabled( 'sentry' ) ) {
		window.Raven.config( 'https://02c1c1625528468ea40a86143860cdb7@sentry.io/96319' ).install();
		// This is an experiment to send uncaught error in Promises to Sentry
		// We might want to remove it if we receive too many errors
		window.addEventListener( 'unhandledrejection', ( err ) => {
			window.Raven.captureException( err.reason );
		} );
	}

	window.switchLocale = switchLocale;

	if ( window.localeData ) {
		i18n.setLocale( window.localeData );
	}

	injectTapEventPlugin();

	// pre-load checkout chunk
	sections.checkout();
}
github Automattic / delphin / client / switch-locale.js View on Github external
function switchLocale( localeSlug ) {
	setLocaleCookie( localeSlug );

	if ( localeSlug === config( 'i18n_default_locale_slug' ) ) {
		// sets the locale back to the default
		i18n.setLocale();
		return;
	}

	request.get( languageFileUrl( localeSlug ) ).end( function( error, response ) {
		if ( error ) {
			debug( 'Encountered an error loading locale file for ' + localeSlug + '. Falling back to English.' );
			return;
		}
		i18n.setLocale( response.body );
	} );
}
github Automattic / woocommerce-services / client / lib / calypso-boot / index.js View on Github external
export default function boot() {
	// Initialize i18n mixin
	//ReactClass.injection.injectMixin( i18n.mixin );

	if ( ! window.i18nLocale ) {
		return;
	}

	const i18nLocaleStringsObject = JSON.parse( window.i18nLocale.json );
	if ( ! i18nLocaleStringsObject || ! i18nLocaleStringsObject[ '' ] ) {
		return;
	}

	i18nLocaleStringsObject[ '' ].localeSlug = window.i18nLocale.localeSlug;
	i18n.setLocale( i18nLocaleStringsObject );
}
github Automattic / wc-synchrotron / client / calypso / boot / index.js View on Github external
export default function boot() {
	let i18nLocaleStringsObject = null;

	bootDebug( 'Starting Calypso Support' );

	i18n.setLocale( window.i18nLocaleStrings );

	ReactInjection.Class.injectMixin( i18n.mixin );

	// Infer touch screen by checking if device supports touch events
	if ( touchDetect.hasTouch() ) {
		classes( document.documentElement ).add( 'touch' );
	} else {
		classes( document.documentElement ).add( 'notouch' );
	}

	// Initialize touch
	injectTapEventPlugin();
}
github Automattic / wp-calypso / client / lib / i18n-utils / switch-locale.js View on Github external
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 );

					loadUserUndeployedTranslations( targetLocaleSlug );
				}
			},
			// Failure.
github Automattic / jetpack / _inc / client / admin.js View on Github external
Initial_State.locale[ '' ].localeSlug = Initial_State.localeSlug;

	// Overloading the toLocaleString method to use the set locale
	Number.prototype.realToLocaleString = Number.prototype.toLocaleString;

	Number.prototype.toLocaleString = function( locale, options ) {
		locale = locale || Initial_State.localeSlug;
		options = options || {};

		return this.realToLocaleString( locale, options );
	};
} else {
	Initial_State.locale = { '': { localeSlug: Initial_State.localeSlug } };
}

i18n.setLocale( Initial_State.locale );

const hashHistory = useRouterHistory( createHashHistory )();

const history = syncHistoryWithStore( hashHistory, store );

// Add dispatch and actionTypes to the window object so we can use it from the browser's console
if ( 'undefined' !== typeof window && process.env.NODE_ENV === 'development' ) {
	assign( window, {
		actionTypes: actionTypes,
		dispatch: store.dispatch,
	} );
}

render();

function render() {
github Automattic / wp-calypso / client / state / ui / language / actions.js View on Github external
export const setLocaleRawData = localeData => {
	i18n.setLocale( localeData );

	const { localeSlug, localeVariant = null } = localeData[ '' ];

	return {
		type: LOCALE_SET,
		localeSlug,
		localeVariant,
	};
};
github Automattic / delphin / client / switch-locale.js View on Github external
request.get( languageFileUrl( localeSlug ) ).end( function( error, response ) {
		if ( error ) {
			debug( 'Encountered an error loading locale file for ' + localeSlug + '. Falling back to English.' );
			return;
		}
		i18n.setLocale( response.body );
	} );
}