@wordpress/babel-plugin-makepot 5.0.1-next.d6164808d3.0 → 5.1.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 (3) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/index.js +31 -37
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- ## 5.0.0-next.0 (2022-08-23)
5
+ ## 5.1.0 (2022-09-13)
6
+
7
+ ### Bug Fix
8
+
9
+ - Makepot: Fix translations object handling ([#43797](https://github.com/WordPress/gutenberg/pull/43797)).
10
+
11
+ ## 5.0.0 (2022-08-24)
6
12
 
7
13
  ### Breaking Change
8
14
 
package/index.js CHANGED
@@ -33,7 +33,7 @@
33
33
  */
34
34
 
35
35
  const { po } = require( 'gettext-parser' );
36
- const { pick, reduce, forEach, isEqual, merge, isEmpty } = require( 'lodash' );
36
+ const { pick, reduce, isEqual, merge, isEmpty } = require( 'lodash' );
37
37
  const { relative, sep } = require( 'path' );
38
38
  const { writeFileSync } = require( 'fs' );
39
39
 
@@ -122,7 +122,7 @@ function getExtractedComment( path, _originalNodeLine ) {
122
122
  }
123
123
 
124
124
  let comment;
125
- forEach( node.leadingComments, ( commentNode ) => {
125
+ Object.values( node.leadingComments ?? {} ).forEach( ( commentNode ) => {
126
126
  let line = 0;
127
127
  if ( commentNode && commentNode.loc && commentNode.loc.end ) {
128
128
  line = commentNode.loc.end.line;
@@ -330,44 +330,38 @@ module.exports = () => {
330
330
  for ( const context in strings[ file ] ) {
331
331
  // Within the same file, sort translations by line.
332
332
  const sortedTranslations = sortByReference(
333
- strings[ file ][ context ]
333
+ Object.values( strings[ file ][ context ] )
334
334
  );
335
335
 
336
- forEach(
337
- sortedTranslations,
338
- ( translation ) => {
339
- const { msgctxt = '', msgid } =
340
- translation;
341
- if (
342
- ! memo.hasOwnProperty( msgctxt )
343
- ) {
344
- memo[ msgctxt ] = {};
345
- }
346
-
347
- // Merge references if translation already exists.
348
- if (
349
- isSameTranslation(
350
- translation,
351
- memo[ msgctxt ][ msgid ]
352
- )
353
- ) {
354
- translation.comments.reference = [
355
- ...new Set(
356
- [
357
- memo[ msgctxt ][ msgid ]
358
- .comments.reference,
359
- translation.comments
360
- .reference,
361
- ]
362
- .join( '\n' )
363
- .split( '\n' )
364
- ),
365
- ].join( '\n' );
366
- }
367
-
368
- memo[ msgctxt ][ msgid ] = translation;
336
+ sortedTranslations.forEach( ( translation ) => {
337
+ const { msgctxt = '', msgid } = translation;
338
+ if ( ! memo.hasOwnProperty( msgctxt ) ) {
339
+ memo[ msgctxt ] = {};
369
340
  }
370
- );
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
+ } );
371
365
  }
372
366
 
373
367
  return memo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/babel-plugin-makepot",
3
- "version": "5.0.1-next.d6164808d3.0",
3
+ "version": "5.1.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": "ba8a396d2f418e53a6c4c50575582f3f3eb11ff7"
40
+ "gitHead": "0d732d4b184adcb28cc83087603e81b764390d4b"
41
41
  }