@wordpress/babel-plugin-makepot 5.5.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +41 -49
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -33,7 +33,7 @@
33
33
  */
34
34
 
35
35
  const { po } = require( 'gettext-parser' );
36
- const { pick, reduce, isEqual, merge, isEmpty } = require( 'lodash' );
36
+ const { merge, isEmpty } = require( 'lodash' );
37
37
  const { relative, sep } = require( 'path' );
38
38
  const { writeFileSync } = require( 'fs' );
39
39
 
@@ -182,10 +182,7 @@ function isValidTranslationKey( key ) {
182
182
  * @return {boolean} Whether valid translation keys match.
183
183
  */
184
184
  function isSameTranslation( a, b ) {
185
- return isEqual(
186
- pick( a, VALID_TRANSLATION_KEYS ),
187
- pick( b, VALID_TRANSLATION_KEYS )
188
- );
185
+ return VALID_TRANSLATION_KEYS.every( ( key ) => a[ key ] === b[ key ] );
189
186
  }
190
187
 
191
188
  /**
@@ -324,50 +321,45 @@ module.exports = () => {
324
321
  const files = Object.keys( strings ).sort();
325
322
 
326
323
  // Combine translations from each file grouped by context.
327
- const translations = reduce(
328
- files,
329
- ( memo, file ) => {
330
- for ( const context in strings[ file ] ) {
331
- // Within the same file, sort translations by line.
332
- const sortedTranslations = sortByReference(
333
- Object.values( strings[ file ][ context ] )
334
- );
335
-
336
- sortedTranslations.forEach( ( translation ) => {
337
- const { msgctxt = '', msgid } = translation;
338
- if ( ! memo.hasOwnProperty( msgctxt ) ) {
339
- memo[ msgctxt ] = {};
340
- }
341
-
342
- // Merge references if translation already exists.
343
- if (
344
- isSameTranslation(
345
- translation,
346
- memo[ msgctxt ][ msgid ]
347
- )
348
- ) {
349
- translation.comments.reference = [
350
- ...new Set(
351
- [
352
- memo[ msgctxt ][ msgid ]
353
- .comments.reference,
354
- translation.comments
355
- .reference,
356
- ]
357
- .join( '\n' )
358
- .split( '\n' )
359
- ),
360
- ].join( '\n' );
361
- }
362
-
363
- memo[ msgctxt ][ msgid ] = translation;
364
- } );
365
- }
366
-
367
- return memo;
368
- },
369
- {}
370
- );
324
+ const translations = files.reduce( ( memo, file ) => {
325
+ for ( const context in strings[ file ] ) {
326
+ // Within the same file, sort translations by line.
327
+ const sortedTranslations = sortByReference(
328
+ Object.values( strings[ file ][ context ] )
329
+ );
330
+
331
+ sortedTranslations.forEach( ( translation ) => {
332
+ const { msgctxt = '', msgid } = translation;
333
+ if ( ! memo.hasOwnProperty( msgctxt ) ) {
334
+ memo[ msgctxt ] = {};
335
+ }
336
+
337
+ // Merge references if translation already exists.
338
+ if (
339
+ isSameTranslation(
340
+ translation,
341
+ memo[ msgctxt ][ msgid ]
342
+ )
343
+ ) {
344
+ translation.comments.reference = [
345
+ ...new Set(
346
+ [
347
+ memo[ msgctxt ][ msgid ]
348
+ .comments.reference,
349
+ translation.comments.reference,
350
+ ]
351
+ .join( '\n' )
352
+ .split( '\n' )
353
+ ),
354
+ ].join( '\n' );
355
+ }
356
+
357
+ memo[ msgctxt ][ msgid ] = translation;
358
+ } );
359
+ }
360
+
361
+ return memo;
362
+ }, {} );
371
363
 
372
364
  // Merge translations from individual files into headers
373
365
  const data = merge( {}, baseData, { translations } );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/babel-plugin-makepot",
3
- "version": "5.5.0",
3
+ "version": "5.7.0",
4
4
  "description": "WordPress Babel internationalization (i18n) plugin.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "511f4cc1f0138641bc4394bc1cf36e833109c791"
40
+ "gitHead": "1eb65aabe6738097f4c062e78f69ae8f05879848"
41
41
  }