How to use the i18n-calypso.getLocaleSlug 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 / apps / notifications / src / panel / templates / block-user.jsx View on Github external
getTimeString = timestamp => {
		var DAY_IN_SECONDS = 3600 * 24,
			MAX_LENGTH = 15,
			parsedTime = Date.parse( timestamp ),
			momentTime,
			timeString;

		if ( isNaN( parsedTime ) ) {
			return '';
		}

		const localeSlug = getLocaleSlug();
		momentTime = moment( timestamp ).locale( localeSlug );

		if ( Date.now() - parsedTime > 1000 * DAY_IN_SECONDS * 5 ) {
			// 30 Apr 2015
			timeString = momentTime.format( 'll' );

			if ( timeString.length > MAX_LENGTH ) {
				// 2015/4/30 if 'll' is too long, e.g. "30 de abr. de 2015"
				timeString = momentTime.format( 'l' );
			}
		} else {
			// simplified units, no "ago", e.g. 7 min, 4 hours, 2 days
			timeString = momentTime.fromNow( true );
		}

		return timeString;
github Automattic / wp-calypso / client / lib / i18n-utils / utils.js View on Github external
export function localizeUrl( fullUrl, locale ) {
	const localeSlug = locale || ( typeof getLocaleSlug === 'function' ? getLocaleSlug() : 'en' );
	const urlParts = url.parse( String( fullUrl ) );

	if ( ! urlParts ) {
		return fullUrl;
	}

	// Let's unify the URL.
	urlParts.protocol = 'https';
	if ( 'en.wordpress.com' === urlParts.hostname ) {
		urlParts.host = 'wordpress.com';
	}
	if ( ! endsWith( urlParts.pathname, '.php' ) ) {
		urlParts.pathname = ( urlParts.pathname + '/' ).replace( /\/+$/, '/' );
	}

	if ( ! localeSlug || 'en' === localeSlug ) {
github Automattic / wp-calypso / client / state / stats / lists / utils.js View on Github external
export function parseUnitPeriods( unit, period ) {
	let splitYearWeek;
	const localeSlug = getLocaleSlug();

	switch ( unit ) {
		case 'week':
			splitYearWeek = period.split( '-W' );
			return moment()
				.locale( localeSlug )
				.isoWeekYear( splitYearWeek[ 0 ] )
				.isoWeek( splitYearWeek[ 1 ] )
				.endOf( 'isoWeek' );
		case 'month':
			return moment( period, 'YYYY-MM' )
				.locale( localeSlug )
				.endOf( 'month' );
		case 'year':
			return moment( period, 'YYYY' )
				.locale( localeSlug )
github Automattic / wp-calypso / client / lib / wporg / index.js View on Github external
function getWporgLocaleCode() {
	const currentLocaleCode = i18n.getLocaleSlug();
	let wpOrgLocaleCode = find( languages, { langSlug: currentLocaleCode } ).wpLocale;

	if ( wpOrgLocaleCode === '' ) {
		wpOrgLocaleCode = currentLocaleCode;
	}

	return wpOrgLocaleCode;
}
github Automattic / wp-calypso / client / lib / i18n-utils / empathy-mode.js View on Github external
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;
		}
github Automattic / wp-calypso / client / lib / human-date / index.js View on Github external
export default function humanDate(
	dateOrMoment,
	dateFormat = 'll',
	locale = i18n.getLocaleSlug()
) {
	const now = moment().locale( locale );
	dateOrMoment = moment( dateOrMoment ).locale( locale );

	let millisAgo = now.diff( dateOrMoment );
	if ( millisAgo < 0 ) {
		millisAgo = 0;
	}

	if ( millisAgo < MILLIS_IN_MINUTE ) {
		return i18n.translate( 'just now' );
	}

	if ( millisAgo < MILLIS_IN_MINUTE * 60 ) {
		const minutes = Math.ceil( millisAgo / MILLIS_IN_MINUTE );
		return i18n.translate( '%(minutes)dm ago', {
github Automattic / wp-calypso / client / signup / navigation-link / index.jsx View on Github external
return this.props.backUrl;
		}

		const previousStep = this.getPreviousStep();

		const stepSectionName = get(
			this.props.signupProgress,
			[ previousStep.stepName, 'stepSectionName' ],
			''
		);

		return getStepUrl(
			previousStep.lastKnownFlow || this.props.flowName,
			previousStep.stepName,
			stepSectionName,
			getLocaleSlug()
		);
	}
github Automattic / delphin / app / components / ui / language-picker / index.js View on Github external
getCurrentLanguage() {
		return find( config( 'languages' ), { langSlug: i18n.getLocaleSlug() } );
	}
github Automattic / delphin / app / lib / translate / index.js View on Github external
export const shouldTranslateWord = word => i18n.getLocaleSlug() !== config( 'i18n_default_locale_slug' ) || ! isRomanAlphabetWord( word );