diff --git a/.eslintrc.js b/.eslintrc.js index 0f71c3660dd026..38992de398e513 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -144,6 +144,7 @@ module.exports = { 'partial', 'partialRight', 'random', + 'reduce', 'reject', 'repeat', 'reverse', diff --git a/packages/babel-plugin-makepot/index.js b/packages/babel-plugin-makepot/index.js index 2273fdb4c42647..3dc1b3ed26651d 100644 --- a/packages/babel-plugin-makepot/index.js +++ b/packages/babel-plugin-makepot/index.js @@ -33,7 +33,7 @@ */ const { po } = require( 'gettext-parser' ); -const { pick, reduce, isEqual, merge, isEmpty } = require( 'lodash' ); +const { pick, isEqual, merge, isEmpty } = require( 'lodash' ); const { relative, sep } = require( 'path' ); const { writeFileSync } = require( 'fs' ); @@ -324,50 +324,45 @@ module.exports = () => { const files = Object.keys( strings ).sort(); // Combine translations from each file grouped by context. - const translations = reduce( - files, - ( memo, file ) => { - for ( const context in strings[ file ] ) { - // Within the same file, sort translations by line. - const sortedTranslations = sortByReference( - Object.values( strings[ file ][ context ] ) - ); - - sortedTranslations.forEach( ( translation ) => { - const { msgctxt = '', msgid } = translation; - if ( ! memo.hasOwnProperty( msgctxt ) ) { - memo[ msgctxt ] = {}; - } - - // Merge references if translation already exists. - if ( - isSameTranslation( - translation, - memo[ msgctxt ][ msgid ] - ) - ) { - translation.comments.reference = [ - ...new Set( - [ - memo[ msgctxt ][ msgid ] - .comments.reference, - translation.comments - .reference, - ] - .join( '\n' ) - .split( '\n' ) - ), - ].join( '\n' ); - } - - memo[ msgctxt ][ msgid ] = translation; - } ); - } - - return memo; - }, - {} - ); + const translations = files.reduce( ( memo, file ) => { + for ( const context in strings[ file ] ) { + // Within the same file, sort translations by line. + const sortedTranslations = sortByReference( + Object.values( strings[ file ][ context ] ) + ); + + sortedTranslations.forEach( ( translation ) => { + const { msgctxt = '', msgid } = translation; + if ( ! memo.hasOwnProperty( msgctxt ) ) { + memo[ msgctxt ] = {}; + } + + // Merge references if translation already exists. + if ( + isSameTranslation( + translation, + memo[ msgctxt ][ msgid ] + ) + ) { + translation.comments.reference = [ + ...new Set( + [ + memo[ msgctxt ][ msgid ] + .comments.reference, + translation.comments.reference, + ] + .join( '\n' ) + .split( '\n' ) + ), + ].join( '\n' ); + } + + memo[ msgctxt ][ msgid ] = translation; + } ); + } + + return memo; + }, {} ); // Merge translations from individual files into headers const data = merge( {}, baseData, { translations } );