@wp-blocks/make-pot 1.4.0 → 1.5.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 +79 -11
- package/lib/assets/package-i18n.js +1 -1
- package/lib/cli/getArgs.js +1 -1
- package/lib/cli/getJsonArgs.js +1 -1
- package/lib/cli/parseCli.js +1 -1
- package/lib/cli.js +2 -0
- package/lib/extractors/css.js +1 -1
- package/lib/extractors/headers.js +6 -1
- package/lib/extractors/json.js +1 -1
- package/lib/extractors/php.js +2 -2
- package/lib/extractors/schema.js +4 -1
- package/lib/extractors/utils.js +1 -1
- package/lib/fs/fs.js +1 -1
- package/lib/fs/glob.js +1 -3
- package/lib/index.js +1 -2
- package/lib/jsonCommand.js +1 -2
- package/lib/makeJson.js +2 -0
- package/lib/makePot.js +2 -0
- package/lib/parser/exec.js +7 -3
- package/lib/parser/makeJson.js +1 -3
- package/lib/parser/makePot.js +1 -1
- package/lib/parser/patterns.js +1 -1
- package/lib/parser/process.js +1 -1
- package/lib/parser/taskRunner.js +1 -1
- package/lib/parser/tree.js +1 -1
- package/lib/potCommand.js +1 -1
- package/lib/types.js +1 -1
- package/lib/utils/common.js +3 -2
- package/package.json +19 -20
- package/tests/extract.test.js +381 -381
- package/tests/getFiles.test.no.js +85 -85
- package/tests/tree.test.js +158 -158
- package/tests/wpcliCompare.no.js +32 -32
- package/tsconfig.json +2 -0
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
const { sep } = require("node:path");
|
|
2
|
-
const { describe, it } = require("node:test");
|
|
3
|
-
const assert = require("node:assert");
|
|
4
|
-
const { parseCliArgs } = require("
|
|
5
|
-
const { getFiles } = require("
|
|
6
|
-
|
|
7
|
-
describe("getFiles", () => {
|
|
8
|
-
const DEFAULTS = parseCliArgs({
|
|
9
|
-
domain: "plugin",
|
|
10
|
-
slug: "plugin-slug",
|
|
11
|
-
paths: { cwd: "tests/fixtures/", out: "tests/fixtures/" },
|
|
12
|
-
options: {
|
|
13
|
-
silent: true,
|
|
14
|
-
},
|
|
15
|
-
$0: "makepot",
|
|
16
|
-
_: [0, 1],
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("should retrieve a all files", async () => {
|
|
20
|
-
const args = { ...DEFAULTS, domain: "theme" };
|
|
21
|
-
const pattern = { include: ["./src/**"], exclude: [] };
|
|
22
|
-
|
|
23
|
-
const files = getFiles(args, pattern);
|
|
24
|
-
const collected = [];
|
|
25
|
-
for (const file of files) {
|
|
26
|
-
assert.equal(!!file, true);
|
|
27
|
-
collected.push(file);
|
|
28
|
-
}
|
|
29
|
-
assert.deepStrictEqual(collected.length, 28);
|
|
30
|
-
assert.strictEqual(
|
|
31
|
-
collected.find((e) => e.includes("const.ts")),
|
|
32
|
-
"src\\const.ts",
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("Should retrieve a list of txt files based on the provided plugin pattern", async () => {
|
|
37
|
-
const args = {
|
|
38
|
-
...DEFAULTS,
|
|
39
|
-
};
|
|
40
|
-
const pattern = {
|
|
41
|
-
include: ["**/*.txt"],
|
|
42
|
-
exclude: ["node_modules", "dist"],
|
|
43
|
-
};
|
|
44
|
-
const expectedFiles = [
|
|
45
|
-
`tests${sep}fixtures${sep}file1.txt`,
|
|
46
|
-
`tests${sep}fixtures${sep}sourcedir${sep}file2.txt`,
|
|
47
|
-
`tests${sep}fixtures${sep}block${sep}readme.txt`,
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
const files = getFiles(args, pattern);
|
|
51
|
-
const collected = [];
|
|
52
|
-
for (const file of files) {
|
|
53
|
-
assert.equal(!!file, true);
|
|
54
|
-
collected.push(file);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
assert.deepStrictEqual(collected, expectedFiles);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("should retrieve a list of theme.json files based on the provided theme pattern", async () => {
|
|
61
|
-
const args = {
|
|
62
|
-
...DEFAULTS,
|
|
63
|
-
};
|
|
64
|
-
const pattern = {
|
|
65
|
-
include: ["tests/fixtures/sourcedir/**/*.json"],
|
|
66
|
-
exclude: [],
|
|
67
|
-
};
|
|
68
|
-
const expectedFiles = [
|
|
69
|
-
`tests${sep}fixtures${sep}sourcedir${sep}theme.json`,
|
|
70
|
-
`tests${sep}fixtures${sep}sourcedir${sep}package.json`,
|
|
71
|
-
`tests${sep}fixtures${sep}sourcedir${sep}node_modules${sep}module${sep}block.json`,
|
|
72
|
-
];
|
|
73
|
-
|
|
74
|
-
const files = getFiles(args, pattern);
|
|
75
|
-
const collected = [];
|
|
76
|
-
for (const file of files) {
|
|
77
|
-
assert.equal(!!file, true);
|
|
78
|
-
collected.push(file);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const fileFound = collected.filter((file) => expectedFiles.includes(file));
|
|
82
|
-
|
|
83
|
-
assert.deepStrictEqual(fileFound.length, 3);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
1
|
+
const { sep } = require("node:path");
|
|
2
|
+
const { describe, it } = require("node:test");
|
|
3
|
+
const assert = require("node:assert");
|
|
4
|
+
const { parseCliArgs } = require("../lib/cli/parseCli.js");
|
|
5
|
+
const { getFiles } = require("../lib/fs/glob.js");
|
|
6
|
+
|
|
7
|
+
describe("getFiles", () => {
|
|
8
|
+
const DEFAULTS = parseCliArgs({
|
|
9
|
+
domain: "plugin",
|
|
10
|
+
slug: "plugin-slug",
|
|
11
|
+
paths: { cwd: "tests/fixtures/", out: "tests/fixtures/" },
|
|
12
|
+
options: {
|
|
13
|
+
silent: true,
|
|
14
|
+
},
|
|
15
|
+
$0: "makepot",
|
|
16
|
+
_: [0, 1],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should retrieve a all files", async () => {
|
|
20
|
+
const args = { ...DEFAULTS, domain: "theme" };
|
|
21
|
+
const pattern = { include: ["./src/**"], exclude: [] };
|
|
22
|
+
|
|
23
|
+
const files = getFiles(args, pattern);
|
|
24
|
+
const collected = [];
|
|
25
|
+
for (const file of files) {
|
|
26
|
+
assert.equal(!!file, true);
|
|
27
|
+
collected.push(file);
|
|
28
|
+
}
|
|
29
|
+
assert.deepStrictEqual(collected.length, 28);
|
|
30
|
+
assert.strictEqual(
|
|
31
|
+
collected.find((e) => e.includes("const.ts")),
|
|
32
|
+
"src\\const.ts",
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("Should retrieve a list of txt files based on the provided plugin pattern", async () => {
|
|
37
|
+
const args = {
|
|
38
|
+
...DEFAULTS,
|
|
39
|
+
};
|
|
40
|
+
const pattern = {
|
|
41
|
+
include: ["**/*.txt"],
|
|
42
|
+
exclude: ["node_modules", "dist"],
|
|
43
|
+
};
|
|
44
|
+
const expectedFiles = [
|
|
45
|
+
`tests${sep}fixtures${sep}file1.txt`,
|
|
46
|
+
`tests${sep}fixtures${sep}sourcedir${sep}file2.txt`,
|
|
47
|
+
`tests${sep}fixtures${sep}block${sep}readme.txt`,
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const files = getFiles(args, pattern);
|
|
51
|
+
const collected = [];
|
|
52
|
+
for (const file of files) {
|
|
53
|
+
assert.equal(!!file, true);
|
|
54
|
+
collected.push(file);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
assert.deepStrictEqual(collected, expectedFiles);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should retrieve a list of theme.json files based on the provided theme pattern", async () => {
|
|
61
|
+
const args = {
|
|
62
|
+
...DEFAULTS,
|
|
63
|
+
};
|
|
64
|
+
const pattern = {
|
|
65
|
+
include: ["tests/fixtures/sourcedir/**/*.json"],
|
|
66
|
+
exclude: [],
|
|
67
|
+
};
|
|
68
|
+
const expectedFiles = [
|
|
69
|
+
`tests${sep}fixtures${sep}sourcedir${sep}theme.json`,
|
|
70
|
+
`tests${sep}fixtures${sep}sourcedir${sep}package.json`,
|
|
71
|
+
`tests${sep}fixtures${sep}sourcedir${sep}node_modules${sep}module${sep}block.json`,
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
const files = getFiles(args, pattern);
|
|
75
|
+
const collected = [];
|
|
76
|
+
for (const file of files) {
|
|
77
|
+
assert.equal(!!file, true);
|
|
78
|
+
collected.push(file);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const fileFound = collected.filter((file) => expectedFiles.includes(file));
|
|
82
|
+
|
|
83
|
+
assert.deepStrictEqual(fileFound.length, 3);
|
|
84
|
+
});
|
|
85
|
+
});
|
package/tests/tree.test.js
CHANGED
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
const path = require("node:path");
|
|
2
|
-
const fs = require("node:fs");
|
|
3
|
-
const { describe, it } = require("node:test");
|
|
4
|
-
const assert = require("node:assert");
|
|
5
|
-
const { doTree } = require("../lib
|
|
6
|
-
|
|
7
|
-
describe("doTree js", () => {
|
|
8
|
-
const filepath = "tests/fixtures/block/javascript.js";
|
|
9
|
-
const filePath = path.join(process.cwd(), filepath);
|
|
10
|
-
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
11
|
-
it("Should parse TSX file and extract strings", () => {
|
|
12
|
-
const fileParsed = doTree(fileContent, filepath);
|
|
13
|
-
assert.deepEqual(fileParsed.blocks[0], {
|
|
14
|
-
comments: {
|
|
15
|
-
reference: ["tests/fixtures/block/javascript.js:7"],
|
|
16
|
-
translator: undefined,
|
|
17
|
-
},
|
|
18
|
-
msgctxt: undefined,
|
|
19
|
-
msgid: "Simple Block",
|
|
20
|
-
msgid_plural: undefined,
|
|
21
|
-
msgstr: [""],
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe("doTree php", () => {
|
|
27
|
-
const filepath = "tests/fixtures/plugin/plugin.php";
|
|
28
|
-
const filePath = path.join(process.cwd(), filepath);
|
|
29
|
-
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
30
|
-
it("Should parse TSX file and extract strings", () => {
|
|
31
|
-
const fileParsed = doTree(fileContent, filepath);
|
|
32
|
-
assert.deepEqual(fileParsed.blocks[1], {
|
|
33
|
-
comments: {
|
|
34
|
-
reference: ["tests/fixtures/plugin/plugin.php:65"],
|
|
35
|
-
translator: undefined,
|
|
36
|
-
},
|
|
37
|
-
msgctxt: undefined,
|
|
38
|
-
msgid: "You\\'re a silly monkey",
|
|
39
|
-
msgid_plural: undefined,
|
|
40
|
-
msgstr: [""],
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("doTree tsx file", () => {
|
|
46
|
-
const filepath = "tests/fixtures/block/SvgControls.tsx";
|
|
47
|
-
const filePath = path.join(process.cwd(), filepath);
|
|
48
|
-
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
49
|
-
it("Should parse TSX file and extract strings", () => {
|
|
50
|
-
const fileParsed = doTree(fileContent, filepath);
|
|
51
|
-
assert.deepEqual(fileParsed.blocks[2], {
|
|
52
|
-
comments: {
|
|
53
|
-
reference: ["tests/fixtures/block/SvgControls.tsx:107"],
|
|
54
|
-
translator: undefined,
|
|
55
|
-
},
|
|
56
|
-
msgctxt: undefined,
|
|
57
|
-
msgid: "Replace SVG",
|
|
58
|
-
msgid_plural: undefined,
|
|
59
|
-
msgstr: [""],
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe("doTree php test file", async () => {
|
|
65
|
-
/** see wp cli tests */
|
|
66
|
-
it("should extract translations and comments from code content", () => {
|
|
67
|
-
const content = `<?php
|
|
68
|
-
|
|
69
|
-
// translators: Foo Bar Comment
|
|
70
|
-
__( 'Foo Bar', 'foo-plugin' );
|
|
71
|
-
|
|
72
|
-
// TrANslAtORs: Bar Baz Comment
|
|
73
|
-
__( 'Bar Baz', 'foo-plugin' );
|
|
74
|
-
|
|
75
|
-
// translators: Software name
|
|
76
|
-
const string = __( 'WordPress', 'foo-plugin' );
|
|
77
|
-
|
|
78
|
-
// translators: So much space
|
|
79
|
-
|
|
80
|
-
__( 'Spacey text', 'foo-plugin' );
|
|
81
|
-
|
|
82
|
-
/* translators: Long comment
|
|
83
|
-
spanning multiple
|
|
84
|
-
lines */
|
|
85
|
-
const string = __( 'Short text', 'foo-plugin' );
|
|
86
|
-
|
|
87
|
-
ReactDOM.render(
|
|
88
|
-
<h1>{__( 'Hello JSX', 'foo-plugin' )}</h1>,
|
|
89
|
-
document.getElementById('root')
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
wp.i18n.__( 'wp.i18n.__', 'foo-plugin' );
|
|
93
|
-
|
|
94
|
-
const translate = wp.i18n;
|
|
95
|
-
translate.__( 'translate.__', 'foo-plugin' );
|
|
96
|
-
|
|
97
|
-
Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__["__"])( 'webpack.__', 'foo-plugin' );
|
|
98
|
-
Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__[/* __ */ "a"])( 'webpack.mangle.__', 'foo-plugin' );
|
|
99
|
-
|
|
100
|
-
Object(u.__)( 'minified.__', 'foo-plugin' );
|
|
101
|
-
Object(j._x)( 'minified._x', 'minified._x_context', 'foo-plugin' );
|
|
102
|
-
|
|
103
|
-
/* translators: babel */
|
|
104
|
-
(0, __)( 'babel.__', 'foo-plugin' );
|
|
105
|
-
(0, _i18n.__)( 'babel-i18n.__', 'foo-plugin' );
|
|
106
|
-
(0, _i18n._x)( 'babel-i18n._x', 'babel-i18n._x_context', 'foo-plugin' );
|
|
107
|
-
|
|
108
|
-
eval( "__( 'Hello Eval World', 'foo-plugin' );" );
|
|
109
|
-
|
|
110
|
-
__( "ASDASDASD', 'foo-plugin' );
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Plugin Name: Plugin name
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
/* translators: Translators 1! */
|
|
117
|
-
_e( 'hello world', 'foo-plugin' );
|
|
118
|
-
|
|
119
|
-
/* Translators: Translators 2! */
|
|
120
|
-
$foo = __( 'foo', 'foo-plugin' );
|
|
121
|
-
|
|
122
|
-
/* translators: localized date and time format, see https://secure.php.net/date */
|
|
123
|
-
__( 'F j, Y g:i a', 'foo-plugin' );
|
|
124
|
-
|
|
125
|
-
// translators: let your ears fly!
|
|
126
|
-
__( 'on', 'foo-plugin' );
|
|
127
|
-
|
|
128
|
-
/*
|
|
129
|
-
* Translators: If there are characters in your language that are not supported
|
|
130
|
-
* by Lato, translate this to 'off'. Do not translate into your own language.
|
|
131
|
-
*/
|
|
132
|
-
__( 'off', 'foo-plugin' );
|
|
133
|
-
|
|
134
|
-
/* translators: this should get extracted. */ $foo = __( 'baba', 'foo-plugin' );
|
|
135
|
-
|
|
136
|
-
/* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g( __( 'bubu', 'foo-plugin' ) );
|
|
137
|
-
|
|
138
|
-
{TAB}/*
|
|
139
|
-
{TAB} * translators: this comment block is indented with a tab and should get extracted too.
|
|
140
|
-
{TAB} */
|
|
141
|
-
{TAB}__( 'yolo', 'foo-plugin' );
|
|
142
|
-
|
|
143
|
-
/* translators: This is a comment */
|
|
144
|
-
__( 'Plugin name', 'foo-plugin' );
|
|
145
|
-
|
|
146
|
-
/* Translators: This is another comment! */
|
|
147
|
-
__( 'https://example.com', 'foo-plugin' );
|
|
148
|
-
`;
|
|
149
|
-
|
|
150
|
-
const filename = "filename.php";
|
|
151
|
-
|
|
152
|
-
const r = doTree(content, filename).blocks;
|
|
153
|
-
const res = Object.values(r)[0];
|
|
154
|
-
|
|
155
|
-
assert.strictEqual(r.map((block) => block).length, 11);
|
|
156
|
-
assert.strictEqual(r.filter((block) => block.comments).length, 11);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
1
|
+
const path = require("node:path");
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const { describe, it } = require("node:test");
|
|
4
|
+
const assert = require("node:assert");
|
|
5
|
+
const { doTree } = require("../lib");
|
|
6
|
+
|
|
7
|
+
describe("doTree js", () => {
|
|
8
|
+
const filepath = "tests/fixtures/block/javascript.js";
|
|
9
|
+
const filePath = path.join(process.cwd(), filepath);
|
|
10
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
11
|
+
it("Should parse TSX file and extract strings", () => {
|
|
12
|
+
const fileParsed = doTree(fileContent, filepath);
|
|
13
|
+
assert.deepEqual(fileParsed.blocks[0], {
|
|
14
|
+
comments: {
|
|
15
|
+
reference: ["tests/fixtures/block/javascript.js:7"],
|
|
16
|
+
translator: undefined,
|
|
17
|
+
},
|
|
18
|
+
msgctxt: undefined,
|
|
19
|
+
msgid: "Simple Block",
|
|
20
|
+
msgid_plural: undefined,
|
|
21
|
+
msgstr: [""],
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("doTree php", () => {
|
|
27
|
+
const filepath = "tests/fixtures/plugin/plugin.php";
|
|
28
|
+
const filePath = path.join(process.cwd(), filepath);
|
|
29
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
30
|
+
it("Should parse TSX file and extract strings", () => {
|
|
31
|
+
const fileParsed = doTree(fileContent, filepath);
|
|
32
|
+
assert.deepEqual(fileParsed.blocks[1], {
|
|
33
|
+
comments: {
|
|
34
|
+
reference: ["tests/fixtures/plugin/plugin.php:65"],
|
|
35
|
+
translator: undefined,
|
|
36
|
+
},
|
|
37
|
+
msgctxt: undefined,
|
|
38
|
+
msgid: "You\\'re a silly monkey",
|
|
39
|
+
msgid_plural: undefined,
|
|
40
|
+
msgstr: [""],
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("doTree tsx file", () => {
|
|
46
|
+
const filepath = "tests/fixtures/block/SvgControls.tsx";
|
|
47
|
+
const filePath = path.join(process.cwd(), filepath);
|
|
48
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
49
|
+
it("Should parse TSX file and extract strings", () => {
|
|
50
|
+
const fileParsed = doTree(fileContent, filepath);
|
|
51
|
+
assert.deepEqual(fileParsed.blocks[2], {
|
|
52
|
+
comments: {
|
|
53
|
+
reference: ["tests/fixtures/block/SvgControls.tsx:107"],
|
|
54
|
+
translator: undefined,
|
|
55
|
+
},
|
|
56
|
+
msgctxt: undefined,
|
|
57
|
+
msgid: "Replace SVG",
|
|
58
|
+
msgid_plural: undefined,
|
|
59
|
+
msgstr: [""],
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("doTree php test file", async () => {
|
|
65
|
+
/** see wp cli tests */
|
|
66
|
+
it("should extract translations and comments from code content", () => {
|
|
67
|
+
const content = `<?php
|
|
68
|
+
|
|
69
|
+
// translators: Foo Bar Comment
|
|
70
|
+
__( 'Foo Bar', 'foo-plugin' );
|
|
71
|
+
|
|
72
|
+
// TrANslAtORs: Bar Baz Comment
|
|
73
|
+
__( 'Bar Baz', 'foo-plugin' );
|
|
74
|
+
|
|
75
|
+
// translators: Software name
|
|
76
|
+
const string = __( 'WordPress', 'foo-plugin' );
|
|
77
|
+
|
|
78
|
+
// translators: So much space
|
|
79
|
+
|
|
80
|
+
__( 'Spacey text', 'foo-plugin' );
|
|
81
|
+
|
|
82
|
+
/* translators: Long comment
|
|
83
|
+
spanning multiple
|
|
84
|
+
lines */
|
|
85
|
+
const string = __( 'Short text', 'foo-plugin' );
|
|
86
|
+
|
|
87
|
+
ReactDOM.render(
|
|
88
|
+
<h1>{__( 'Hello JSX', 'foo-plugin' )}</h1>,
|
|
89
|
+
document.getElementById('root')
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
wp.i18n.__( 'wp.i18n.__', 'foo-plugin' );
|
|
93
|
+
|
|
94
|
+
const translate = wp.i18n;
|
|
95
|
+
translate.__( 'translate.__', 'foo-plugin' );
|
|
96
|
+
|
|
97
|
+
Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__["__"])( 'webpack.__', 'foo-plugin' );
|
|
98
|
+
Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__[/* __ */ "a"])( 'webpack.mangle.__', 'foo-plugin' );
|
|
99
|
+
|
|
100
|
+
Object(u.__)( 'minified.__', 'foo-plugin' );
|
|
101
|
+
Object(j._x)( 'minified._x', 'minified._x_context', 'foo-plugin' );
|
|
102
|
+
|
|
103
|
+
/* translators: babel */
|
|
104
|
+
(0, __)( 'babel.__', 'foo-plugin' );
|
|
105
|
+
(0, _i18n.__)( 'babel-i18n.__', 'foo-plugin' );
|
|
106
|
+
(0, _i18n._x)( 'babel-i18n._x', 'babel-i18n._x_context', 'foo-plugin' );
|
|
107
|
+
|
|
108
|
+
eval( "__( 'Hello Eval World', 'foo-plugin' );" );
|
|
109
|
+
|
|
110
|
+
__( "ASDASDASD', 'foo-plugin' );
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Plugin Name: Plugin name
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
/* translators: Translators 1! */
|
|
117
|
+
_e( 'hello world', 'foo-plugin' );
|
|
118
|
+
|
|
119
|
+
/* Translators: Translators 2! */
|
|
120
|
+
$foo = __( 'foo', 'foo-plugin' );
|
|
121
|
+
|
|
122
|
+
/* translators: localized date and time format, see https://secure.php.net/date */
|
|
123
|
+
__( 'F j, Y g:i a', 'foo-plugin' );
|
|
124
|
+
|
|
125
|
+
// translators: let your ears fly!
|
|
126
|
+
__( 'on', 'foo-plugin' );
|
|
127
|
+
|
|
128
|
+
/*
|
|
129
|
+
* Translators: If there are characters in your language that are not supported
|
|
130
|
+
* by Lato, translate this to 'off'. Do not translate into your own language.
|
|
131
|
+
*/
|
|
132
|
+
__( 'off', 'foo-plugin' );
|
|
133
|
+
|
|
134
|
+
/* translators: this should get extracted. */ $foo = __( 'baba', 'foo-plugin' );
|
|
135
|
+
|
|
136
|
+
/* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g( __( 'bubu', 'foo-plugin' ) );
|
|
137
|
+
|
|
138
|
+
{TAB}/*
|
|
139
|
+
{TAB} * translators: this comment block is indented with a tab and should get extracted too.
|
|
140
|
+
{TAB} */
|
|
141
|
+
{TAB}__( 'yolo', 'foo-plugin' );
|
|
142
|
+
|
|
143
|
+
/* translators: This is a comment */
|
|
144
|
+
__( 'Plugin name', 'foo-plugin' );
|
|
145
|
+
|
|
146
|
+
/* Translators: This is another comment! */
|
|
147
|
+
__( 'https://example.com', 'foo-plugin' );
|
|
148
|
+
`;
|
|
149
|
+
|
|
150
|
+
const filename = "filename.php";
|
|
151
|
+
|
|
152
|
+
const r = doTree(content, filename).blocks;
|
|
153
|
+
const res = Object.values(r)[0];
|
|
154
|
+
|
|
155
|
+
assert.strictEqual(r.map((block) => block).length, 11);
|
|
156
|
+
assert.strictEqual(r.filter((block) => block.comments).length, 11);
|
|
157
|
+
});
|
|
158
|
+
});
|
package/tests/wpcliCompare.no.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
const fs = require("node:fs");
|
|
2
|
-
const path = require("node:path");
|
|
3
|
-
const { describe, it } = require("node:test");
|
|
4
|
-
const assert = require("node:assert");
|
|
5
|
-
|
|
6
|
-
const { makePot } = require("../lib/");
|
|
7
|
-
const { getArgs } = require("../lib/cli/getArgs.js");
|
|
8
|
-
|
|
9
|
-
describe("doTree is like wpcli", () => {
|
|
10
|
-
it("Should emit a pot file for theme like the wp-cli makepot", async () => {
|
|
11
|
-
const filePath = path.join(process.cwd(), "./tests/fixtures/theme/");
|
|
12
|
-
const potPath = path.join(process.cwd(), "./tests/fixtures/theme.pot");
|
|
13
|
-
const potContent = fs.readFileSync(potPath, "utf8");
|
|
14
|
-
const args = getArgs({
|
|
15
|
-
_: [filePath],
|
|
16
|
-
});
|
|
17
|
-
const fileParsed = await makePot(args);
|
|
18
|
-
assert.deepEqual(fileParsed, potContent);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should emit a pot file for plugin like the wp-cli makepot", async () => {
|
|
22
|
-
const filePath = path.join(process.cwd(), "./tests/fixtures/vinyl/");
|
|
23
|
-
const potPath = path.join(process.cwd(), "./tests/fixtures/vinyl.pot");
|
|
24
|
-
const potContent = fs.readFileSync(potPath, "utf8");
|
|
25
|
-
|
|
26
|
-
const args = getArgs({
|
|
27
|
-
_: [filePath],
|
|
28
|
-
});
|
|
29
|
-
const fileParsed = await makePot(args);
|
|
30
|
-
assert.deepEqual(fileParsed, potContent);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const { describe, it } = require("node:test");
|
|
4
|
+
const assert = require("node:assert");
|
|
5
|
+
|
|
6
|
+
const { makePot } = require("../lib/");
|
|
7
|
+
const { getArgs } = require("../lib/cli/getArgs.js");
|
|
8
|
+
|
|
9
|
+
describe("doTree is like wpcli", () => {
|
|
10
|
+
it("Should emit a pot file for theme like the wp-cli makepot", async () => {
|
|
11
|
+
const filePath = path.join(process.cwd(), "./tests/fixtures/theme/");
|
|
12
|
+
const potPath = path.join(process.cwd(), "./tests/fixtures/theme.pot");
|
|
13
|
+
const potContent = fs.readFileSync(potPath, "utf8");
|
|
14
|
+
const args = getArgs({
|
|
15
|
+
_: [filePath],
|
|
16
|
+
});
|
|
17
|
+
const fileParsed = await makePot(args);
|
|
18
|
+
assert.deepEqual(fileParsed, potContent);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should emit a pot file for plugin like the wp-cli makepot", async () => {
|
|
22
|
+
const filePath = path.join(process.cwd(), "./tests/fixtures/vinyl/");
|
|
23
|
+
const potPath = path.join(process.cwd(), "./tests/fixtures/vinyl.pot");
|
|
24
|
+
const potContent = fs.readFileSync(potPath, "utf8");
|
|
25
|
+
|
|
26
|
+
const args = getArgs({
|
|
27
|
+
_: [filePath],
|
|
28
|
+
});
|
|
29
|
+
const fileParsed = await makePot(args);
|
|
30
|
+
assert.deepEqual(fileParsed, potContent);
|
|
31
|
+
});
|
|
32
|
+
});
|