@wp-blocks/make-pot 1.0.2 → 1.2.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/README.md +18 -1
- package/lib/cli/parseCli.js +11 -12
- package/lib/cli/parseCli.js.map +1 -1
- package/lib/const.js +1 -12
- package/lib/const.js.map +1 -1
- package/lib/extractors/headers.d.ts +2 -3
- package/lib/extractors/headers.js +23 -13
- package/lib/extractors/headers.js.map +1 -1
- package/lib/extractors/index.d.ts +2 -2
- package/lib/extractors/index.js +15 -25
- package/lib/extractors/index.js.map +1 -1
- package/lib/extractors/json.d.ts +3 -2
- package/lib/extractors/json.js +17 -30
- package/lib/extractors/json.js.map +1 -1
- package/lib/extractors/schema.d.ts +73 -2
- package/lib/extractors/schema.js +31 -52
- package/lib/extractors/schema.js.map +1 -1
- package/lib/extractors/text.js +3 -4
- package/lib/extractors/text.js.map +1 -1
- package/lib/extractors/utils.d.ts +4 -4
- package/lib/extractors/utils.js +17 -16
- package/lib/extractors/utils.js.map +1 -1
- package/lib/fs/glob.d.ts +2 -2
- package/lib/fs/glob.js +9 -21
- package/lib/fs/glob.js.map +1 -1
- package/lib/fs/index.js +2 -13
- package/lib/fs/index.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/parser/exec.d.ts +0 -1
- package/lib/parser/exec.js +38 -60
- package/lib/parser/exec.js.map +1 -1
- package/lib/parser/index.d.ts +2 -2
- package/lib/parser/index.js +25 -19
- package/lib/parser/index.js.map +1 -1
- package/lib/parser/patterns.js +6 -7
- package/lib/parser/patterns.js.map +1 -1
- package/lib/parser/process.d.ts +4 -5
- package/lib/parser/process.js +25 -57
- package/lib/parser/process.js.map +1 -1
- package/lib/parser/progress.d.ts +3 -0
- package/lib/parser/progress.js +21 -0
- package/lib/parser/progress.js.map +1 -0
- package/lib/parser/taskRunner.d.ts +4 -0
- package/lib/parser/taskRunner.js +33 -0
- package/lib/parser/taskRunner.js.map +1 -0
- package/lib/parser/tree.d.ts +2 -2
- package/lib/parser/tree.js +40 -23
- package/lib/parser/tree.js.map +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +7 -2
- package/lib/utils/index.js.map +1 -1
- package/package.json +16 -3
- package/tests/extract.test.ts +95 -104
- package/tests/getFiles.test.ts +114 -114
- package/tests/ignoreFunction.test.ts +102 -126
- package/tests/tree.test.ts +6 -7
- package/tsconfig.json +3 -3
- package/lib/cliArgs.d.ts +0 -4
- package/lib/cliArgs.js +0 -216
- package/lib/cliArgs.js.map +0 -1
- package/lib/consolidate.d.ts +0 -2
- package/lib/consolidate.js +0 -37
- package/lib/consolidate.js.map +0 -1
- package/lib/fs.d.ts +0 -2
- package/lib/fs.js +0 -69
- package/lib/fs.js.map +0 -1
- package/lib/glob.d.ts +0 -13
- package/lib/glob.js +0 -95
- package/lib/glob.js.map +0 -1
- package/lib/makePot.d.ts +0 -2
- package/lib/makePot.js +0 -83
- package/lib/makePot.js.map +0 -1
- package/lib/maps.d.ts +0 -122
- package/lib/maps.js +0 -73
- package/lib/maps.js.map +0 -1
- package/lib/parser/consolidate.d.ts +0 -2
- package/lib/parser/consolidate.js +0 -37
- package/lib/parser/consolidate.js.map +0 -1
- package/lib/parser/makePot.d.ts +0 -2
- package/lib/parser/makePot.js +0 -35
- package/lib/parser/makePot.js.map +0 -1
- package/lib/parser.d.ts +0 -6
- package/lib/parser.js +0 -110
- package/lib/parser.js.map +0 -1
- package/lib/tree.d.ts +0 -2
- package/lib/tree.js +0 -78
- package/lib/tree.js.map +0 -1
- package/lib/utils.d.ts +0 -8
- package/lib/utils.js +0 -78
- package/lib/utils.js.map +0 -1
- package/tests/consolidate.test.ts +0 -77
- package/tests/getStrings.test.ts +0 -85
- /package/{LICENSE.md → LICENSE} +0 -0
- /package/tests/{jsonParse.test.ts → jsonParse.ts} +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initProgress = void 0;
|
|
7
|
+
const cli_progress_1 = __importDefault(require("cli-progress"));
|
|
8
|
+
function initProgress(args, filesCount) {
|
|
9
|
+
if (args.options?.silent)
|
|
10
|
+
return undefined;
|
|
11
|
+
const progressBar = new cli_progress_1.default.SingleBar({
|
|
12
|
+
clearOnComplete: true,
|
|
13
|
+
etaBuffer: 1000,
|
|
14
|
+
hideCursor: true,
|
|
15
|
+
format: ' {bar} {percentage}% | ETA: {eta}s | {filename} | {value}/{total}',
|
|
16
|
+
}, cli_progress_1.default.Presets.shades_classic);
|
|
17
|
+
progressBar.start(filesCount, 0);
|
|
18
|
+
return progressBar;
|
|
19
|
+
}
|
|
20
|
+
exports.initProgress = initProgress;
|
|
21
|
+
//# sourceMappingURL=progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.js","sourceRoot":"","sources":["../../src/parser/progress.ts"],"names":[],"mappings":";;;;;;AACA,gEAAqD;AASrD,SAAgB,YAAY,CAC3B,IAAU,EACV,UAAkB;IAElB,IAAI,IAAI,CAAC,OAAO,EAAE,MAAM;QAAE,OAAO,SAAS,CAAA;IAE1C,MAAM,WAAW,GAAG,IAAI,sBAAW,CAAC,SAAS,CAC5C;QACC,eAAe,EAAE,IAAI;QACrB,SAAS,EAAE,IAAI;QACf,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,mEAAmE;KAC3E,EACD,sBAAW,CAAC,OAAO,CAAC,cAAc,CAClC,CAAA;IAED,WAAW,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA;IAGhC,OAAO,WAAW,CAAA;AACnB,CAAC;AApBD,oCAoBC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SetOfBlocks } from 'gettext-merger';
|
|
2
|
+
import { Args } from '../types';
|
|
3
|
+
import { SingleBar } from 'cli-progress';
|
|
4
|
+
export declare function taskRunner(tasks: Promise<SetOfBlocks>[], destination: SetOfBlocks, args: Args, progressBar?: SingleBar): Promise<SetOfBlocks>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.taskRunner = void 0;
|
|
4
|
+
async function taskRunner(tasks, destination, args, progressBar) {
|
|
5
|
+
await Promise.allSettled(tasks)
|
|
6
|
+
.then((strings) => {
|
|
7
|
+
return strings
|
|
8
|
+
.map((block) => block.status === 'fulfilled' && block.value)
|
|
9
|
+
.filter(Boolean);
|
|
10
|
+
})
|
|
11
|
+
.then((consolidated) => {
|
|
12
|
+
consolidated.forEach((result) => {
|
|
13
|
+
if (result.blocks.length > 0) {
|
|
14
|
+
destination.addArray(result.blocks);
|
|
15
|
+
console.log('✅ ' + result.path + ' [', result.blocks.map((b) => b.msgid).join(', '), ']');
|
|
16
|
+
}
|
|
17
|
+
else
|
|
18
|
+
console.log('❌ ', result.path + ' has no strings');
|
|
19
|
+
});
|
|
20
|
+
progressBar?.stop();
|
|
21
|
+
})
|
|
22
|
+
.catch((err) => {
|
|
23
|
+
console.log('❌ Failed!', err);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
});
|
|
26
|
+
if (!args.options?.silent) {
|
|
27
|
+
console.log('🎉 Done!');
|
|
28
|
+
console.log('📝 Found', Object.values(destination.blocks).length, 'translation strings in', args.paths.cwd);
|
|
29
|
+
}
|
|
30
|
+
return destination;
|
|
31
|
+
}
|
|
32
|
+
exports.taskRunner = taskRunner;
|
|
33
|
+
//# sourceMappingURL=taskRunner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taskRunner.js","sourceRoot":"","sources":["../../src/parser/taskRunner.ts"],"names":[],"mappings":";;;AAYO,KAAK,UAAU,UAAU,CAC/B,KAA6B,EAC7B,WA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AC,GAAG,CACV,UAAU,EACV,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,EACxC,wBAAwB,EACxB,IAAI,CAAC,KAAK,CAAC,GAAG,CACd,CAAA;IACF,CAAC;IAED,OAAO,WAAW,CAAA;AACnB,CAAC;AAjDD,gCAiDC"}
|
package/lib/parser/tree.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function doTree(sourceCode: string, filepath: string):
|
|
1
|
+
import { SetOfBlocks } from 'gettext-merger';
|
|
2
|
+
export declare function doTree(sourceCode: string, filepath: string): SetOfBlocks;
|
package/lib/parser/tree.js
CHANGED
|
@@ -8,36 +8,37 @@ const tree_sitter_1 = __importDefault(require("tree-sitter"));
|
|
|
8
8
|
const const_1 = require("../const");
|
|
9
9
|
const glob_1 = require("../fs/glob");
|
|
10
10
|
const utils_1 = require("../utils");
|
|
11
|
+
const gettext_merger_1 = require("gettext-merger");
|
|
11
12
|
function collectComments(node) {
|
|
12
|
-
var _a, _b;
|
|
13
13
|
let currentNode = node;
|
|
14
14
|
let depth = 0;
|
|
15
15
|
while (currentNode && depth < 6) {
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (currentNode?.previousSibling?.type === 'comment' &&
|
|
17
|
+
currentNode?.previousSibling?.text
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.includes('translators')) {
|
|
20
|
+
return (0, utils_1.stripTranslationMarkup)(currentNode?.previousSibling.text);
|
|
19
21
|
}
|
|
20
22
|
depth++;
|
|
21
23
|
currentNode = currentNode.parent;
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
function doTree(sourceCode, filepath) {
|
|
25
|
-
var _a;
|
|
26
27
|
const parser = new tree_sitter_1.default();
|
|
27
28
|
parser.setLanguage((0, glob_1.getParser)(filepath));
|
|
28
29
|
const tree = parser.parse(sourceCode);
|
|
29
|
-
const gettextTranslations =
|
|
30
|
-
const typeToMatch =
|
|
30
|
+
const gettextTranslations = new gettext_merger_1.SetOfBlocks([], filepath);
|
|
31
|
+
const typeToMatch = filepath.split('.').pop()?.toLowerCase() !== 'php'
|
|
31
32
|
? 'call_expression'
|
|
32
33
|
: 'function_call_expression';
|
|
34
|
+
const stringType = ['string', 'encapsed_string', 'string_value'];
|
|
33
35
|
function traverse(node) {
|
|
34
|
-
|
|
35
|
-
if (node === null || node === void 0 ? void 0 : node.children.length)
|
|
36
|
+
if (node?.children.length)
|
|
36
37
|
for (const child of node.children) {
|
|
37
38
|
traverse(child);
|
|
38
39
|
}
|
|
39
|
-
if (
|
|
40
|
-
const functionName =
|
|
40
|
+
if (node?.type === typeToMatch) {
|
|
41
|
+
const functionName = node.firstChild?.text ?? null;
|
|
41
42
|
if (functionName === null ||
|
|
42
43
|
!Object.keys(const_1.i18nFunctions).includes(functionName)) {
|
|
43
44
|
return;
|
|
@@ -55,29 +56,45 @@ function doTree(sourceCode, filepath) {
|
|
|
55
56
|
let translationKeyIndex = 0;
|
|
56
57
|
for (const child of children) {
|
|
57
58
|
let node = child;
|
|
58
|
-
|
|
59
|
+
let nodeValue = node.text;
|
|
60
|
+
if (child.type === 'argument') {
|
|
59
61
|
if (child.children.length === 0)
|
|
60
62
|
continue;
|
|
61
63
|
node = child.children[0];
|
|
62
64
|
}
|
|
63
|
-
if (node
|
|
65
|
+
if (node?.type === ',') {
|
|
64
66
|
continue;
|
|
67
|
+
}
|
|
68
|
+
if (stringType.includes(node?.type)) {
|
|
69
|
+
nodeValue = nodeValue.slice(1, -1);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
console.warn('Unexpected node type: ' +
|
|
73
|
+
node?.type +
|
|
74
|
+
' is ' +
|
|
75
|
+
translationKeys[translationKeyIndex] +
|
|
76
|
+
' for ' +
|
|
77
|
+
nodeValue +
|
|
78
|
+
' in ' +
|
|
79
|
+
filepath);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
65
82
|
const currentKey = translationKeys[translationKeyIndex];
|
|
66
|
-
translation[currentKey] =
|
|
67
|
-
child.text.slice(1, -1);
|
|
83
|
+
translation[currentKey] = nodeValue;
|
|
68
84
|
translationKeyIndex += 1;
|
|
69
85
|
}
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
const comments = collectComments(argsNode);
|
|
87
|
+
const block = new gettext_merger_1.Block({
|
|
88
|
+
msgctxt: translation.msgctxt,
|
|
89
|
+
msgid: translation.msgid ?? '',
|
|
90
|
+
msgid_plural: translation.msgid_plural,
|
|
74
91
|
msgstr: translation.msgid_plural ? ['', ''] : [''],
|
|
75
92
|
comments: {
|
|
76
|
-
translator:
|
|
77
|
-
reference: `${filepath}:${node.startPosition.row + 1}
|
|
93
|
+
translator: comments ? [comments] : undefined,
|
|
94
|
+
reference: [`${filepath}:${node.startPosition.row + 1}`],
|
|
78
95
|
},
|
|
79
|
-
};
|
|
80
|
-
gettextTranslations
|
|
96
|
+
});
|
|
97
|
+
gettextTranslations.add(block);
|
|
81
98
|
}
|
|
82
99
|
}
|
|
83
100
|
traverse(tree.rootNode);
|
package/lib/parser/tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/parser/tree.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqD;
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/parser/tree.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqD;AACrD,oCAAwC;AAGxC,qCAAsC;AACtC,oCAAiD;AACjD,mDAAmD;AAQnD,SAAS,eAAe,CAAC,IAAgB;IACxC,IAAI,WAAW,GAAG,IAAI,CAAA;IACtB,IAAI,KAAK,GAAG,CAAC,CAAA;IAGb,OAAO,WAAW,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACjC,IACC,WAAW,EAAE,eAAe,EAAE,IAAI,KAAK,SAAS;YAChD,WAAW,EAAE,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ACN,eAAe,CAAC,mBAAmB,CAAC;wBACpC,QAAQ;wBACR,SAAS;wBACT,MAAM;wBACN,QAAQ,CACT,CAAA;oBAED,SAAQ;gBACT,CAAC;gBAGD,MAAM,UAAU,GAAG,eAAe,CAAC,mBAAmB,CAAC,CAAA;gBAGvD,WAAW,CAAC,UAAsC,CAAC,GAAG,SAAS,CAAA;gBAG/D,mBAAmB,IAAI,CAAC,CAAA;YACzB,CAAC;YAGD,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAA;YAG1C,MAAM,KAAK,GAAG,IAAI,sBAAK,CAAC;gBACvB,OAAO,EAAE,WAAW,CAAC,OAAO;gBAC5B,KAAK,EAAE,WAAW,CAAC,KAAK,IAAI,EAAE;gBAC9B,YAAY,EAAE,WAAW,CAAC,YAAY;gBACtC,MAAM,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAClD,QAAQ,EAAE;oBACT,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;oBAC7C,SAAS,EAAE,CAAC,GAAG,QAAQ,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC;iBACxD;aACD,CAAC,CAAA;YAEF,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAC/B,CAAC;IACF,CAAC;IAED,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAGvB,OAAO,mBAAmB,CAAA;AAC3B,CAAC;AAlID,wBAkIC"}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare function stringstring(string: string | string[] | undefined): str
|
|
|
6
6
|
export declare function advancedObjectMerge(obj1: TranslationStrings, obj2: TranslationStrings): TranslationStrings;
|
|
7
7
|
export declare function detectPatternType(pattern: string): 'file' | 'directory' | 'glob';
|
|
8
8
|
export declare function includeFunction(includePath: string[]): string[];
|
|
9
|
+
export declare function getCopyright(slug: string, license?: string): string;
|
package/lib/utils/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.includeFunction = exports.detectPatternType = exports.advancedObjectMerge = exports.stringstring = exports.stripTranslationMarkup = exports.removeCommentMarkup = exports.getCommentBlock = void 0;
|
|
6
|
+
exports.getCopyright = exports.includeFunction = exports.detectPatternType = exports.advancedObjectMerge = exports.stringstring = exports.stripTranslationMarkup = exports.removeCommentMarkup = exports.getCommentBlock = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
function getCommentBlock(input) {
|
|
9
9
|
const commentBlock = input.match(/\/\*\*?[\s\S]*?\*\//);
|
|
@@ -31,7 +31,7 @@ function stringstring(string) {
|
|
|
31
31
|
}
|
|
32
32
|
exports.stringstring = stringstring;
|
|
33
33
|
function advancedObjectMerge(obj1, obj2) {
|
|
34
|
-
const merged =
|
|
34
|
+
const merged = { ...obj1 };
|
|
35
35
|
for (const key in obj2) {
|
|
36
36
|
if (Object.prototype.hasOwnProperty.call(obj2, key)) {
|
|
37
37
|
merged[key] =
|
|
@@ -75,4 +75,9 @@ function includeFunction(includePath) {
|
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
exports.includeFunction = includeFunction;
|
|
78
|
+
function getCopyright(slug, license = 'GPL v2 or later') {
|
|
79
|
+
return (`# Copyright (C) ${new Date().getFullYear()} ${slug}\n` +
|
|
80
|
+
`# This file is distributed under the ${license} license.`);
|
|
81
|
+
}
|
|
82
|
+
exports.getCopyright = getCopyright;
|
|
78
83
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AASvB,SAAgB,eAAe,CAAC,KAAa;IAC5C,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACvD,OAAO,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AACvD,CAAC;AAHD,0CAGC;AAQD,SAAgB,mBAAmB,CAAC,KAAa;IAChD,OAAO,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;AACnC,CAAC;AAFD,kDAEC;AAQD,SAAgB,sBAAsB,CAAC,OAAe;IACrD,MAAM,cAAc,GACnB,iFAAiF,CAAA;IAClF,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;IAC7C,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;AACtC,CAAC;AALD,wDAKC;AAQD,SAAgB,YAAY,CAC3B,MAAqC;IAErC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAChC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACzB,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,CAAA;IAChB,CAAC;IACD,OAAO,IAAI,CAAA;AACZ,CAAC;AAVD,oCAUC;AASD,SAAgB,mBAAmB,CAClC,IAAwB,EACxB,IAAwB;IAExB,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AASvB,SAAgB,eAAe,CAAC,KAAa;IAC5C,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,qBAA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C,OAAO,WAAW,CAC1D,CAAA;AACF,CAAC;AARD,oCAQC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-blocks/make-pot",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"license": "GPL-3.0-or-later",
|
|
5
|
+
"homepage": "https://wp-blocks.github.io/make-pot/",
|
|
4
6
|
"description": "A Node.js script for generating a POT file from source code",
|
|
5
|
-
"
|
|
7
|
+
"authors": [
|
|
8
|
+
"Erik Golinelli <erik@codekraft.it> (https://codekraft.it/)",
|
|
9
|
+
"John Hooks <bitmachina@outlook.com> (https://johnhooks.io/)"
|
|
10
|
+
],
|
|
6
11
|
"main": "lib/index.js",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"gettext",
|
|
14
|
+
"i18n",
|
|
15
|
+
"pot",
|
|
16
|
+
"WordPress",
|
|
17
|
+
"translation",
|
|
18
|
+
"internalization"
|
|
19
|
+
],
|
|
7
20
|
"scripts": {
|
|
8
21
|
"postinstall": "npm rebuild tree-sitter tree-sitter-typescript tree-sitter-php tree-sitter-javascript --force",
|
|
9
22
|
"build": "tsc --build",
|
|
@@ -27,7 +40,7 @@
|
|
|
27
40
|
"dependencies": {
|
|
28
41
|
"axios": "^1.6.8",
|
|
29
42
|
"cli-progress": "^3.12.0",
|
|
30
|
-
"gettext-merger": "^
|
|
43
|
+
"gettext-merger": "^1.2.1",
|
|
31
44
|
"gettext-parser": "^7.0.1",
|
|
32
45
|
"glob": "^10.3.10",
|
|
33
46
|
"tree-sitter": "^0.20.6",
|
package/tests/extract.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect } from '@jest/globals'
|
|
2
2
|
import { doTree } from '../src/parser/tree'
|
|
3
|
+
import { Block } from 'gettext-merger'
|
|
3
4
|
|
|
4
5
|
describe('getStrings', () => {
|
|
5
6
|
it('should extract translations from js', () => {
|
|
@@ -7,36 +8,34 @@ describe('getStrings', () => {
|
|
|
7
8
|
const filename = 'filename.js'
|
|
8
9
|
|
|
9
10
|
const result = doTree(content, filename)
|
|
11
|
+
const expected = new Block([])
|
|
12
|
+
expected.msgid = 'Hello World'
|
|
13
|
+
expected.comments = {
|
|
14
|
+
reference: ['filename.js:1'],
|
|
15
|
+
translator: [''],
|
|
16
|
+
}
|
|
10
17
|
|
|
11
|
-
expect(result).
|
|
12
|
-
'': {
|
|
13
|
-
'Hello World': {
|
|
14
|
-
comments: {
|
|
15
|
-
reference: 'filename.js:1',
|
|
16
|
-
},
|
|
17
|
-
msgid: 'Hello World',
|
|
18
|
-
msgstr: [''],
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
})
|
|
18
|
+
expect(result.blocks[0].msgid).toBe(expected.msgid)
|
|
22
19
|
})
|
|
20
|
+
|
|
23
21
|
it('should extract translations from ts', () => {
|
|
24
22
|
const content = `__('Hello World', 'greeting');`
|
|
25
23
|
const filename = 'filename.ts'
|
|
26
24
|
|
|
27
|
-
const result = doTree(content, filename)
|
|
25
|
+
const result = doTree(content, filename).blocks[0].toJson()
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
const expected = new Block([])
|
|
28
|
+
expected.msgid = 'Hello World'
|
|
29
|
+
expected.comments = {
|
|
30
|
+
reference: ['filename.ts:1'],
|
|
31
|
+
translator: [''],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
expect(result.msgid).toBe(expected.msgid)
|
|
35
|
+
expect(expected.comments?.reference).toHaveLength(1)
|
|
36
|
+
expect([result.comments?.reference]).toEqual(
|
|
37
|
+
expected.comments?.reference
|
|
38
|
+
)
|
|
40
39
|
})
|
|
41
40
|
it('should extract translations from tsx', () => {
|
|
42
41
|
const content = `const element = <h1>{ __('Hello World', 'greeting')}</h1>;`
|
|
@@ -45,17 +44,15 @@ describe('getStrings', () => {
|
|
|
45
44
|
|
|
46
45
|
const result = doTree(content, filename)
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
})
|
|
47
|
+
const expected = new Block([])
|
|
48
|
+
expected.msgid = 'Hello World'
|
|
49
|
+
expected.msgstr = ['']
|
|
50
|
+
expected.comments = {
|
|
51
|
+
reference: ['filename.tsx:1'],
|
|
52
|
+
translator: [''],
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
expect(result.blocks[0].toJson()).toEqual(expected.toJson())
|
|
59
56
|
})
|
|
60
57
|
it('should extract translations with context', () => {
|
|
61
58
|
const content = `<?php __('Hello World', 'greeting'); ?>`
|
|
@@ -63,42 +60,30 @@ describe('getStrings', () => {
|
|
|
63
60
|
|
|
64
61
|
const result = doTree(content, filename)
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
msgid_plural: '',
|
|
76
|
-
msgstr: [''],
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
})
|
|
63
|
+
const expected = new Block([])
|
|
64
|
+
expected.msgid = 'Hello World'
|
|
65
|
+
expected.msgstr = ['']
|
|
66
|
+
expected.comments = {
|
|
67
|
+
reference: ['filename.php:1'],
|
|
68
|
+
translator: [''],
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
expect(result.blocks[0].toJson()).toEqual(expected.toJson())
|
|
80
72
|
})
|
|
81
73
|
it('should extract translations from code content with no context or translator comments', () => {
|
|
82
74
|
const content = `<?php _e('Hello World'); ?>`
|
|
83
|
-
const expected =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
},
|
|
90
|
-
msgctxt: '',
|
|
91
|
-
msgid: 'Hello World',
|
|
92
|
-
msgstr: [''],
|
|
93
|
-
msgid_plural: '',
|
|
94
|
-
},
|
|
95
|
-
},
|
|
75
|
+
const expected = new Block([])
|
|
76
|
+
expected.msgid = 'Hello World'
|
|
77
|
+
expected.msgstr = ['']
|
|
78
|
+
expected.comments = {
|
|
79
|
+
translator: undefined,
|
|
80
|
+
reference: ['filename.php:1'],
|
|
96
81
|
}
|
|
97
82
|
const filename = 'filename.php'
|
|
98
83
|
|
|
99
84
|
const result = doTree(content, filename)
|
|
100
85
|
|
|
101
|
-
expect(result).toEqual(expected)
|
|
86
|
+
expect(result.blocks[0]).toEqual(expected)
|
|
102
87
|
})
|
|
103
88
|
|
|
104
89
|
it('should extract translations with comments', () => {
|
|
@@ -106,18 +91,18 @@ describe('getStrings', () => {
|
|
|
106
91
|
const content = `
|
|
107
92
|
<?php /** translators: ciao! */ echo _x('Hello World', 'greeting'); ?>`
|
|
108
93
|
const expected = {
|
|
109
|
-
|
|
110
|
-
|
|
94
|
+
blocks: [
|
|
95
|
+
{
|
|
111
96
|
comments: {
|
|
112
|
-
reference: 'filename.php:2',
|
|
113
|
-
translator: 'ciao!',
|
|
97
|
+
reference: ['filename.php:2'],
|
|
98
|
+
translator: ['ciao!'],
|
|
114
99
|
},
|
|
115
100
|
msgctxt: 'greeting',
|
|
116
101
|
msgid: 'Hello World',
|
|
117
|
-
msgid_plural: '',
|
|
118
102
|
msgstr: [''],
|
|
119
103
|
},
|
|
120
|
-
|
|
104
|
+
],
|
|
105
|
+
path: 'filename.php',
|
|
121
106
|
}
|
|
122
107
|
|
|
123
108
|
const result = doTree(content, filename)
|
|
@@ -137,24 +122,14 @@ describe('getStrings', () => {
|
|
|
137
122
|
|
|
138
123
|
|
|
139
124
|
<?php echo _x('Hello World', 'greeting'); ?>`
|
|
140
|
-
const expected =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
msgid: 'Hello World',
|
|
145
|
-
msgid_plural: '',
|
|
146
|
-
msgstr: [''],
|
|
147
|
-
comments: {
|
|
148
|
-
translator: '',
|
|
149
|
-
reference: 'filename.php:10',
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
}
|
|
125
|
+
const expected = `#: filename.php:10
|
|
126
|
+
msgctxt "greeting"
|
|
127
|
+
msgid "Hello World"
|
|
128
|
+
msgstr ""`
|
|
154
129
|
|
|
155
130
|
const result = doTree(content, filename)
|
|
156
131
|
|
|
157
|
-
expect(result).
|
|
132
|
+
expect(result.blocks[0].toStr()).toBe(expected)
|
|
158
133
|
})
|
|
159
134
|
|
|
160
135
|
it('should extract translations inside a sprint', () => {
|
|
@@ -168,9 +143,15 @@ echo $link;`
|
|
|
168
143
|
'Check out this link to my <a href="%s">website</a> made with WordPress.':
|
|
169
144
|
{
|
|
170
145
|
comments: {
|
|
146
|
+
extracted: '',
|
|
147
|
+
flag: '',
|
|
148
|
+
previous: '',
|
|
171
149
|
reference: 'filename.php:3',
|
|
150
|
+
translator: '',
|
|
172
151
|
},
|
|
152
|
+
msgctxt: '',
|
|
173
153
|
msgid: 'Check out this link to my <a href="%s">website</a> made with WordPress.',
|
|
154
|
+
msgid_plural: undefined,
|
|
174
155
|
msgstr: [''],
|
|
175
156
|
},
|
|
176
157
|
},
|
|
@@ -178,11 +159,36 @@ echo $link;`
|
|
|
178
159
|
|
|
179
160
|
const result = doTree(content, filename)
|
|
180
161
|
|
|
181
|
-
expect(result).toMatchObject(expected)
|
|
162
|
+
expect(result.toJson()).toMatchObject(expected)
|
|
182
163
|
})
|
|
183
164
|
})
|
|
184
165
|
|
|
185
166
|
describe('getStrings wp cli', () => {
|
|
167
|
+
it('should extract from an array of translations', () => {
|
|
168
|
+
const filename = 'filename.php'
|
|
169
|
+
const content = `<?php $var = 'don't do this'; $instructions = array(
|
|
170
|
+
"Overview" => array(
|
|
171
|
+
"title" => __( 'Overview', '3d-product-viewer' ),
|
|
172
|
+
"text" => __( "Hold down the right button to move the model", '3d-product-viewer' ),
|
|
173
|
+
"icon" => 'icon-book'
|
|
174
|
+
),
|
|
175
|
+
"Rotation" => array(
|
|
176
|
+
"title" => __( 'Rotation', '3d-product-viewer' ),
|
|
177
|
+
"text" => __( "Left-click and drag to change the angle", '3d-product-viewer' ),
|
|
178
|
+
"icon" => 'icon-rotation'
|
|
179
|
+
),
|
|
180
|
+
"Zoom" => array(
|
|
181
|
+
"title" => __( 'Zoom', '3d-product-viewer' ),
|
|
182
|
+
"text" => __( "Variable is % and not {$var}", '3d-product-viewer' ),
|
|
183
|
+
"icon" => 'icon-zoom'
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
`
|
|
187
|
+
|
|
188
|
+
const result = doTree(content, filename)
|
|
189
|
+
expect(result).toMatchSnapshot()
|
|
190
|
+
})
|
|
191
|
+
|
|
186
192
|
it('should extract translations with translator comments inside the formatting hell', () => {
|
|
187
193
|
const filename = 'filename.php'
|
|
188
194
|
const content = `<?php if ( count( $errors_in_remigrate_batch ) > 0 ) {
|
|
@@ -190,10 +196,10 @@ describe('getStrings wp cli', () => {
|
|
|
190
196
|
WP_CLI::warning(
|
|
191
197
|
sprintf(
|
|
192
198
|
/* Translators: %1$d is number of errors and %2$s is the formatted array of order IDs. */
|
|
193
|
-
|
|
199
|
+
_n(
|
|
194
200
|
'%1$d error found: %2$s when re-migrating order. Please review the error above.',
|
|
195
201
|
'%1$d errors found: %2$s when re-migrating orders. Please review the errors above.',
|
|
196
|
-
|
|
202
|
+
count( %s ),
|
|
197
203
|
'woocommerce'
|
|
198
204
|
),
|
|
199
205
|
count( $errors_in_remigrate_batch ),
|
|
@@ -204,26 +210,11 @@ describe('getStrings wp cli', () => {
|
|
|
204
210
|
WP_CLI::warning( 'Re-migration successful.', 'woocommerce' );
|
|
205
211
|
}
|
|
206
212
|
`
|
|
207
|
-
const expected = {
|
|
208
|
-
'': {
|
|
209
|
-
'%1$d error found: %2$s when re-migrating order. Please review the error above.':
|
|
210
|
-
{
|
|
211
|
-
comments: {
|
|
212
|
-
reference: 'filename.php:6',
|
|
213
|
-
translator:
|
|
214
|
-
'%1$d is number of errors and %2$s is the formatted array of order IDs.',
|
|
215
|
-
},
|
|
216
|
-
msgctxt: '',
|
|
217
|
-
msgid: '%1$d error found: %2$s when re-migrating order. Please review the error above.',
|
|
218
|
-
msgid_plural:
|
|
219
|
-
'%1$d errors found: %2$s when re-migrating orders. Please review the errors above.',
|
|
220
|
-
msgstr: ['', ''],
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
}
|
|
224
213
|
|
|
225
214
|
const result = doTree(content, filename)
|
|
226
|
-
expect(
|
|
215
|
+
expect(
|
|
216
|
+
'%1$d error found: %2$s when re-migrating order. Please review the error above.'
|
|
217
|
+
).toBe(result.blocks[0].msgid)
|
|
227
218
|
})
|
|
228
219
|
|
|
229
220
|
/** see https://github.com/wp-cli/i18n-command/blob/main/features/makepot.feature */
|