@wp-blocks/make-pot 1.4.0 → 1.5.1
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/block-i18n.js.map +7 -0
- package/lib/assets/package-i18n.js +1 -1
- package/lib/assets/package-i18n.js.map +7 -0
- package/lib/assets/theme-i18n.js.map +7 -0
- package/lib/assets/wp-plugin-i18n.js.map +7 -0
- package/lib/assets/wp-theme-i18n.js.map +7 -0
- package/lib/cli/getArgs.js +1 -1
- package/lib/cli/getArgs.js.map +7 -0
- package/lib/cli/getJsonArgs.js +1 -1
- package/lib/cli/getJsonArgs.js.map +7 -0
- package/lib/cli/parseCli.js +1 -1
- package/lib/cli/parseCli.js.map +7 -0
- package/lib/cli.js +2 -0
- package/lib/cli.js.map +7 -0
- package/lib/const.js +1 -1
- package/lib/const.js.map +7 -0
- package/lib/extractors/css.js +1 -1
- package/lib/extractors/css.js.map +7 -0
- package/lib/extractors/headers.js +6 -1
- package/lib/extractors/headers.js.map +7 -0
- package/lib/extractors/json.js +1 -1
- package/lib/extractors/json.js.map +7 -0
- package/lib/extractors/packageJson.js +1 -0
- package/lib/extractors/packageJson.js.map +7 -0
- package/lib/extractors/php.js +2 -2
- package/lib/extractors/php.js.map +7 -0
- package/lib/extractors/schema.js +4 -1
- package/lib/extractors/schema.js.map +7 -0
- package/lib/extractors/text.js +1 -1
- package/lib/extractors/text.js.map +7 -0
- package/lib/fs/fs.js +2 -1
- package/lib/fs/fs.js.map +7 -0
- package/lib/fs/glob.js +1 -3
- package/lib/fs/glob.js.map +7 -0
- package/lib/index.js +1 -2
- package/lib/index.js.map +7 -0
- package/lib/jsonCommand.js +1 -2
- package/lib/jsonCommand.js.map +7 -0
- package/lib/makeJson.js +2 -0
- package/lib/makeJson.js.map +7 -0
- package/lib/makePot.js +2 -0
- package/lib/makePot.js.map +7 -0
- package/lib/parser/exec.js +7 -3
- package/lib/parser/exec.js.map +7 -0
- package/lib/parser/makeJson.js +1 -3
- package/lib/parser/makeJson.js.map +7 -0
- package/lib/parser/makePot.js +1 -1
- package/lib/parser/makePot.js.map +7 -0
- package/lib/parser/patterns.js +1 -1
- package/lib/parser/patterns.js.map +7 -0
- package/lib/parser/process.js +1 -1
- package/lib/parser/process.js.map +7 -0
- package/lib/parser/progress.js +1 -1
- package/lib/parser/progress.js.map +7 -0
- package/lib/parser/taskRunner.js +2 -1
- package/lib/parser/taskRunner.js.map +7 -0
- package/lib/parser/tree.js +1 -1
- package/lib/parser/tree.js.map +7 -0
- package/lib/potCommand.js +1 -1
- package/lib/potCommand.js.map +7 -0
- package/lib/types.js +1 -1
- package/lib/types.js.map +7 -0
- package/lib/utils/common.js +4 -2
- package/lib/utils/common.js.map +7 -0
- package/lib/utils/extractors.js +1 -0
- package/lib/utils/extractors.js.map +7 -0
- package/package.json +22 -22
- package/tests/extract-headers.test.js +54 -0
- package/tests/extract.test.js +381 -381
- package/tests/jsonParse.test.js +167 -0
- package/tests/parse-headers.test.js +74 -0
- package/tests/tree.test.js +158 -158
- package/tsconfig.json +2 -0
- package/lib/extractors/utils.js +0 -1
- package/tests/getFiles.test.no.js +0 -85
- package/tests/jsonParse.no.js +0 -49
- package/tests/wpcliCompare.no.js +0 -32
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const { describe, it } = require("node:test");
|
|
3
|
+
const assert = require("node:assert");
|
|
4
|
+
const { parseJsonFile } = require("../lib");
|
|
5
|
+
|
|
6
|
+
describe("should parse json", () => {
|
|
7
|
+
describe("should parse block.json", () => {
|
|
8
|
+
it("block.json", async () => {
|
|
9
|
+
const expected = [
|
|
10
|
+
{
|
|
11
|
+
msgid: "block title",
|
|
12
|
+
msgctxt: "my block title",
|
|
13
|
+
comments: {
|
|
14
|
+
reference: ["block.json"],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
msgid: "block description",
|
|
19
|
+
msgctxt: "my block description",
|
|
20
|
+
comments: {
|
|
21
|
+
reference: ["block.json"],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
msgid: "block keyword",
|
|
26
|
+
msgctxt: "my block keyword",
|
|
27
|
+
comments: {
|
|
28
|
+
reference: ["block.json"],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
msgid: "block keyword",
|
|
33
|
+
msgctxt: "my block keyword 2",
|
|
34
|
+
comments: {
|
|
35
|
+
reference: ["block.json"],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
msgid: "block keyword",
|
|
40
|
+
msgctxt: "my block keyword 3",
|
|
41
|
+
comments: {
|
|
42
|
+
reference: ["block.json"],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const result = await parseJsonFile({
|
|
48
|
+
fileContent: fs.readFileSync("tests/fixtures/block/block.json", "utf8"),
|
|
49
|
+
filename: "block.json",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
assert.deepStrictEqual(result, expected);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("should parse theme.json", () => {
|
|
57
|
+
it("theme.json", async () => {
|
|
58
|
+
const expected = [
|
|
59
|
+
{
|
|
60
|
+
msgid: "Font size name",
|
|
61
|
+
msgctxt: "Extra small",
|
|
62
|
+
comments: {
|
|
63
|
+
reference: ["block.json"],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
msgid: "Font size name",
|
|
68
|
+
msgctxt: "Small",
|
|
69
|
+
comments: {
|
|
70
|
+
reference: ["block.json"],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
msgid: "Font size name",
|
|
75
|
+
msgctxt: "Medium",
|
|
76
|
+
comments: {
|
|
77
|
+
reference: ["block.json"],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
msgid: "Font size name",
|
|
82
|
+
msgctxt: "Large",
|
|
83
|
+
comments: {
|
|
84
|
+
reference: ["block.json"],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
msgid: "Font size name",
|
|
89
|
+
msgctxt: "Extra large",
|
|
90
|
+
comments: {
|
|
91
|
+
reference: ["block.json"],
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
msgid: "Font family name",
|
|
96
|
+
msgctxt: "System Fonts",
|
|
97
|
+
comments: {
|
|
98
|
+
reference: ["block.json"],
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
msgid: "Color name",
|
|
103
|
+
msgctxt: "Base",
|
|
104
|
+
comments: {
|
|
105
|
+
reference: ["block.json"],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
msgid: "Color name",
|
|
110
|
+
msgctxt: "Contrast",
|
|
111
|
+
comments: {
|
|
112
|
+
reference: ["block.json"],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
msgid: "Color name",
|
|
117
|
+
msgctxt: "Accent",
|
|
118
|
+
comments: {
|
|
119
|
+
reference: ["block.json"],
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
msgid: "Color name",
|
|
124
|
+
msgctxt: "Accent Two",
|
|
125
|
+
comments: {
|
|
126
|
+
reference: ["block.json"],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
msgid: "Color name",
|
|
131
|
+
msgctxt: "Accent Three",
|
|
132
|
+
comments: {
|
|
133
|
+
reference: ["block.json"],
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
msgid: "Gradient name",
|
|
138
|
+
msgctxt: "Accent Two to Contrast",
|
|
139
|
+
comments: {
|
|
140
|
+
reference: ["block.json"],
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
msgid: "Template part name",
|
|
145
|
+
msgctxt: "Header",
|
|
146
|
+
comments: {
|
|
147
|
+
reference: ["block.json"],
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
msgid: "Template part name",
|
|
152
|
+
msgctxt: "Footer",
|
|
153
|
+
comments: {
|
|
154
|
+
reference: ["block.json"],
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
const result = await parseJsonFile({
|
|
160
|
+
fileContent: fs.readFileSync("tests/fixtures/fse/theme.json", "utf8"),
|
|
161
|
+
filename: "theme.json",
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
assert.deepStrictEqual(result, expected);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const { describe, it } = require("node:test");
|
|
3
|
+
const assert = require("node:assert");
|
|
4
|
+
const { generateHeader, getAuthorFromPackage } = require("../lib");
|
|
5
|
+
const { join } = require("node:path");
|
|
6
|
+
|
|
7
|
+
describe("Header generation", () => {
|
|
8
|
+
describe("Should generate a valid header", () => {
|
|
9
|
+
it("from user full data", async () => {
|
|
10
|
+
const expected = {};
|
|
11
|
+
const author = await getAuthorFromPackage({
|
|
12
|
+
authors: ["John Doe <1dHsK@example.com> (http://example.com)"],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
assert.deepStrictEqual(author, {
|
|
16
|
+
name: "John Doe",
|
|
17
|
+
email: "1dHsK@example.com",
|
|
18
|
+
website: "http://example.com",
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("from user data", async () => {
|
|
23
|
+
const expected = {};
|
|
24
|
+
const author = await getAuthorFromPackage({
|
|
25
|
+
authors: ["erik"],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
assert.deepStrictEqual(author, {
|
|
29
|
+
name: "erik",
|
|
30
|
+
email: undefined,
|
|
31
|
+
website: undefined,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("from package.json data", async () => {
|
|
36
|
+
const expected = {
|
|
37
|
+
"Project-Id-Version": "plugin 1.0.0",
|
|
38
|
+
"Report-Msgid-Bugs-To": "John Doe <bbb@ccc.ddd>",
|
|
39
|
+
"MIME-Version": "1.0",
|
|
40
|
+
"Content-Transfer-Encoding": "8bit",
|
|
41
|
+
"content-type": "text/plain; charset=iso-8859-1",
|
|
42
|
+
"plural-forms": "nplurals=2; plural=(n!=1);",
|
|
43
|
+
"POT-Creation-Date": undefined,
|
|
44
|
+
"PO-Revision-Date": undefined,
|
|
45
|
+
"Last-Translator": "John Doe <bbb@ccc.ddd>",
|
|
46
|
+
"Language-Team": "John Doe <bbb@ccc.ddd>",
|
|
47
|
+
"X-Generator": "@wp-blocks/make-pot 1.5.1",
|
|
48
|
+
Language: "en",
|
|
49
|
+
"X-Domain": "plugin",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const result = await generateHeader({
|
|
53
|
+
headers: {
|
|
54
|
+
name: "my-block",
|
|
55
|
+
author: "John Doe",
|
|
56
|
+
version: "1.0.0",
|
|
57
|
+
license: "MIT",
|
|
58
|
+
homepage: "https://example.com",
|
|
59
|
+
repository: "https://github.com/example/my-block",
|
|
60
|
+
domain: "my-plugin-text-domain",
|
|
61
|
+
},
|
|
62
|
+
paths: {
|
|
63
|
+
cwd: join(process.cwd(), "tests/fixtures/plugin"),
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// remove the date "POT-Creation-Date"
|
|
68
|
+
result["POT-Creation-Date"] = undefined;
|
|
69
|
+
result["PO-Revision-Date"] = undefined;
|
|
70
|
+
|
|
71
|
+
assert.deepStrictEqual(result, expected);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
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/tsconfig.json
CHANGED
package/lib/extractors/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var a=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var x=(n,t)=>{for(var e in t)a(n,e,{get:t[e],enumerable:!0})},p=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of m(t))!y.call(n,s)&&s!==e&&a(n,s,{get:()=>t[s],enumerable:!(r=k(t,s))||r.enumerable});return n};var B=n=>p(a({},"__esModule",{value:!0}),n);var j={};x(j,{gentranslation:()=>l,getKeyByValue:()=>O,yieldParsedData:()=>b});module.exports=B(j);var g=require("gettext-merger"),d=require("./json.js");function O(n,t){return Object.keys(n).find(e=>n[e]===t)??void 0}const l=(n,t,e)=>{const r=new g.Block([]);return r.msgctxt=void 0,r.msgid=t,r.msgid_plural="",r.msgstr=[],r.comments={extracted:[n],reference:[e]},r};function b(n,t,e){const r=new g.SetOfBlocks([],e);return n&&(r.path=e,Object.entries(n).forEach(([s,o])=>{function f(i,c=s){const u=l((0,d.getJsonComment)(s,t),c,e);r.add(u)}if(o)typeof o=="string"?f(o):Array.isArray(o)?o.forEach(i=>f(i)):Object.entries(o).forEach(([i,c])=>{typeof c=="string"&&f(c,i)});else return})),r}0&&(module.exports={gentranslation,getKeyByValue,yieldParsedData});
|
|
@@ -1,85 +0,0 @@
|
|
|
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
|
-
});
|