示例#1
0
function potJson( done ) {
	return src( [ 'locale/*.po' ] )
		.pipe( po2json() )
		.pipe( through.obj( ( file, enc, cb ) => {
			const json = JSON.parse( String( file.contents ) );
			const keys = Object.keys( json );

			for ( let x = 0; x < keys.length; x++ ) {
				const key = keys[ x ];
				const newObj = [];

				for ( let z = 1; z < json[ key ].length; z++ ) {
					newObj.push( json[ key ][ z ] );
				}

				json[ key ] = newObj;
			}

			file.contents = new Buffer( he.decode( JSON.stringify( json ) ) );
			cb( null, file );
		} ) )
		.pipe( dest( 'locale/json/' ) )
		.on( 'end', function() {
			done();
		} );
}
示例#2
0
	} ).on( 'close', function() {

		// Extracting only the first argument to the translation function
		terms = JSON.parse( '[' + terms.join( ',' ) + ']' ).map( function( term ) {
			return term[0];
		} );

		gulp.src( [ 'languages/*.po' ] )
			.pipe( po2json() )
			.pipe( json_transform( function( data, file ) {
				var filtered = {
					'': data['']
				};

				Object.keys( data ).forEach( function( term ) {
					if ( -1 !== terms.indexOf( term ) ) {
						filtered[ term ] = data[ term ];
					}
				} );

				return filtered;
			} ) )
			.pipe( gulp.dest( 'languages/json/' ) )
			.on( 'end', done );
	} );