@wp-blocks/make-pot 1.3.2 → 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.
@@ -1,381 +1,381 @@
1
- const { describe, it, beforeEach, before } = require("node:test");
2
- const assert = require("node:assert");
3
- const { Block } = require("gettext-merger");
4
- const { doTree } = require("../lib/");
5
-
6
- describe("getStrings", () => {
7
- it("should extract translations from js", () => {
8
- const content = `var foo = __('Hello World', 'greeting');`;
9
- const filename = "filename.js";
10
-
11
- const result = doTree(content, filename);
12
- const expected = new Block([]);
13
- expected.msgid = "Hello World";
14
- expected.comments = {
15
- reference: ["filename.js:1"],
16
- translator: [""],
17
- };
18
-
19
- assert.strictEqual(result.blocks[0].msgid, expected.msgid);
20
- });
21
-
22
- it("should extract translations from ts", () => {
23
- const content = `__('Hello World', 'greeting');`;
24
- const filename = "filename.ts";
25
-
26
- const result = doTree(content, filename).blocks[0].toJson();
27
-
28
- const expected = new Block([]);
29
- expected.msgid = "Hello World";
30
- expected.comments = {
31
- reference: ["filename.ts:1"],
32
- translator: [""],
33
- };
34
-
35
- assert.strictEqual(result.msgid, expected.msgid);
36
- assert.strictEqual(expected.comments?.reference.length, 1);
37
- assert.deepStrictEqual(
38
- [result.comments.reference],
39
- expected.comments.reference,
40
- );
41
- });
42
-
43
- it("should extract translations from tsx", () => {
44
- const content = `const element = <h1>{ __('Hello World', 'greeting')}</h1>;`;
45
-
46
- const filename = "filename.tsx";
47
-
48
- const result = doTree(content, filename);
49
-
50
- const expected = new Block([]);
51
- expected.msgid = "Hello World";
52
- expected.msgstr = [""];
53
- expected.comments = {
54
- reference: ["filename.tsx:1"],
55
- translator: [""],
56
- };
57
-
58
- assert.deepStrictEqual(result.blocks[0].toJson(), expected.toJson());
59
- });
60
-
61
- it("should extract translations with context", () => {
62
- const content = `<?php __('Hello World', 'greeting'); ?>`;
63
- const filename = "filename.php";
64
-
65
- const result = doTree(content, filename);
66
-
67
- const expected = new Block([]);
68
- expected.msgid = "Hello World";
69
- expected.msgstr = [""];
70
- expected.comments = {
71
- reference: ["filename.php:1"],
72
- translator: [""],
73
- };
74
-
75
- assert.deepStrictEqual(result.blocks[0].toJson(), expected.toJson());
76
- });
77
-
78
- it("should extract translations from code content with no context or translator comments", () => {
79
- const content = `<?php _e('Hello World'); ?>`;
80
- const expected = new Block([]);
81
- expected.msgctxt = undefined;
82
- expected.msgid = "Hello World";
83
- expected.msgid_plural = undefined;
84
- expected.msgstr = [""];
85
- expected.comments = {
86
- translator: undefined,
87
- reference: ["filename.php:1"],
88
- };
89
- const filename = "filename.php";
90
-
91
- const result = doTree(content, filename);
92
-
93
- assert.deepEqual(result.blocks[0], expected);
94
- });
95
-
96
- it("should extract translations with comments", () => {
97
- const filename = "filename.php";
98
- const content = `
99
- <?php /** translators: ciao! */ echo _x('Hello World', 'greeting'); ?>`;
100
- const expectedComments = {
101
- reference: ["filename.php:2"],
102
- translator: ["ciao!"],
103
- };
104
-
105
- const result = doTree(content, filename);
106
-
107
- assert.deepEqual(result.blocks[0].comments, expectedComments);
108
- });
109
-
110
- it("should extract translations with comments reporting the right position", () => {
111
- const filename = "filename.php";
112
- const content = `
113
-
114
-
115
-
116
- /** line 5*/
117
-
118
-
119
-
120
-
121
- <?php echo _x('Hello World', 'greeting'); ?>`;
122
- const expected = `#: filename.php:10
123
- msgctxt "greeting"
124
- msgid "Hello World"
125
- msgstr ""`;
126
-
127
- const result = doTree(content, filename);
128
-
129
- assert.strictEqual(result.blocks[0].toStr(), expected);
130
- });
131
-
132
- it("should extract translations inside a sprint", () => {
133
- const filename = "filename.php";
134
- const content = ` <?php
135
- $url = 'http://example.com';
136
- $link = sprintf( wp_kses( __( 'Check out this link to my <a href="%s">website</a> made with WordPress.', 'my-text-domain' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $url ) );
137
- echo $link;`;
138
- const expected = {
139
- "": {
140
- 'Check out this link to my <a href="%s">website</a> made with WordPress.':
141
- {
142
- comments: {
143
- extracted: "",
144
- flag: "",
145
- previous: "",
146
- reference: "filename.php:3",
147
- translator: "",
148
- },
149
- msgctxt: "",
150
- msgid:
151
- 'Check out this link to my <a href="%s">website</a> made with WordPress.',
152
- msgid_plural: undefined,
153
- msgstr: [""],
154
- },
155
- },
156
- };
157
-
158
- const result = doTree(content, filename);
159
-
160
- assert.deepStrictEqual(result.toJson(), expected);
161
- });
162
- });
163
-
164
- describe("getStrings wp cli", () => {
165
- it("should extract from an array of translations", () => {
166
- const filename = "filename.php";
167
- const content = `<?php $var = 'don't do this'; $instructions = array(
168
- "Overview" => array(
169
- "title" => __( 'Overview', '3d-product-viewer' ),
170
- "text" => __( "Hold down the right button to move the model", '3d-product-viewer' ),
171
- "icon" => 'icon-book'
172
- ),
173
- "Rotation" => array(
174
- "title" => __( 'Rotation', '3d-product-viewer' ),
175
- "text" => __( "Left-click and drag to change the angle", '3d-product-viewer' ),
176
- "icon" => 'icon-rotation'
177
- ),
178
- "Zoom" => array(
179
- "title" => __( 'Zoom', '3d-product-viewer' ),
180
- "text" => __( "Variable is % and not {$var}", '3d-product-viewer' ),
181
- "icon" => 'icon-zoom'
182
- )
183
- );
184
- `;
185
-
186
- const result = doTree(content, filename);
187
- assert.deepStrictEqual(result.blocks[0].msgid, "Overview");
188
- });
189
-
190
- it("should extract translations with translator comments inside the formatting hell", () => {
191
- const filename = "filename.php";
192
- const content = `<?php if ( count( $errors_in_remigrate_batch ) > 0 ) {
193
- $formatted_errors = wp_json_encode( $errors_in_remigrate_batch, JSON_PRETTY_PRINT );
194
- WP_CLI::warning(
195
- sprintf(
196
- /* Translators: %1$d is number of errors and %2$s is the formatted array of order IDs. */
197
- _n(
198
- '%1$d error found: %2$s when re-migrating order. Please review the error above.',
199
- '%1$d errors found: %2$s when re-migrating orders. Please review the errors above.',
200
- count( %s ),
201
- 'woocommerce'
202
- ),
203
- count( $errors_in_remigrate_batch ),
204
- $formatted_errors
205
- )
206
- );
207
- } else {
208
- WP_CLI::warning( 'Re-migration successful.', 'woocommerce' );
209
- }
210
- `;
211
-
212
- const result = doTree(content, filename);
213
- assert.strictEqual(
214
- "%1$d error found: %2$s when re-migrating order. Please review the error above.",
215
- result.blocks[0].msgid,
216
- );
217
- });
218
-
219
- /** see https://github.com/wp-cli/i18n-command/blob/main/features/makepot.feature */
220
- it("should extract translations and comments from code content", () => {
221
- const content = `<?php
222
-
223
- And a foo-plugin/foo-plugin.php file:
224
- """
225
- <?php
226
- /**
227
- */
228
- __( 'Hello World', 'foo-plugin' );
229
- """
230
- And a foo-plugin/vendor/ignored.php file:
231
- """
232
- <?php
233
- __( 'I am being ignored', 'foo-plugin' );
234
- """
235
- __( '__', 'foo-plugin' );
236
- esc_attr__( 'esc_attr__', 'foo-plugin' );
237
- esc_html__( 'esc_html__', 'foo-plugin' );
238
- esc_xml__( 'esc_xml__', 'foo-plugin' );
239
- _e( '_e', 'foo-plugin' );
240
- esc_attr_e( 'esc_attr_e', 'foo-plugin' );
241
- esc_html_e( 'esc_html_e', 'foo-plugin' );
242
- esc_xml_e( 'esc_xml_e', 'foo-plugin' );
243
- _x( '_x', '_x_context', 'foo-plugin' );
244
- _ex( '_ex', '_ex_context', 'foo-plugin' );
245
- esc_attr_x( 'esc_attr_x', 'esc_attr_x_context', 'foo-plugin' );
246
- esc_html_x( 'esc_html_x', 'esc_html_x_context', 'foo-plugin' );
247
- esc_xml_x( 'esc_xml_x', 'esc_xml_x_context', 'foo-plugin' );
248
- _n( '_n_single', '_n_plural', $number, 'foo-plugin' );
249
- _nx( '_nx_single', '_nx_plural', $number, '_nx_context', 'foo-plugin' );
250
- _n_noop( '_n_noop_single', '_n_noop_plural', 'foo-plugin' );
251
- _nx_noop( '_nx_noop_single', '_nx_noop_plural', '_nx_noop_context', 'foo-plugin' );
252
-
253
- // Compat.
254
- _( '_', 'foo-plugin' );
255
-
256
- // Deprecated.
257
- _c( '_c', 'foo-plugin' );
258
- _nc( '_nc_single', '_nc_plural', $number, 'foo-plugin' );
259
- __ngettext( '__ngettext_single', '__ngettext_plural', $number, 'foo-plugin' );
260
- __ngettext_noop( '__ngettext_noop_single', '__ngettext_noop_plural', 'foo-plugin' );
261
-
262
- __unsupported_func( '__unsupported_func', 'foo-plugin' );
263
- __( 'wrong-domain', 'wrong-domain' );
264
-
265
- // See https://github.com/wp-cli/i18n-command/issues/344
266
- \\__( '\\__', 'foo-plugin' );
267
- \\_e( '\\_e', 'foo-plugin' );
268
- // Included to test if peast correctly parses regexes containing a quote.
269
- // See: https://github.com/wp-cli/i18n-command/issues/98
270
- n = n.replace(/"/g, '&quot;');
271
- n = n.replace(/"|'/g, '&quot;');
272
-
273
- __( '__', 'foo-plugin' );
274
- _x( '_x', '_x_context', 'foo-plugin' );
275
- _n( '_n_single', '_n_plural', number, 'foo-plugin' );
276
- _nx( '_nx_single', '_nx_plural', number, '_nx_context', 'foo-plugin' );
277
-
278
- __( 'wrong-domain', 'wrong-domain' );
279
-
280
- __( 'Hello world' ); // translators: Greeting`;
281
-
282
- const filename = "filename.php";
283
-
284
- const result = doTree(content, filename);
285
-
286
- assert.strictEqual(result.blocks.length, 26);
287
- });
288
-
289
- /** see wp cli tests */
290
- it("should extract translations and comments from code content", () => {
291
- const content = `<?php
292
-
293
- // translators: Foo Bar Comment
294
- __( 'Foo Bar', 'foo-plugin' );
295
-
296
- // TrANslAtORs: Bar Baz Comment
297
- __( 'Bar Baz', 'foo-plugin' );
298
-
299
- // translators: Software name
300
- const string = __( 'WordPress', 'foo-plugin' );
301
-
302
- // translators: So much space
303
-
304
- __( 'Spacey text', 'foo-plugin' );
305
-
306
- /* translators: Long comment
307
- spanning multiple
308
- lines */
309
- const string = __( 'Short text', 'foo-plugin' );
310
-
311
- ReactDOM.render(
312
- <h1>{__( 'Hello JSX', 'foo-plugin' )}</h1>,
313
- document.getElementById('root')
314
- );
315
-
316
- wp.i18n.__( 'wp.i18n.__', 'foo-plugin' );
317
- wp.i18n._n( 'wp.i18n._n_single', 'wp.i18n._n_plural', number, 'foo-plugin' );
318
-
319
- const translate = wp.i18n;
320
- translate.__( 'translate.__', 'foo-plugin' );
321
-
322
- Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__["__"])( 'webpack.__', 'foo-plugin' );
323
- Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__[/* __ */ "a"])( 'webpack.mangle.__', 'foo-plugin' );
324
-
325
- Object(u.__)( 'minified.__', 'foo-plugin' );
326
- Object(j._x)( 'minified._x', 'minified._x_context', 'foo-plugin' );
327
-
328
- /* translators: babel */
329
- (0, __)( 'babel.__', 'foo-plugin' );
330
- (0, _i18n.__)( 'babel-i18n.__', 'foo-plugin' );
331
- (0, _i18n._x)( 'babel-i18n._x', 'babel-i18n._x_context', 'foo-plugin' );
332
-
333
- eval( "__( 'Hello Eval World', 'foo-plugin' );" );
334
-
335
- __( \`This is a \${bug}\`, 'foo-plugin' );
336
-
337
- /**
338
- * Plugin Name: Plugin name
339
- */
340
-
341
- /* translators: Translators 1! */
342
- _e( 'hello world', 'foo-plugin' );
343
-
344
- /* Translators: Translators 2! */
345
- $foo = __( 'foo', 'foo-plugin' );
346
-
347
- /* translators: localized date and time format, see https://secure.php.net/date */
348
- __( 'F j, Y g:i a', 'foo-plugin' );
349
-
350
- // translators: let your ears fly!
351
- __( 'on', 'foo-plugin' );
352
-
353
- /*
354
- * Translators: If there are characters in your language that are not supported
355
- * by Lato, translate this to 'off'. Do not translate into your own language.
356
- */
357
- __( 'off', 'foo-plugin' );
358
-
359
- /* translators: this should get extracted. */ $foo = __( 'baba', 'foo-plugin' );
360
-
361
- /* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g( __( 'bubu', 'foo-plugin' ) );
362
-
363
- {TAB}/*
364
- {TAB} * translators: this comment block is indented with a tab and should get extracted too.
365
- {TAB} */
366
- {TAB}__( 'yolo', 'foo-plugin' );
367
-
368
- /* translators: This is a comment */
369
- __( 'Plugin name', 'foo-plugin' );
370
-
371
- /* Translators: This is another comment! */
372
- __( 'https://example.com', 'foo-plugin' );
373
- `;
374
-
375
- const filename = "filename.php";
376
-
377
- const result = doTree(content, filename);
378
-
379
- assert.strictEqual(result.blocks.length, 20);
380
- });
381
- });
1
+ const { describe, it, beforeEach, before } = require("node:test");
2
+ const assert = require("node:assert");
3
+ const { Block } = require("gettext-merger");
4
+ const { doTree } = require("../lib");
5
+
6
+ describe("getStrings", () => {
7
+ it("should extract translations from js", () => {
8
+ const content = `var foo = __('Hello World', 'greeting');`;
9
+ const filename = "filename.js";
10
+
11
+ const result = doTree(content, filename);
12
+ const expected = new Block([]);
13
+ expected.msgid = "Hello World";
14
+ expected.comments = {
15
+ reference: ["filename.js:1"],
16
+ translator: [""],
17
+ };
18
+
19
+ assert.strictEqual(result.blocks[0].msgid, expected.msgid);
20
+ });
21
+
22
+ it("should extract translations from ts", () => {
23
+ const content = `__('Hello World', 'greeting');`;
24
+ const filename = "filename.ts";
25
+
26
+ const result = doTree(content, filename).blocks[0].toJson();
27
+
28
+ const expected = new Block([]);
29
+ expected.msgid = "Hello World";
30
+ expected.comments = {
31
+ reference: ["filename.ts:1"],
32
+ translator: [""],
33
+ };
34
+
35
+ assert.strictEqual(result.msgid, expected.msgid);
36
+ assert.strictEqual(expected.comments?.reference.length, 1);
37
+ assert.deepStrictEqual(
38
+ [result.comments.reference],
39
+ expected.comments.reference,
40
+ );
41
+ });
42
+
43
+ it("should extract translations from tsx", () => {
44
+ const content = `const element = <h1>{ __('Hello World', 'greeting')}</h1>;`;
45
+
46
+ const filename = "filename.tsx";
47
+
48
+ const result = doTree(content, filename);
49
+
50
+ const expected = new Block([]);
51
+ expected.msgid = "Hello World";
52
+ expected.msgstr = [""];
53
+ expected.comments = {
54
+ reference: ["filename.tsx:1"],
55
+ translator: [""],
56
+ };
57
+
58
+ assert.deepStrictEqual(result.blocks[0].toJson(), expected.toJson());
59
+ });
60
+
61
+ it("should extract translations with context", () => {
62
+ const content = `<?php __('Hello World', 'greeting'); ?>`;
63
+ const filename = "filename.php";
64
+
65
+ const result = doTree(content, filename);
66
+
67
+ const expected = new Block([]);
68
+ expected.msgid = "Hello World";
69
+ expected.msgstr = [""];
70
+ expected.comments = {
71
+ reference: ["filename.php:1"],
72
+ translator: [""],
73
+ };
74
+
75
+ assert.deepStrictEqual(result.blocks[0].toJson(), expected.toJson());
76
+ });
77
+
78
+ it("should extract translations from code content with no context or translator comments", () => {
79
+ const content = `<?php _e('Hello World'); ?>`;
80
+ const expected = new Block([]);
81
+ expected.msgctxt = undefined;
82
+ expected.msgid = "Hello World";
83
+ expected.msgid_plural = undefined;
84
+ expected.msgstr = [""];
85
+ expected.comments = {
86
+ translator: undefined,
87
+ reference: ["filename.php:1"],
88
+ };
89
+ const filename = "filename.php";
90
+
91
+ const result = doTree(content, filename);
92
+
93
+ assert.deepEqual(result.blocks[0], expected);
94
+ });
95
+
96
+ it("should extract translations with comments", () => {
97
+ const filename = "filename.php";
98
+ const content = `
99
+ <?php /** translators: ciao! */ echo _x('Hello World', 'greeting'); ?>`;
100
+ const expectedComments = {
101
+ reference: ["filename.php:2"],
102
+ translator: ["ciao!"],
103
+ };
104
+
105
+ const result = doTree(content, filename);
106
+
107
+ assert.deepEqual(result.blocks[0].comments, expectedComments);
108
+ });
109
+
110
+ it("should extract translations with comments reporting the right position", () => {
111
+ const filename = "filename.php";
112
+ const content = `
113
+
114
+
115
+
116
+ /** line 5*/
117
+
118
+
119
+
120
+
121
+ <?php echo _x('Hello World', 'greeting'); ?>`;
122
+ const expected = `#: filename.php:10
123
+ msgctxt "greeting"
124
+ msgid "Hello World"
125
+ msgstr ""`;
126
+
127
+ const result = doTree(content, filename);
128
+
129
+ assert.strictEqual(result.blocks[0].toStr(), expected);
130
+ });
131
+
132
+ it("should extract translations inside a sprint", () => {
133
+ const filename = "filename.php";
134
+ const content = ` <?php
135
+ $url = 'http://example.com';
136
+ $link = sprintf( wp_kses( __( 'Check out this link to my <a href="%s">website</a> made with WordPress.', 'my-text-domain' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $url ) );
137
+ echo $link;`;
138
+ const expected = {
139
+ "": {
140
+ 'Check out this link to my <a href="%s">website</a> made with WordPress.':
141
+ {
142
+ comments: {
143
+ extracted: "",
144
+ flag: "",
145
+ previous: "",
146
+ reference: "filename.php:3",
147
+ translator: "",
148
+ },
149
+ msgctxt: "",
150
+ msgid:
151
+ 'Check out this link to my <a href="%s">website</a> made with WordPress.',
152
+ msgid_plural: undefined,
153
+ msgstr: [""],
154
+ },
155
+ },
156
+ };
157
+
158
+ const result = doTree(content, filename);
159
+
160
+ assert.deepStrictEqual(result.toJson(), expected);
161
+ });
162
+ });
163
+
164
+ describe("getStrings wp cli", () => {
165
+ it("should extract from an array of translations", () => {
166
+ const filename = "filename.php";
167
+ const content = `<?php $var = 'don't do this'; $instructions = array(
168
+ "Overview" => array(
169
+ "title" => __( 'Overview', '3d-product-viewer' ),
170
+ "text" => __( "Hold down the right button to move the model", '3d-product-viewer' ),
171
+ "icon" => 'icon-book'
172
+ ),
173
+ "Rotation" => array(
174
+ "title" => __( 'Rotation', '3d-product-viewer' ),
175
+ "text" => __( "Left-click and drag to change the angle", '3d-product-viewer' ),
176
+ "icon" => 'icon-rotation'
177
+ ),
178
+ "Zoom" => array(
179
+ "title" => __( 'Zoom', '3d-product-viewer' ),
180
+ "text" => __( "Variable is % and not {$var}", '3d-product-viewer' ),
181
+ "icon" => 'icon-zoom'
182
+ )
183
+ );
184
+ `;
185
+
186
+ const result = doTree(content, filename);
187
+ assert.deepStrictEqual(result.blocks[0].msgid, "Overview");
188
+ });
189
+
190
+ it("should extract translations with translator comments inside the formatting hell", () => {
191
+ const filename = "filename.php";
192
+ const content = `<?php if ( count( $errors_in_remigrate_batch ) > 0 ) {
193
+ $formatted_errors = wp_json_encode( $errors_in_remigrate_batch, JSON_PRETTY_PRINT );
194
+ WP_CLI::warning(
195
+ sprintf(
196
+ /* Translators: %1$d is number of errors and %2$s is the formatted array of order IDs. */
197
+ _n(
198
+ '%1$d error found: %2$s when re-migrating order. Please review the error above.',
199
+ '%1$d errors found: %2$s when re-migrating orders. Please review the errors above.',
200
+ count( %s ),
201
+ 'woocommerce'
202
+ ),
203
+ count( $errors_in_remigrate_batch ),
204
+ $formatted_errors
205
+ )
206
+ );
207
+ } else {
208
+ WP_CLI::warning( 'Re-migration successful.', 'woocommerce' );
209
+ }
210
+ `;
211
+
212
+ const result = doTree(content, filename);
213
+ assert.strictEqual(
214
+ "%1$d error found: %2$s when re-migrating order. Please review the error above.",
215
+ result.blocks[0].msgid,
216
+ );
217
+ });
218
+
219
+ /** see https://github.com/wp-cli/i18n-command/blob/main/features/makepot.feature */
220
+ it("should extract translations and comments from code content", () => {
221
+ const content = `<?php
222
+
223
+ And a foo-plugin/foo-plugin.php file:
224
+ """
225
+ <?php
226
+ /**
227
+ */
228
+ __( 'Hello World', 'foo-plugin' );
229
+ """
230
+ And a foo-plugin/vendor/ignored.php file:
231
+ """
232
+ <?php
233
+ __( 'I am being ignored', 'foo-plugin' );
234
+ """
235
+ __( '__', 'foo-plugin' );
236
+ esc_attr__( 'esc_attr__', 'foo-plugin' );
237
+ esc_html__( 'esc_html__', 'foo-plugin' );
238
+ esc_xml__( 'esc_xml__', 'foo-plugin' );
239
+ _e( '_e', 'foo-plugin' );
240
+ esc_attr_e( 'esc_attr_e', 'foo-plugin' );
241
+ esc_html_e( 'esc_html_e', 'foo-plugin' );
242
+ esc_xml_e( 'esc_xml_e', 'foo-plugin' );
243
+ _x( '_x', '_x_context', 'foo-plugin' );
244
+ _ex( '_ex', '_ex_context', 'foo-plugin' );
245
+ esc_attr_x( 'esc_attr_x', 'esc_attr_x_context', 'foo-plugin' );
246
+ esc_html_x( 'esc_html_x', 'esc_html_x_context', 'foo-plugin' );
247
+ esc_xml_x( 'esc_xml_x', 'esc_xml_x_context', 'foo-plugin' );
248
+ _n( '_n_single', '_n_plural', $number, 'foo-plugin' );
249
+ _nx( '_nx_single', '_nx_plural', $number, '_nx_context', 'foo-plugin' );
250
+ _n_noop( '_n_noop_single', '_n_noop_plural', 'foo-plugin' );
251
+ _nx_noop( '_nx_noop_single', '_nx_noop_plural', '_nx_noop_context', 'foo-plugin' );
252
+
253
+ // Compat.
254
+ _( '_', 'foo-plugin' );
255
+
256
+ // Deprecated.
257
+ _c( '_c', 'foo-plugin' );
258
+ _nc( '_nc_single', '_nc_plural', $number, 'foo-plugin' );
259
+ __ngettext( '__ngettext_single', '__ngettext_plural', $number, 'foo-plugin' );
260
+ __ngettext_noop( '__ngettext_noop_single', '__ngettext_noop_plural', 'foo-plugin' );
261
+
262
+ __unsupported_func( '__unsupported_func', 'foo-plugin' );
263
+ __( 'wrong-domain', 'wrong-domain' );
264
+
265
+ // See https://github.com/wp-cli/i18n-command/issues/344
266
+ \\__( '\\__', 'foo-plugin' );
267
+ \\_e( '\\_e', 'foo-plugin' );
268
+ // Included to test if peast correctly parses regexes containing a quote.
269
+ // See: https://github.com/wp-cli/i18n-command/issues/98
270
+ n = n.replace(/"/g, '&quot;');
271
+ n = n.replace(/"|'/g, '&quot;');
272
+
273
+ __( '__', 'foo-plugin' );
274
+ _x( '_x', '_x_context', 'foo-plugin' );
275
+ _n( '_n_single', '_n_plural', number, 'foo-plugin' );
276
+ _nx( '_nx_single', '_nx_plural', number, '_nx_context', 'foo-plugin' );
277
+
278
+ __( 'wrong-domain', 'wrong-domain' );
279
+
280
+ __( 'Hello world' ); // translators: Greeting`;
281
+
282
+ const filename = "filename.php";
283
+
284
+ const result = doTree(content, filename);
285
+
286
+ assert.strictEqual(result.blocks.length, 27);
287
+ });
288
+
289
+ /** see wp cli tests */
290
+ it("should extract translations and comments from code content", () => {
291
+ const content = `<?php
292
+
293
+ // translators: Foo Bar Comment
294
+ __( 'Foo Bar', 'foo-plugin' );
295
+
296
+ // TrANslAtORs: Bar Baz Comment
297
+ __( 'Bar Baz', 'foo-plugin' );
298
+
299
+ // translators: Software name
300
+ const string = __( 'WordPress', 'foo-plugin' );
301
+
302
+ // translators: So much space
303
+
304
+ __( 'Spacey text', 'foo-plugin' );
305
+
306
+ /* translators: Long comment
307
+ spanning multiple
308
+ lines */
309
+ const string = __( 'Short text', 'foo-plugin' );
310
+
311
+ ReactDOM.render(
312
+ <h1>{__( 'Hello JSX', 'foo-plugin' )}</h1>,
313
+ document.getElementById('root')
314
+ );
315
+
316
+ wp.i18n.__( 'wp.i18n.__', 'foo-plugin' );
317
+ wp.i18n._n( 'wp.i18n._n_single', 'wp.i18n._n_plural', number, 'foo-plugin' );
318
+
319
+ const translate = wp.i18n;
320
+ translate.__( 'translate.__', 'foo-plugin' );
321
+
322
+ Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__["__"])( 'webpack.__', 'foo-plugin' );
323
+ Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__[/* __ */ "a"])( 'webpack.mangle.__', 'foo-plugin' );
324
+
325
+ Object(u.__)( 'minified.__', 'foo-plugin' );
326
+ Object(j._x)( 'minified._x', 'minified._x_context', 'foo-plugin' );
327
+
328
+ /* translators: babel */
329
+ (0, __)( 'babel.__', 'foo-plugin' );
330
+ (0, _i18n.__)( 'babel-i18n.__', 'foo-plugin' );
331
+ (0, _i18n._x)( 'babel-i18n._x', 'babel-i18n._x_context', 'foo-plugin' );
332
+
333
+ eval( "__( 'Hello Eval World', 'foo-plugin' );" );
334
+
335
+ __( \`This is a \${bug}\`, 'foo-plugin' );
336
+
337
+ /**
338
+ * Plugin Name: Plugin name
339
+ */
340
+
341
+ /* translators: Translators 1! */
342
+ _e( 'hello world', 'foo-plugin' );
343
+
344
+ /* Translators: Translators 2! */
345
+ $foo = __( 'foo', 'foo-plugin' );
346
+
347
+ /* translators: localized date and time format, see https://secure.php.net/date */
348
+ __( 'F j, Y g:i a', 'foo-plugin' );
349
+
350
+ // translators: let your ears fly!
351
+ __( 'on', 'foo-plugin' );
352
+
353
+ /*
354
+ * Translators: If there are characters in your language that are not supported
355
+ * by Lato, translate this to 'off'. Do not translate into your own language.
356
+ */
357
+ __( 'off', 'foo-plugin' );
358
+
359
+ /* translators: this should get extracted. */ $foo = __( 'baba', 'foo-plugin' );
360
+
361
+ /* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g( __( 'bubu', 'foo-plugin' ) );
362
+
363
+ {TAB}/*
364
+ {TAB} * translators: this comment block is indented with a tab and should get extracted too.
365
+ {TAB} */
366
+ {TAB}__( 'yolo', 'foo-plugin' );
367
+
368
+ /* translators: This is a comment */
369
+ __( 'Plugin name', 'foo-plugin' );
370
+
371
+ /* Translators: This is another comment! */
372
+ __( 'https://example.com', 'foo-plugin' );
373
+ `;
374
+
375
+ const filename = "filename.php";
376
+
377
+ const result = doTree(content, filename);
378
+
379
+ assert.strictEqual(result.blocks.length, 20);
380
+ });
381
+ });