@wordpress/babel-plugin-makepot 4.4.0 → 5.0.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 +21 -16
- 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,9 +329,8 @@ 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(
|
|
@@ -347,8 +351,8 @@ module.exports = () => {
|
|
|
347
351
|
memo[ msgctxt ][ msgid ]
|
|
348
352
|
)
|
|
349
353
|
) {
|
|
350
|
-
translation.comments.reference =
|
|
351
|
-
|
|
354
|
+
translation.comments.reference = [
|
|
355
|
+
...new Set(
|
|
352
356
|
[
|
|
353
357
|
memo[ msgctxt ][ msgid ]
|
|
354
358
|
.comments.reference,
|
|
@@ -357,7 +361,8 @@ module.exports = () => {
|
|
|
357
361
|
]
|
|
358
362
|
.join( '\n' )
|
|
359
363
|
.split( '\n' )
|
|
360
|
-
)
|
|
364
|
+
),
|
|
365
|
+
].join( '\n' );
|
|
361
366
|
}
|
|
362
367
|
|
|
363
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.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": "171b87c7465b93e685e081c5f57f153507363c95"
|
|
41
41
|
}
|