/**
 * Parse comment to target language
 */ export default function parseComment ( options ) { const { comment , targetLanguage = 'zh-cn' , skip = [ ] } = options ; const splitLabel = `${ Math . random ( ) }` ; Object . entries ( comment ) . forEach ( ( [ key , value ] ) => { if ( key === 'children' ) { comment [ key ] = value . map ( ( v ) => parseComment ( { ... options , comment : v } ) ) ; return ; } if ( typeof value === 'string' && skip . indexOf ( key ) === - 1 ) { const stringList = value . replace ( /\n([a-z]{2}-[A-Z]{2})[:：]/g , ( _ , $1 ) => `${ splitLabel }${ $1 }` ) . split ( splitLabel ) ; let length = stringList . length ; if ( length > 1 ) { while ( length -- ) { const str = stringList [ length ] ; const regExp = new RegExp ( `^${ targetLanguage }` , 'i' ) ; if ( regExp . test ( str ) ) { comment [ key ] = str . replace ( regExp , '' ) . replace ( /^:\s*|\s*\n$/g , '' ) . replace ( /\n/g , '\\n' ) ; return ; } } } } } ) ; return comment ; }