lib/index.js
function normalizeTranslateArguments( args ) {
	var original = args[ 0 ],
		options = {},
		i;

	// warn about older deprecated syntax
	if ( typeof original !== 'string' || args.length > 3 || ( args.length > 2 && typeof args[ 1 ] === 'object' && typeof args[ 2 ] === 'object' ) ) {
		warn( 'Deprecated Invocation: `translate()` accepts ( string, [string], [object] ). These arguments passed:', simpleArguments( args ), '. See https://github.com/Automattic/i18n-calypso#translate-method' );
	}
	if ( args.length === 2 && typeof original === 'string' && typeof args[ 1 ] === 'string' ) {
		warn( 'Invalid Invocation: `translate()` requires an options object for plural translations, but passed:', simpleArguments( args ) );
	}

	// options could be in position 0, 1, or 2
	// sending options as the first object is deprecated and will raise a warning
	for ( i = 0; i < args.length; i++ ) {
		if ( typeof args[ i ] === 'object' ) {
			options = args[ i ];
		}
	}

	// `original` can be passed as first parameter or as part of the options object
	// though passing original as part of the options is a deprecated approach and will be removed
	if ( typeof original === 'string' ) {
		options.original = original;
	} else if ( typeof options.original === 'object' ) {
		options.plural = options.original.plural;
		options.count = options.original.count;
		options.original = options.original.single;
	}
	if ( typeof args[ 1 ] === 'string' ) {
		options.plural = args[ 1 ];
	}

	if ( typeof options.original === 'undefined' ) {
		throw new Error( 'Translate called without a `string` value as first argument.' );
	}

	return options;
}
function normalizeTranslateArguments( args ) {
	var original = args[ 0 ],
		options = {},
		i;

	// warn about older deprecated syntax
	if ( typeof original !== 'string' || args.length > 3 || ( args.length > 2 && typeof args[ 1 ] === 'object' && typeof args[ 2 ] === 'object' ) ) {
		warn( 'Deprecated Invocation: `translate()` accepts ( string, [string], [object] ). These arguments passed:', simpleArguments( args ), '. See https://github.com/Automattic/i18n-calypso#translate-method' );
	}
	if ( args.length === 2 && typeof original === 'string' && typeof args[ 1 ] === 'string' ) {
		warn( 'Invalid Invocation: `translate()` requires an options object for plural translations, but passed:', simpleArguments( args ) );
	}

	// options could be in position 0, 1, or 2
	// sending options as the first object is deprecated and will raise a warning
	for ( i = 0; i < args.length; i++ ) {
		if ( typeof args[ i ] === 'object' ) {
			options = args[ i ];
		}
	}

	// `original` can be passed as first parameter or as part of the options object
	// though passing original as part of the options is a deprecated approach and will be removed
	if ( typeof original === 'string' ) {
		options.original = original;
	} else if ( typeof options.original === 'object' ) {
		options.plural = options.original.plural;
		options.count = options.original.count;
		options.original = options.original.single;
	}
	if ( typeof args[ 1 ] === 'string' ) {
		options.plural = args[ 1 ];
	}

	if ( typeof options.original === 'undefined' ) {
		throw new Error( 'Translate called without a `string` value as first argument.' );
	}

	return options;
}
function normalizeTranslateArguments ( args ) { var original = args [ 0 ] , options = { } , i ; // warn about older deprecated syntax if ( typeof original !== 'string' || args . length > 3 || ( args . length > 2 && typeof args [ 1 ] === 'object' && typeof args [ 2 ] === 'object' ) ) { warn ( 'Deprecated Invocation: `translate()` accepts ( string, [string], [object] ). These arguments passed:' , simpleArguments ( args ) , '. See https://github.com/Automattic/i18n-calypso#translate-method' ) ; } if ( args . length === 2 && typeof original === 'string' && typeof args [ 1 ] === 'string' ) { warn ( 'Invalid Invocation: `translate()` requires an options object for plural translations, but passed:' , simpleArguments ( args ) ) ; } // options could be in position 0, 1, or 2 // sending options as the first object is deprecated and will raise a warning for ( i = 0 ; i < args . length ; i ++ ) { if ( typeof args [ i ] === 'object' ) { options = args [ i ] ; } } // `original` can be passed as first parameter or as part of the options object // though passing original as part of the options is a deprecated approach and will be removed if ( typeof original === 'string' ) { options . original = original ; } else if ( typeof options . original === 'object' ) { options . plural = options . original . plural ; options . count = options . original . count ; options . original = options . original . single ; } if ( typeof args [ 1 ] === 'string' ) { options . plural = args [ 1 ] ; } if ( typeof options . original === 'undefined' ) { throw new Error ( 'Translate called without a `string` value as first argument.' ) ; } return options ; }
Coerce the possible arguments and normalize to a single object
@param  {arguments} args - arguments passed in from `translate()`
@return {object}         - a single object describing translation needs
Coerce the possible arguments and normalize to a single object