@wordpress/babel-plugin-makepot 4.3.2 → 5.0.1-next.957ca95e4c.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.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/index.js +31 -27
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Install the module:
|
|
|
21
21
|
npm install @wordpress/babel-plugin-makepot --save-dev
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
**Note**: This package requires Node.js
|
|
24
|
+
**Note**: This package requires Node.js 14.0.0 or later. It is not compatible with older versions.
|
|
25
25
|
|
|
26
26
|
## Contributing to this package
|
|
27
27
|
|
package/index.js
CHANGED
|
@@ -33,16 +33,7 @@
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
const { po } = require( 'gettext-parser' );
|
|
36
|
-
const {
|
|
37
|
-
pick,
|
|
38
|
-
reduce,
|
|
39
|
-
uniq,
|
|
40
|
-
forEach,
|
|
41
|
-
sortBy,
|
|
42
|
-
isEqual,
|
|
43
|
-
merge,
|
|
44
|
-
isEmpty,
|
|
45
|
-
} = require( 'lodash' );
|
|
36
|
+
const { pick, reduce, forEach, isEqual, merge, isEmpty } = require( 'lodash' );
|
|
46
37
|
const { relative, sep } = require( 'path' );
|
|
47
38
|
const { writeFileSync } = require( 'fs' );
|
|
48
39
|
|
|
@@ -197,6 +188,20 @@ function isSameTranslation( a, b ) {
|
|
|
197
188
|
);
|
|
198
189
|
}
|
|
199
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Sorts multiple translation objects by their reference.
|
|
193
|
+
* The reference is where they occur, in the format `file:line`.
|
|
194
|
+
*
|
|
195
|
+
* @param {Array} translations Array of translations to sort.
|
|
196
|
+
*
|
|
197
|
+
* @return {Array} Sorted translations.
|
|
198
|
+
*/
|
|
199
|
+
function sortByReference( translations = [] ) {
|
|
200
|
+
return [ ...translations ].sort( ( a, b ) =>
|
|
201
|
+
a.comments.reference.localeCompare( b.comments.reference )
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
200
205
|
module.exports = () => {
|
|
201
206
|
const strings = {};
|
|
202
207
|
let nplurals = 2,
|
|
@@ -324,18 +329,15 @@ module.exports = () => {
|
|
|
324
329
|
( memo, file ) => {
|
|
325
330
|
for ( const context in strings[ file ] ) {
|
|
326
331
|
// Within the same file, sort translations by line.
|
|
327
|
-
const sortedTranslations =
|
|
328
|
-
strings[ file ][ context ]
|
|
329
|
-
'comments.reference'
|
|
332
|
+
const sortedTranslations = sortByReference(
|
|
333
|
+
strings[ file ][ context ]
|
|
330
334
|
);
|
|
331
335
|
|
|
332
336
|
forEach(
|
|
333
337
|
sortedTranslations,
|
|
334
338
|
( translation ) => {
|
|
335
|
-
const {
|
|
336
|
-
|
|
337
|
-
msgid,
|
|
338
|
-
} = translation;
|
|
339
|
+
const { msgctxt = '', msgid } =
|
|
340
|
+
translation;
|
|
339
341
|
if (
|
|
340
342
|
! memo.hasOwnProperty( msgctxt )
|
|
341
343
|
) {
|
|
@@ -349,16 +351,18 @@ module.exports = () => {
|
|
|
349
351
|
memo[ msgctxt ][ msgid ]
|
|
350
352
|
)
|
|
351
353
|
) {
|
|
352
|
-
translation.comments.reference =
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
.
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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' );
|
|
362
366
|
}
|
|
363
367
|
|
|
364
368
|
memo[ msgctxt ][ msgid ] = translation;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/babel-plugin-makepot",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1-next.957ca95e4c.0",
|
|
4
4
|
"description": "WordPress Babel internationalization (i18n) plugin.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"url": "https://github.com/WordPress/gutenberg/issues"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
24
|
+
"node": ">=14"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"index.js"
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "272a74bbbaab10ee24424eafe9578e705fbfbbb4"
|
|
41
41
|
}
|