@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.
- package/README.md +168 -4
- package/lib/assets/package-i18n.js +1 -1
- package/lib/cli/getArgs.js +1 -1
- package/lib/cli/getJsonArgs.js +1 -0
- package/lib/cli/parseCli.js +1 -1
- package/lib/cli.js +2 -0
- package/lib/const.js +1 -1
- 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 -0
- package/lib/makeJson.js +2 -1
- package/lib/makePot.js +2 -0
- package/lib/parser/exec.js +7 -3
- package/lib/parser/makeJson.js +1 -0
- 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 -0
- package/lib/types.js +1 -1
- package/lib/utils/common.js +3 -2
- package/package.json +19 -15
- 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 +3 -1
- package/lib/run.js +0 -1
package/README.md
CHANGED
|
@@ -2,15 +2,26 @@
|
|
|
2
2
|
[](https://github.com/wp-blocks/make-pot?tab=GPL-3.0-1-ov-file#readme)
|
|
3
3
|
[](https://github.com/wp-blocks/make-pot/actions/workflows/node.js.yml)
|
|
4
4
|
|
|
5
|
-
## Make
|
|
5
|
+
## Make POT
|
|
6
6
|
|
|
7
7
|
`make-pot` is a Node.js module designed to generate the `.pot` file for your WordPress plugin or theme. This file serves as the basis for internationalization, allowing translators to localize your plugin or theme into different languages.
|
|
8
8
|
|
|
9
9
|
Extract strings from your WordPress plugin or theme and generate a `.pot` file. Works with `js`, `jx`, `ts`, `tsx`, `cjs`, `mjs`, `php`, `blade`, `txt`, `json` with a custom schema for theme and block.json files.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Make JSON
|
|
12
|
+
`make-json` is a Node.js module designed to convert `.po` files into JSON format for your WordPress plugin or theme. This conversion facilitates client-side translations and enables your JavaScript code to use the translated strings.
|
|
13
|
+
|
|
14
|
+
Transform your translation files into a JSON format compatible with WordPress i18n package. This module simplifies the process of making your WordPress plugin or theme fully translatable on the frontend.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
You can install `make-pot` as a dependecy via npm:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npm install -d @wp-blocks/make-pot
|
|
22
|
+
```
|
|
12
23
|
|
|
13
|
-
|
|
24
|
+
or globally
|
|
14
25
|
|
|
15
26
|
```
|
|
16
27
|
npm install -g @wp-blocks/make-pot
|
|
@@ -19,7 +30,22 @@ npm install -g @wp-blocks/make-pot
|
|
|
19
30
|
### Usage
|
|
20
31
|
|
|
21
32
|
```bash
|
|
33
|
+
# without installation
|
|
22
34
|
npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]
|
|
35
|
+
npx @wp-blocks/make-pot --makejson [sourceDirectory] [destination] [options]
|
|
36
|
+
|
|
37
|
+
# installed
|
|
38
|
+
npx makepot [sourceDirectory] [destination] [options]
|
|
39
|
+
npx makejson [sourceDirectory] [destination] [options]
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Make Pot
|
|
43
|
+
|
|
44
|
+
Example usage:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# without installation
|
|
48
|
+
npx @wp-blocks/make-pot src languages --charset='utf-8' --include="src/**/*.{ts,tsx},inc/**/*,admin/**/*.{php}"
|
|
23
49
|
```
|
|
24
50
|
|
|
25
51
|
#### Positional Arguments:
|
|
@@ -27,7 +53,7 @@ npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]
|
|
|
27
53
|
- `sourceDirectory` (optional): Specifies the source directory of your plugin or theme. If not provided, the `.pot` file root will be the source directory.
|
|
28
54
|
- `destination` (optional): Specifies the destination directory where the `.pot` file will be generated. If not provided, the `.pot` file will be created in the source directory.
|
|
29
55
|
|
|
30
|
-
#### Options:
|
|
56
|
+
#### Make Pot Options:
|
|
31
57
|
|
|
32
58
|
- `--version`: Displays the version number of `make-pot`.
|
|
33
59
|
- `-h`, `--help`: Displays help information.
|
|
@@ -51,8 +77,48 @@ npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]
|
|
|
51
77
|
- `--exclude <files>`: Excludes specific files from processing.
|
|
52
78
|
- `--silent`: Suppresses output to stdout.
|
|
53
79
|
- `--json`: Outputs the JSON gettext data.
|
|
80
|
+
- `--charset`: Defines the encoding charset of the pot file, you can choose "iso-8859-1" and "uft-8" (defaults to iso-8859-1)
|
|
54
81
|
- `--output`: Outputs the gettext data.
|
|
55
82
|
|
|
83
|
+
### Example usage
|
|
84
|
+
|
|
85
|
+
First of all remember that the 'make-pot' help can be printed using the command `npx @wp-blocks/make-pot -h`, and the help for the json command can be printed using the command `npx make-json -h`. the commands are available after installing the module (`npm install @wp-blocks/make-pot`)
|
|
86
|
+
|
|
87
|
+
#### Using `make-pot` in your `package.json` (assiming you have already installed the makepot command)
|
|
88
|
+
```bash
|
|
89
|
+
"scripts": {
|
|
90
|
+
"build": "npm run build:scripts && npm run build:makepot",
|
|
91
|
+
"build:scripts": "wp-scripts build",
|
|
92
|
+
"build:makepot": "npx makepot",
|
|
93
|
+
"build-2:makejson": "npx makejson",
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
> Note: that it should be launched after creating the “.po” files with the localized translations (and then at a later time)
|
|
97
|
+
|
|
98
|
+
Both command does not need any arguments, they will parse the required data from the plugin file (the one in the root directory with the same name of the folder) or the theme.json/theme css file in the case of themes.
|
|
99
|
+
So what you should check before running the command is to have all the WordPress and Node.js required data/metadata in place, nothing else. Anyway, the command can be customized if you need, let's see some examples:
|
|
100
|
+
|
|
101
|
+
#### Using `make-pot` include and exclude files
|
|
102
|
+
We use glob module to include and exclude files. please check [glob](https://github.com/isaacs/node-glob)
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Every file in includes, frontend and admin directories that is not in node_modules
|
|
106
|
+
npx @wp-blocks/make-pot --include='includes/**/*,frontend/**/*,admin/**/*' --exclude="**/node_modules/**"
|
|
107
|
+
|
|
108
|
+
# Every file that is a tsx, ts, js and not in node_modules
|
|
109
|
+
npx @wp-blocks/make-pot --include='**/*.{tsx,ts,js}' --exclude="**/node_modules/**"
|
|
110
|
+
|
|
111
|
+
# Merge the resulting pot file with another pot file
|
|
112
|
+
npx @wp-blocks/make-pot --mergePaths='path/to/other.pot'
|
|
113
|
+
|
|
114
|
+
# Remove the strings from the resulting pot file with another pot file
|
|
115
|
+
npx @wp-blocks/make-pot --subtractPaths='path/to/other.pot'
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Tip:
|
|
119
|
+
The include and exclude options works in a different way... the include option adds the files to the default list of files to be processed, while the exclude option replaces the original list and excludes the specified files/directories.
|
|
120
|
+
The mergePaths option will merge the resulting pot file with another pot file, while the subtractPaths option will subtract the strings from the resulting pot file with another pot file.
|
|
121
|
+
|
|
56
122
|
## As a build chain step
|
|
57
123
|
|
|
58
124
|
The `make-pot` module can be used as a build step in your build chain.
|
|
@@ -63,6 +129,100 @@ To do so, create a `build:makepot` action in your `package.json` with the follow
|
|
|
63
129
|
"build:makepot": "npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]"
|
|
64
130
|
}
|
|
65
131
|
```
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
# Make JSON
|
|
135
|
+
|
|
136
|
+
### Why JSON Translation for WordPress JavaScript?
|
|
137
|
+
|
|
138
|
+
#### Overview
|
|
139
|
+
WordPress 5.0 introduced Gutenberg, a JavaScript-heavy editor. This shifted much of the internationalization (I18N) work from the server to the client side. While functions like `wp_localize_script()` were used before, Gutenberg required a more robust solution.
|
|
140
|
+
|
|
141
|
+
#### JavaScript Localization Functions
|
|
142
|
+
WordPress 5.0 introduced the `wp-i18n` JavaScript package, offering localization functions (`__()`, `_x()`, `_n()`, `_nx()`, `sprintf()`) similar to their PHP counterparts, enabling seamless I18N in JavaScript.
|
|
143
|
+
|
|
144
|
+
#### Loading Translations
|
|
145
|
+
To fully internationalize a plugin or theme, you must load translations using `wp_set_script_translations()`, which requires:
|
|
146
|
+
1. Script handle (e.g., `my-plugin-script`)
|
|
147
|
+
2. Text domain (e.g., `my-plugin`)
|
|
148
|
+
3. Optional: Path to translation files (if not hosted on WordPress.org)
|
|
149
|
+
|
|
150
|
+
#### JSON Translation Files
|
|
151
|
+
Unlike traditional PO/MO files, JavaScript translations use JSON. This format is easily readable in JavaScript and compatible with the Jed JavaScript gettext library, used by the `wp-i18n` package. WordPress.org generates these JSON files automatically, but custom ones can be created if needed.
|
|
152
|
+
|
|
153
|
+
## JSON Utility args
|
|
154
|
+
|
|
155
|
+
- `source`: (positional) the source directory of your plugin or theme translations (e.g. `languages`).
|
|
156
|
+
- `destination`: (positional and optional) The destination directory where the `.json` file will be generated. If not provided, the `.json` file will be created in the source directory.
|
|
157
|
+
- `--scriptName`: The name of the script that needs this translation file.
|
|
158
|
+
- `--allowedFormats`: The allowed formats of the translation file (e.g. `js` or `tsx`).
|
|
159
|
+
- `--purge`: if enabled, removes the existing translation file. Otherwise, the old translation file will be merged with the new.
|
|
160
|
+
- `--prettyPrint`: Pretty prints the translation file.
|
|
161
|
+
- `--debug`: Enables debug mode.
|
|
162
|
+
|
|
163
|
+
## How to Generate Json translations
|
|
164
|
+
|
|
165
|
+
#### Build the json translations file
|
|
166
|
+
|
|
167
|
+
First, build the translation pot file using `makepot` (no matter with this module or not) and then translate it into the different languages.
|
|
168
|
+
|
|
169
|
+
translate the pot file into your language and then run `makejson`:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
npx makejson
|
|
173
|
+
# OR
|
|
174
|
+
npx @wp-blocks/make-pot --makejson,
|
|
175
|
+
```
|
|
176
|
+
It Will create a file for each po file in the `languages` directory with the md5 hash with the name of the file.
|
|
177
|
+
In this case, the file will be named my-frontend-script-en_US-79431f0eb8deb8221f24df5112e15095.json because the md5 hash of "build/frontend.js" is 79431f0eb8deb8221f24df5112e15095.
|
|
178
|
+
This is crucial because the md5 hash has to be the same as the path of the script file.
|
|
179
|
+
|
|
180
|
+
## Register the javascript block translations
|
|
181
|
+
|
|
182
|
+
```php
|
|
183
|
+
<?php
|
|
184
|
+
/**
|
|
185
|
+
* Loads the plugin text domain for translation.
|
|
186
|
+
*/
|
|
187
|
+
function my_i18n() {
|
|
188
|
+
load_plugin_textdomain( 'my-text-domain', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
|
189
|
+
}
|
|
190
|
+
add_action( 'init', 'my_i18n' );
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Registers the block using the metadata loaded from the `block.json` file.
|
|
194
|
+
*/
|
|
195
|
+
add_action('init', function () {
|
|
196
|
+
register_block_type( dirname( plugin_basename( __FILE__ ) ) . '/build', [
|
|
197
|
+
"script" => "my-vendor-script",
|
|
198
|
+
"viewScript" => "my-frontend-script",
|
|
199
|
+
"editorScript" => "my-editor-script",
|
|
200
|
+
]);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Registers the block using the metadata loaded from the `block.json` file.
|
|
205
|
+
*/
|
|
206
|
+
function my_register_block_type() {
|
|
207
|
+
|
|
208
|
+
$fe_assets = include dirname( __FILE__ ) . '/build/my-frontend-script.asset.php';
|
|
209
|
+
|
|
210
|
+
wp_register_script(
|
|
211
|
+
'my-frontend-script',
|
|
212
|
+
VSGE_MB_PLUGIN_URL . 'build/frontend.js',
|
|
213
|
+
$fe_assets['dependencies'],
|
|
214
|
+
$fe_assets['version']
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
// 1 - the name of the hook used to register the script
|
|
218
|
+
// 2 - the text domaim of the block
|
|
219
|
+
// 3 - the path to the translations directory
|
|
220
|
+
wp_set_script_translations( 'my-frontend-script', 'my-text-domain', plugin_dir_url(__FILE__) . '/languages' );
|
|
221
|
+
|
|
222
|
+
...
|
|
223
|
+
}
|
|
224
|
+
add_action( 'init', 'my_register_block_type' );
|
|
225
|
+
```
|
|
66
226
|
|
|
67
227
|
### Credits
|
|
68
228
|
|
|
@@ -70,6 +230,10 @@ This module is heavily inspired by the original `makepot` command from [WP-CLI](
|
|
|
70
230
|
Special thanks to the maintainers in particular [Swissspidy](https://github.com/swissspidy) which
|
|
71
231
|
has been very helpful with suggestions and tips on how to rebuild `make-pot`.
|
|
72
232
|
|
|
233
|
+
#### Useful links
|
|
234
|
+
- https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/
|
|
235
|
+
- https://pascalbirchler.com/internationalization-in-wordpress-5-0/
|
|
236
|
+
|
|
73
237
|
Feel free to contribute or report issues on [GitHub](https://github.com/example/example).
|
|
74
238
|
|
|
75
239
|
This tool is licensed under the [GNU General Public License v3](LICENSE).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var t=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var n=(s,r)=>{for(var e in r)o(s,e,{get:r[e],enumerable:!0})},b=(s,r,e,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let u of t(r))!l.call(s,u)&&u!==e&&o(s,u,{get:()=>r[u],enumerable:!(i=a(r,u))||i.enumerable});return s};var g=s=>b(o({},"__esModule",{value:!0}),s);var m={};n(m,{default:()=>h});module.exports=g(m);var h={name:"name",url:"url",description:"description",author:"author",authors:"authors",authorEmail:"authorEmail",version:"version",bugs:"bugs","bugs.url":"bugsUrl","bugs.email":"bugsEmail",license:"license",repository:"repository"};
|
package/lib/cli/getArgs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var l=Object.create;var o=Object.defineProperty;var
|
|
1
|
+
"use strict";var l=Object.create;var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var i in t)o(e,i,{get:t[i],enumerable:!0})},n=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of b(t))!y.call(e,s)&&s!==i&&o(e,s,{get:()=>t[s],enumerable:!(r=g(t,s))||r.enumerable});return e};var a=(e,t,i)=>(i=e!=null?l(u(e)):{},n(t||!e||!e.__esModule?o(i,"default",{value:e,enumerable:!0}):i,e)),m=e=>n(o({},"__esModule",{value:!0}),e);var S={};f(S,{getArgs:()=>h});module.exports=m(S);var p=a(require("node:process")),k=a(require("yargs")),c=require("yargs/helpers"),d=require("./parseCli.js");function h(e={}){const t=k.default((0,c.hideBin)(p.default.argv)).help("h").alias("help","help").usage("Usage: $0 <source> [destination] [options]").positional("sourceDirectory",{describe:"Source directory",type:"string"}).positional("destination",{describe:"Destination directory",type:"string"}).options({slug:{describe:"Plugin or theme slug",type:"string"},domain:{describe:"Text domain to look for in the source code",type:"string"},"skip-js":{describe:"Skip JavaScript files",type:"boolean"},"skip-php":{describe:"Skip PHP files",type:"boolean"},"skip-blade":{describe:"Skip Blade files",type:"boolean"},"skip-block-json":{describe:"Skip block.json files",type:"boolean"},"skip-theme-json":{describe:"Skip theme.json files",type:"boolean"},"skip-audit":{describe:"Skip auditing of strings",type:"boolean"},headers:{describe:"Headers",type:"string"},"file-comment":{describe:"File comment",type:"string"},"package-name":{describe:"Package name",type:"string"},location:{describe:"Include location information",type:"boolean"},"ignore-domain":{describe:"Ignore text domain",type:"boolean"},mergePaths:{describe:"Merge with existing POT file(s)",type:"string"},subtractPaths:{describe:"Subtract strings from existing POT file(s)",type:"string"},subtractAndMerge:{describe:"Subtract and merge strings from existing POT file(s)",type:"boolean"},include:{describe:"Include specific files",type:"string",default:"**"},exclude:{describe:"Exclude specific files",type:"string"},silent:{describe:"No output to stdout",type:"boolean",default:!1},json:{describe:"Output the json gettext data",type:"boolean"},output:{describe:"Output the gettext data",type:"boolean"},charset:{describe:"Charset",type:"string",default:"latin1"}}).parseSync();return(0,d.parseCliArgs)({...e,...t})}0&&(module.exports={getArgs});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.create;var s=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var m=(e,t)=>{for(var r in t)s(e,r,{get:t[r],enumerable:!0})},a=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of g(t))!y.call(e,o)&&o!==r&&s(e,o,{get:()=>t[o],enumerable:!(i=f(t,o))||i.enumerable});return e};var n=(e,t,r)=>(r=e!=null?c(u(e)):{},a(t||!e||!e.__esModule?s(r,"default",{value:e,enumerable:!0}):r,e)),b=e=>a(s({},"__esModule",{value:!0}),e);var A={};m(A,{getJsonArgs:()=>J});module.exports=b(A);var p=n(require("node:process")),h=n(require("yargs")),d=require("yargs/helpers"),l=require("./parseCli");function J(e={}){const t=h.default((0,d.hideBin)(p.default.argv)).help("h").alias("help","help").usage("Usage: $0 <source> [destination] [options]").positional("source",{describe:"Source directory",type:"string"}).positional("destination",{describe:"Destination directory",type:"string"}).options({scriptName:{describe:"The name of the script to be translated",type:"string"},allowedFormats:{describe:"which extensions to use for translation",type:"array",default:["js"]},purge:{describe:"Remove old JSON files",type:"boolean",default:!0},prettyPrint:{describe:"Pretty print JSON",type:"boolean",default:!1},debug:{describe:"Debug mode",type:"boolean",default:!1}}).parseSync();return(0,l.parseJsonArgs)({...e,...t})}0&&(module.exports={getJsonArgs});
|
package/lib/cli/parseCli.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var b=Object.create;var u=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var J=(t,n)=>{for(var e in n)u(t,e,{get:n[e],enumerable:!0})},g=(t,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of P(n))!w.call(t,s)&&s!==e&&u(t,s,{get:()=>n[s],enumerable:!(o=A(n,s))||o.enumerable});return t};var l=(t,n,e)=>(e=t!=null?b(D(t)):{},g(n||!t||!t.__esModule?u(e,"default",{value:t,enumerable:!0}):e,t)),T=t=>g(u({},"__esModule",{value:!0}),t);var S={};J(S,{parseCliArgs:()=>j,parseJsonArgs:()=>O});module.exports=T(S);var c=l(require("node:fs")),i=l(require("node:path")),h=l(require("node:process")),f=require("../const.js"),y=require("../fs/fs"),a=require("../utils/common.js");function _(t="/",n="default"){const e=t;try{return(0,c.accessSync)(i.join(e,`${n}.php`),c.default.constants.R_OK),"plugin"}catch{console.log(`the current working directory ${e} does not contain a ${n}.php file`)}try{return(0,c.accessSync)(i.join(e,"style.css"),c.default.constants.R_OK),"theme"}catch{console.log(`the current working directory ${e} does not contain a style.css file`)}return"generic"}function j(t){const n=t._[0]?.toString(),e=t._[1]?.toString()||"languages",o=n??".",s=e.startsWith("/")?e.slice(1):e,r=h.cwd(),p=t.slug&&typeof t.slug=="string"?t.slug:i.basename(i.resolve(r,o)),m=i.relative(r,o),k=i.relative(r,s);if(!t?.domain)t.domain=_(i.resolve(m),p);else switch(t.domain){case"plugin":case"theme":case"block":case"theme-block":break;default:console.error(`Invalid domain: ${t.domain}. Valid domains are: plugin, theme, block, theme-block, generic`),t.domain="generic"}const d={slug:p,domain:t.domain,paths:{cwd:m,out:k},options:{ignoreDomain:!!t?.ignoreDomain,packageName:String(t.packageName),silent:t.silent===!0,json:!!t.json,location:!!t?.location,output:!!t?.output,fileComment:t.fileComment?String(t.fileComment):void 0,charset:(0,y.getEncodingCharset)(t?.charset),skip:{js:!!t.skipJs,php:!!t.skipPhp,blade:!!t.skipBlade,blockJson:!!t.skipBlockJson,themeJson:!!t.skipThemeJson,audit:!!t.skipAudit}},patterns:{mergePaths:(0,a.stringstring)(t.mergePaths),subtractPaths:(0,a.stringstring)(t.subtractPaths),subtractAndMerge:!!t.subtractAndMerge,include:(0,a.stringstring)(t.include),exclude:[...(0,a.stringstring)(t.exclude),...f.DEFAULT_EXCLUDED_PATH]}};return d.paths.root=t.root?String(t.root):void 0,d}function O(t){const n=t._[0]||"build",e=t._[1]||"languages",o=h.cwd(),s=i.basename(i.resolve(o));let r;return t.scriptName&&(r=t.scriptName.split(",").map(p=>p.trim()),r.length===1&&(r=r[0])),{timeStart:Date.now(),slug:s,source:n,destination:e,scriptName:r,allowedFormats:t.allowedFormats,purge:!!t.purge,prettyPrint:!!t.prettyPrint,debug:!!t.debug,paths:{cwd:o,out:i.join(o,e)}}}0&&(module.exports={parseCliArgs,parseJsonArgs});
|
package/lib/cli.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";var d=Object.create;var n=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var b=(o,r,e,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of A(r))!J.call(o,s)&&s!==e&&n(o,s,{get:()=>r[s],enumerable:!(a=l(r,s))||a.enumerable});return o};var m=(o,r,e)=>(e=o!=null?d(y(o)):{},b(r||!o||!o.__esModule?n(e,"default",{value:o,enumerable:!0}):e,o));var t=m(require("node:process")),c=m(require("yargs")),i=require("yargs/helpers"),p=require("./cli/getArgs.js"),f=require("./cli/getJsonArgs"),g=m(require("./jsonCommand")),k=m(require("./potCommand"));const j=c.default((0,i.hideBin)(t.default.argv)).options({makejson:{describe:"Make JSON file",type:"boolean",default:!1}}).parseSync();j.makejson?(0,g.default)((0,f.getJsonArgs)()):(0,k.default)((0,p.getArgs)());
|
package/lib/const.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var c=Object.create;var _=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,
|
|
1
|
+
"use strict";var c=Object.create;var _=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var b=(t,e)=>{for(var m in e)_(t,m,{get:e[m],enumerable:!0})},n=(t,e,m,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of l(e))!f.call(t,s)&&s!==m&&_(t,s,{get:()=>e[s],enumerable:!(i=p(e,s))||i.enumerable});return t};var o=(t,e,m)=>(m=t!=null?c(u(t)):{},n(e||!t||!t.__esModule?_(m,"default",{value:t,enumerable:!0}):m,t)),h=t=>n(_({},"__esModule",{value:!0}),t);var U={};b(U,{DEFAULT_EXCLUDED_PATH:()=>D,IsoCodeRegex:()=>E,allowedFormats:()=>L,blockJson:()=>k,defaultLocale:()=>J,fileRegex:()=>F,i18nFunctions:()=>T,pkgJsonHeaders:()=>w,pluginHeaders:()=>H,themeHeaders:()=>A,themeJson:()=>j});module.exports=h(U);var d=o(require("./assets/block-i18n.js")),x=o(require("./assets/package-i18n.js")),g=o(require("./assets/theme-i18n.js")),a=o(require("./assets/wp-plugin-i18n.js")),r=o(require("./assets/wp-theme-i18n.js"));const j=g.default,k=d.default,w=x.default,H=a.default,A=r.default,D=[".git","node_modules","vendor","build","dist","uploads","Gruntfile.js","webpack.config.js","**/*.min.js","tsconfig.js","**.test.**","tests"],E=/-([a-z]{2}_[A-Z]{2})\.po$/,F=/#:\s*(.*?)(?::\d+)?$/,J="en_US",L=["php","js","jsx","ts","tsx","mjs","cjs"],T={__:["msgid","text_domain"],esc_attr__:["msgid","text_domain"],esc_html__:["msgid","text_domain"],esc_xml__:["msgid","text_domain"],_e:["msgid","text_domain"],esc_attr_e:["msgid","text_domain"],esc_html_e:["msgid","text_domain"],esc_xml_e:["msgid","text_domain"],_x:["msgid","msgctxt","text_domain"],_ex:["msgid","msgctxt","text_domain"],esc_attr_x:["msgid","msgctxt","text_domain"],esc_html_x:["msgid","msgctxt","text_domain"],esc_xml_x:["msgid","msgctxt","text_domain"],_n:["msgid","msgid_plural","number","text_domain"],_nx:["msgid","msgid_plural","number","msgctxt","text_domain"],_n_noop:["msgid","msgid_plural","text_domain"],_nx_noop:["msgid","msgid_plural","msgctxt","text_domain"],_:["msgid","text_domain"],_c:["msgid","text_domain"],_nc:["msgid","msgid_plural","number","text_domain"],__ngettext:["msgid","msgid_plural","number","text_domain"],__ngettext_noop:["msgid","msgid_plural","text_domain"]};0&&(module.exports={DEFAULT_EXCLUDED_PATH,IsoCodeRegex,allowedFormats,blockJson,defaultLocale,fileRegex,i18nFunctions,pkgJsonHeaders,pluginHeaders,themeHeaders,themeJson});
|
package/lib/extractors/css.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.create;var i=Object.defineProperty;var
|
|
1
|
+
"use strict";var u=Object.create;var i=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var k=(e,t)=>{for(var o in t)i(e,o,{get:t[o],enumerable:!0})},l=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of C(t))!j.call(e,r)&&r!==o&&i(e,r,{get:()=>t[r],enumerable:!(n=x(t,r))||n.enumerable});return e};var a=(e,t,o)=>(o=e!=null?u(T(e)):{},l(t||!e||!e.__esModule?i(o,"default",{value:e,enumerable:!0}):o,e)),B=e=>l(i({},"__esModule",{value:!0}),e);var F={};k(F,{extractCssThemeData:()=>D});module.exports=B(F);var m=a(require("node:fs")),h=a(require("node:path")),d=require("../const.js"),p=require("../utils/common.js"),y=require("./text.js"),g=require("./utils.js");function D(e){let t={};const o=h.default.join(e.paths.cwd,"style.css");if(m.default.existsSync(o)){const n=m.default.readFileSync(o,"utf8"),r=(0,p.getCommentBlock)(n);if(t=(0,y.extractFileData)(r),"Theme Name"in t){console.log(`\u{1F535} Theme stylesheet detected. ${o}`),e.domain="theme";const c={};for(const s of Object.entries(t))if(s?.[0]&&s[1]){const f=(0,g.getKeyByValue)(d.themeHeaders,s[0].trim());if(f===void 0)continue;c[f]=s[1].trim()}return c}}else console.log(`Theme stylesheet not found in ${o}`);return{}}0&&(module.exports={extractCssThemeData});
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},P=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of b(t))!y.call(e,r)&&r!==o&&m(e,r,{get:()=>t[r],enumerable:!(n=T(t,r))||n.enumerable});return e};var H=e=>P(m({},"__esModule",{value:!0}),e);var R={};I(R,{extractMainFileData:()=>x,generateHeader:()=>U,translationsHeaders:()=>E});module.exports=H(R);var d=require("gettext-merger"),f=require("../fs/fs"),u=require("../utils/common"),g=require("./css.js"),p=require("./php.js"),l=require("./utils.js");function M(e){const o=[{key:"slug",name:"Plugin/Theme slug",placeholder:"PLUGIN NAME"},{key:"author",name:"Author name",placeholder:"AUTHOR"},{key:"version",name:"Version",placeholder:""},{key:"email",name:"Author email",placeholder:"AUTHOR EMAIL"},{key:"domain",name:"Text domain",placeholder:"PLUGIN TEXTDOMAIN"}].filter(n=>!e[n.key]||e[n.key]===n.placeholder||n.key==="version"&&e[n.key]==="0.0.1");if(o.length>0){console.error(`
|
|
2
|
+
! Missing required information for POT file header:
|
|
3
|
+
`);for(const n of o)console.error(` - ${n.name} is missing or has a default value (eg. version: 0.0.1, author: AUTHOR EMAIL)`);return console.error(`
|
|
4
|
+
Please provide this information adding the missing fields inside the headers object of the plugin/theme declaration or to the package.json file.`,`
|
|
5
|
+
For more information check the documentation at https://github.com/wp-blocks/makePot`),console.error(`
|
|
6
|
+
`),!1}return!0}function h(e){const t={name:"AUTHOR",email:"AUTHOR EMAIL"};if(!e)return t;if(typeof e=="string"){const o=e.match(/<([^>]+)>/),n=o?o[1].trim():void 0,r=e.match(/\(([^)]+)\)/),a=r?r[1].trim():void 0;let i=e.trim();return o&&(i=i.replace(o[0],"").trim()),r&&(i=i.replace(r[0],"").trim()),{name:i,email:n,website:a}}if(typeof e=="object")return{name:e.name,email:e.email,website:e.website}}function O(e){const t=["author","authors","contributors","maintainers"];for(const o of t)if(e[o]){let n;if(typeof e[o]=="string")n=h(e[o]);else if(typeof e[o]=="object"){for(const r of e[o])if(r&&(n=h(r),n))break}if(n?.name!=="AUTHOR"||n?.email!=="AUTHOR EMAIL")return n}return{name:"AUTHOR",email:"AUTHOR EMAIL"}}function $(e){const{author:t,textDomain:o}=e.headers,n=(0,u.getPkgJsonData)("name","version","author","authors","contributors","maintainers"),r=`https://wordpress.org/support/${e.domain==="theme"?"themes":"plugins"}/${e.slug}`,a=O(n),i=e.headers?.author||a?.name,c=a?.email,s=`${t} <${c}>`,A=process.cwd().split("/").pop()?.toLowerCase().replace(" ","-"),k=e.slug||A||(e.domain==="theme"?"THEME NAME":"PLUGIN NAME");return{...e.headers,author:i,authorString:s,slug:k,email:c,bugs:r,license:e.headers?.license||"gpl-2.0 or later",version:e.headers?.version||n.version||"0.0.1",language:"en",domain:e.headers?.textDomain||e.headers?.slug||"PLUGIN TEXTDOMAIN",xDomain:o}}async function U(e){const t=$(e),{name:o,version:n}=(0,u.getPkgJsonData)("name","version");if(!M(t))return process.exit(1),null;const r={"Project-Id-Version":`${t.slug} ${t.version}`,"Report-Msgid-Bugs-To":t.authorString,"MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","content-type":`text/plain; charset=${(0,f.getEncodingCharset)(e.options?.charset)}`,"plural-forms":"nplurals=2; plural=(n!=1);","POT-Creation-Date":`${new Date().toISOString()}`,"PO-Revision-Date":`${new Date().getFullYear()}-MO-DA HO:MI+ZONE`,"Last-Translator":t.authorString,"Language-Team":t.authorString,"X-Generator":`${o} ${n}`,Language:`${t.language}`};return t.xDomain&&(r["X-Domain"]=t.xDomain),r}function x(e){let t={};return["plugin","block","generic"].includes(e.domain)?t=(0,p.extractPhpPluginData)(e):["theme","theme-block"].includes(e.domain)?t=(0,g.extractCssThemeData)(e):console.log("No main file detected."),t}function E(e){const{domain:t,headers:o}=e,{name:n,description:r,author:a,authorUri:i,url:c}=o,s=t==="plugin"?`${e.slug}.php`:"style.css";return new d.SetOfBlocks([(0,l.gentranslation)(`Name of the ${t}`,n,s),(0,l.gentranslation)(`Url of the ${t}`,c,s),(0,l.gentranslation)(`Description of the ${t}`,r,s),(0,l.gentranslation)(`Author of the ${t}`,a,s),(0,l.gentranslation)(`Author URI of the ${t}`,i,s)])}0&&(module.exports={extractMainFileData,generateHeader,translationsHeaders});
|
package/lib/extractors/json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var k=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var b=(e,n)=>{for(var t in n)c(e,t,{get:n[t],enumerable:!0})},l=(e,n,t,
|
|
1
|
+
"use strict";var k=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var b=(e,n)=>{for(var t in n)c(e,t,{get:n[t],enumerable:!0})},l=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of j(n))!d.call(e,s)&&s!==t&&c(e,s,{get:()=>n[s],enumerable:!(o=u(n,s))||o.enumerable});return e};var g=(e,n,t)=>(t=e!=null?k(J(e)):{},l(n||!e||!e.__esModule?c(t,"default",{value:e,enumerable:!0}):t,e)),S=e=>l(c({},"__esModule",{value:!0}),e);var C={};b(C,{extractPackageJson:()=>F,getJsonComment:()=>x,parseJsonCallback:()=>w,parseJsonFile:()=>h});module.exports=S(C);var m=g(require("node:fs")),f=g(require("node:path")),a=require("../const.js"),r=require("./schema.js"),p=require("./utils.js");async function h(e){return await r.JsonSchemaExtractor.fromString(e.fileContent,{file:e.filename,schema:e.filename==="theme.json"?r.JsonSchemaExtractor.themeJsonSource:r.JsonSchemaExtractor.blockJsonSource,schemaFallback:e.filename==="theme.json"?r.JsonSchemaExtractor.themeJsonFallback:r.JsonSchemaExtractor.blockJsonFallback,addReferences:!0})??{}}function y(e){switch(e){case"block.json":return a.blockJson;case"theme.json":return a.themeJson;default:return{}}}function x(e,n){const t=y(n);return e in Object.values(t)?t[e]:e}function F(e){const n=a.pkgJsonHeaders,t={},o=e.paths.cwd?f.default.join(e.paths.cwd,"package.json"):"package.json";if(m.default.existsSync(o)){const s=JSON.parse(m.default.readFileSync(o,"utf8"));for(const i of Object.keys(n))i in s&&(t[i]=s[i])}return t}async function w(e,n,t){const o=await h({fileContent:e,filename:t,filepath:n});return(0,p.yieldParsedData)(o,t,f.default.join(n,t))}0&&(module.exports={extractPackageJson,getJsonComment,parseJsonCallback,parseJsonFile});
|
package/lib/extractors/php.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var h=Object.create;var s=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var k=(n
|
|
2
|
-
`),o={};for(const d of i){const r=d.match(/^\s*\*\s*([^:]+):\s*(.*)/);if(r
|
|
1
|
+
"use strict";var h=Object.create;var s=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var k=(t,n)=>{for(var e in n)s(t,e,{get:n[e],enumerable:!0})},f=(t,n,e,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of y(n))!R.call(t,o)&&o!==e&&s(t,o,{get:()=>n[o],enumerable:!(i=P(n,o))||i.enumerable});return t};var g=(t,n,e)=>(e=t!=null?h(x(t)):{},f(n||!t||!t.__esModule?s(e,"default",{value:t,enumerable:!0}):e,t)),B=t=>f(s({},"__esModule",{value:!0}),t);var S={};k(S,{extractPhpPluginData:()=>F,parsePHPFile:()=>a});module.exports=B(S);var c=g(require("node:fs")),m=g(require("node:path")),p=require("../const.js"),u=require("./utils.js");function F(t){let n={};const e=m.default.join(t.paths.cwd,`${t.slug}.php`);if(c.default.existsSync(e)){const i=c.default.readFileSync(e,"utf8");return n=a(i),console.log(`\u{1F535} Plugin file detected. (${e})`),t.domain="plugin",n}return console.log("Plugin file not found."),console.log(`Missing Plugin filename: ${e}`),{}}function a(t){const n=t.match(/\/\*\*([\s\S]*?)\*\//);if(n?.[1]){const i=n[1].split(`
|
|
2
|
+
`),o={};for(const d of i){const r=d.match(/^\s*\*\s*([^:]+):\s*(.*)/);if(r?.[1]&&r[2]){const l=(0,u.getKeyByValue)(p.pluginHeaders,r[1].trim());if(l===void 0)continue;o[l]=r[2].trim()}}return o}return{}}0&&(module.exports={extractPhpPluginData,parsePHPFile});
|
package/lib/extractors/schema.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var p=Object.create;var i=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},h=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of f(e))!u.call(t,s)&&s!==r&&i(t,s,{get:()=>e[s],enumerable:!(a=d(e,s))||a.enumerable});return t};var m=(t,e,r)=>(r=t!=null?p(g(t)):{},h(e||!t||!t.__esModule?i(r,"default",{value:t,enumerable:!0}):r,t)),b=t=>h(i({},"__esModule",{value:!0}),t);var j={};y(j,{JsonSchemaExtractor:()=>c});module.exports=b(j);var I=m(require("../assets/block-i18n.js")),S=m(require("../assets/theme-i18n.js"));class c{static schemaCache={};static themeJsonSource="http://develop.svn.wordpress.org/trunk/src/wp-includes/theme-i18n.json";static themeJsonFallback=S;static blockJsonSource="http://develop.svn.wordpress.org/trunk/src/wp-includes/block-i18n.json";static blockJsonFallback=I;static async loadSchema(e,r){if(c.schemaCache[e])return c.schemaCache[e];try{console.log(`
|
|
2
|
+
[i] Loading schema from ${e}`);const a=await fetch(e,{responseType:"json",accept:"application/json",headers:{"Content-Type":"application/json","Access-Control-Allow-Origin":"*"}}).then(s=>s.json()).catch(s=>{throw new Error(`
|
|
3
|
+
Failed to load schema from ${e}. Error: ${s.message}`)});return!a||!a?.data?r:(console.log("Schema loaded successfully"),c.schemaCache[e]=a.data,a.data)}catch(a){return console.error(`
|
|
4
|
+
Failed to load schema from ${e}. Using fallback. Error: ${a.message}`),c.schemaCache[e]=r,r}}static async fromString(e,r){const a=r.schema,s=r.schemaFallback;if(!a||!s){console.error("Schema URL or fallback not provided");return}const n=await c.loadSchema(a,s);try{const o=JSON.parse(e);if(o===null){console.error("Could not parse JSON.");return}return c.extractStringsUsingI18nSchema(n,o)}catch(o){console.error(`Error parsing JSON: ${o.message}`);return}}static extractStringsUsingI18nSchema(e,r){if(!e||!r)return{};if(Array.isArray(e)&&typeof r=="object"){const a={};for(const s in r){const n=c.extractStringsUsingI18nSchema(e[s],s);Object.assign(a,n)}return a}if(typeof e=="object"&&typeof r=="object"){const a="*",s={};for(const[n,o]of Object.entries(r))if(e[n])s[n]=e[n];else if(Object.prototype.hasOwnProperty.call(e,a)){const l=c.extractStringsUsingI18nSchema(e[a],o);l&&Object.assign(s,l)}return s}return{}}}0&&(module.exports={JsonSchemaExtractor});
|
package/lib/extractors/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var p=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},B=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of y(e))!x.call(t,o)&&o!==r&&l(t,o,{get:()=>e[o],enumerable:!(n=k(e,o))||n.enumerable});return t};var O=t=>B(l({},"__esModule",{value:!0}),t);var v={};p(v,{gentranslation:()=>m,getKeyByValue:()=>b,yieldParsedData:()=>j});module.exports=O(v);var g=require("gettext-merger"),d=require("./json.js");function b(t,e){return Object.keys(t).find(r=>t[r]===e)??void 0}const m=(t,e,r)=>{const n=new g.Block([]);return n.msgctxt=void 0,n.msgid=e,n.msgid_plural="",n.msgstr=[],n.comments={extracted:[t],reference:[r]},n};function j(t,e,r){const n=new g.SetOfBlocks([],r);if(!t)return n;n.path=r;for(const[u,s]of Object.entries(t)){let i=function(c,f=u){const a=m((0,d.getJsonComment)(u,e),f,r);n.add(a)};var o=i;if(s)if(typeof s=="string")i(s);else if(Array.isArray(s))for(const c of s)i(c);else for(const[c,f]of Object.entries(s))typeof f=="string"&&i(f,c)}return n}0&&(module.exports={gentranslation,getKeyByValue,yieldParsedData});
|
package/lib/fs/fs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var p=Object.create;var c=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var w=(t,e)=>{for(var n in e)c(t,n,{get:e[n],enumerable:!0})},u=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of m(e))!x.call(t,r)&&r!==n&&c(t,r,{get:()=>e[r],enumerable:!(o=l(e,r))||o.enumerable});return t};var a=(t,e,n)=>(n=t!=null?p(F(t)):{},u(e||!t||!t.__esModule?c(n,"default",{value:t,enumerable:!0}):n,t)),y=t=>u(c({},"__esModule",{value:!0}),t);var j={};w(j,{getCharset:()=>d,getEncodingCharset:()=>h,getOutputPath:()=>$,readFileAsync:()=>S,writeFile:()=>O});module.exports=y(j);var s=a(require("node:fs")),f=require("node:fs/promises"),i=a(require("node:path"));function E(t){if(t===void 0)return".";try{s.default.accessSync(i.default.resolve(t),s.default.constants.R_OK|s.default.constants.W_OK)}catch(e){if(e.code==="ENOENT")return s.default.mkdirSync(t,{recursive:!0}),console.log(`Folder created: ${t}`),t}return t}function d(t){if(!t)return"latin1";switch(t.toLowerCase()){case"utf-8":case"utf8":return"utf-8";default:return"latin1"}}function h(t){if(!t)return"iso-8859-1";switch(t.toLowerCase()){case"utf-8":case"utf8":return"utf-8";default:return"iso-8859-1"}}function $(t){return i.default.join(process.cwd(),t??"languages")}function C(t){const{out:e,headers:n,options:o}=t.paths;let r=e??n?.domainPath??"languages";r=r.replace(/^\/+|\/+$/g,"");const g=o?.json?"json":"pot";return i.default.join(process.cwd(),r,`${t.slug}.${g}`)}function O(t,e){const n=C(e);if(E(i.default.dirname(n))){const o=d(e.options?.charset);console.log(`File created at ${n}`);const r=Buffer.from(t);(0,s.writeFileSync)(n,r.toString(o),{encoding:o})}else console.log(`Folder ${n} does not exist and cannot be created`)}async function S(t){return(0,f.readFile)(t,"utf-8")}0&&(module.exports={getCharset,getEncodingCharset,getOutputPath,readFileAsync,writeFile});
|
package/lib/fs/glob.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
for `+e.include.join(),`
|
|
3
|
-
ignoring patterns: `+e.exclude.join()),new u.Glob(e.include,{ignore:{ignored:r=>d(r,e.exclude)},nodir:!0,cwd:t.paths.cwd,root:t.paths.root?a.default.resolve(t.paths.root):void 0})}0&&(module.exports={getFiles,getParser,ignoreFunc});
|
|
1
|
+
"use strict";var d=Object.create;var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var x=(t,r)=>{for(var e in r)o(t,e,{get:r[e],enumerable:!0})},i=(t,r,e,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of h(r))!w.call(t,s)&&s!==e&&o(t,s,{get:()=>r[s],enumerable:!(a=g(r,s))||a.enumerable});return t};var n=(t,r,e)=>(e=t!=null?d(y(t)):{},i(r||!t||!t.__esModule?o(e,"default",{value:t,enumerable:!0}):e,t)),j=t=>i(o({},"__esModule",{value:!0}),t);var F={};x(F,{getFiles:()=>A,getParser:()=>b,ignoreFunc:()=>f});module.exports=j(F);var c=n(require("node:path")),u=require("glob"),m=require("minimatch"),P=n(require("tree-sitter-javascript")),v=n(require("tree-sitter-php")),p=n(require("tree-sitter-typescript")),l=require("../utils/common.js");function b(t){switch(t.split(".").pop()){case"ts":return p.typescript;case"tsx":return p.tsx;case"js":case"jsx":case"mjs":case"cjs":return P.default;case"php":return v.default;default:return null}}const f=(t,r)=>r.some(e=>{switch((0,l.detectPatternType)(e)){case"file":return t.isNamed(e);case"directory":return t.relative().includes(e);default:return(0,m.minimatch)(t.relative(),e)}});function A(t,r){return new u.Glob(r.include,{ignore:{ignored:e=>f(e,r.exclude)},nodir:!0,cwd:t.paths.cwd,root:t.paths.root?c.default.resolve(t.paths.root):void 0})}0&&(module.exports={getFiles,getParser,ignoreFunc});
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
"use strict";var a=Object.create;var t=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var c=(r,o)=>{for(var e in o)t(r,e,{get:o[e],enumerable:!0})},f=(r,o,e,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let m of u(o))!b.call(r,m)&&m!==e&&t(r,m,{get:()=>o[m],enumerable:!(n=d(o,m))||n.enumerable});return r};var k=(r,o,e)=>(e=r!=null?a(x(r)):{},f(o||!r||!r.__esModule?t(e,"default",{value:r,enumerable:!0}):e,r)),v=r=>f(t({},"__esModule",{value:!0}),r);var P={};c(P,{doTree:()=>i.doTree,makePot:()=>g.makePot});module.exports=v(P);var p=require("./cli/getArgs.js"),s=k(require("./run.js")),g=require("./parser/makePot.js"),i=require("./parser/tree.js");const A=(0,p.getArgs)();(0,s.default)(A);0&&(module.exports={doTree,makePot});
|
|
1
|
+
"use strict";var k=Object.create;var t=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var s=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var J=(o,r)=>{for(var e in r)t(o,e,{get:r[e],enumerable:!0})},x=(o,r,e,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let m of n(r))!u.call(o,m)&&m!==e&&t(o,m,{get:()=>r[m],enumerable:!(a=l(r,m))||a.enumerable});return o};var d=(o,r,e)=>(e=o!=null?k(s(o)):{},x(r||!o||!o.__esModule?t(e,"default",{value:o,enumerable:!0}):e,o)),P=o=>x(t({},"__esModule",{value:!0}),o);var b={};J(b,{default:()=>T,doTree:()=>i.doTree,makeJson:()=>p.default,makePot:()=>f.default});module.exports=P(b);var p=d(require("./jsonCommand")),f=d(require("./potCommand")),i=require("./parser/tree.js"),T={makeJson:p.default,makePot:f.default};0&&(module.exports={doTree,makeJson,makePot});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var p=Object.create;var r=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;var J=(o,e)=>{for(var n in e)r(o,n,{get:e[n],enumerable:!0})},s=(o,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let m of f(e))!l.call(o,m)&&m!==n&&r(o,m,{get:()=>e[m],enumerable:!(t=c(e,m))||t.enumerable});return o};var M=(o,e,n)=>(n=o!=null?p(d(o)):{},s(e||!o||!o.__esModule?r(n,"default",{value:o,enumerable:!0}):n,o)),u=o=>s(r({},"__esModule",{value:!0}),o);var g={};J(g,{default:()=>k});module.exports=u(g);var i=M(require("./parser/makeJson")),a=require("./utils/common");function k(o){const e=new i.default(o);if(Object.keys(o).length>0){(0,a.printMakePotModuleInfo)();const n=new Date;e.invoke().then(t=>{o.debug&&console.log(t),(0,a.printTimeElapsed)(n)}).catch(t=>{console.error(`\u{1FAE4} make-json - Error: ${t}`)})}}
|
package/lib/makeJson.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";var i=Object.create;var e=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var b=(o,r,n,m)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of f(r))!J.call(o,s)&&s!==n&&e(o,s,{get:()=>r[s],enumerable:!(m=a(r,s))||m.enumerable});return o};var c=(o,r,n)=>(n=o!=null?i(p(o)):{},b(r||!o||!o.__esModule?e(n,"default",{value:o,enumerable:!0}):n,o));var t=require("./cli/getJsonArgs"),g=c(require("./jsonCommand"));const d=(0,t.getJsonArgs)();(0,g.default)(d);
|
package/lib/makePot.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";var i=Object.create;var p=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var d=(r,m,o,e)=>{if(m&&typeof m=="object"||typeof m=="function")for(let t of a(m))!A.call(r,t)&&t!==o&&p(r,t,{get:()=>m[t],enumerable:!(e=n(m,t))||e.enumerable});return r};var y=(r,m,o)=>(o=r!=null?i(f(r)):{},d(m||!r||!r.__esModule?p(o,"default",{value:r,enumerable:!0}):o,r));var s=require("./cli/getArgs.js"),g=y(require("./potCommand"));(0,g.default)((0,s.getArgs)());
|
package/lib/parser/exec.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
|
|
3
|
-
${
|
|
1
|
+
"use strict";var C=Object.create;var s=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var A=(t,n)=>{for(var o in n)s(t,o,{get:n[o],enumerable:!0})},l=(t,n,o,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of w(n))!k.call(t,i)&&i!==o&&s(t,i,{get:()=>n[i],enumerable:!(e=j(n,i))||e.enumerable});return t};var m=(t,n,o)=>(o=t!=null?C($(t)):{},l(n||!t||!t.__esModule?s(o,"default",{value:t,enumerable:!0}):o,t)),B=t=>l(s({},"__esModule",{value:!0}),t);var H={};A(H,{exec:()=>G});module.exports=B(H);var c=m(require("node:path")),g=require("gettext-parser"),f=m(require("tannin")),r=require("../extractors/headers.js"),p=require("../fs/fs"),a=require("../utils/common.js"),d=require("./patterns.js"),u=require("./process.js"),h=require("./progress.js"),P=require("./taskRunner.js");function D(t,n){console.log(`
|
|
2
|
+
Script Path: ${t}
|
|
3
|
+
for ${n.include.join()}
|
|
4
|
+
ignoring patterns: ${n.exclude.join()}
|
|
5
|
+
`)}async function G(t){t.options?.silent||(console.log("\u{1F4DD} Starting makePot for",t?.slug),(0,a.printStats)()),t.options?.skip.audit&&(console.log(`
|
|
6
|
+
Audit strings...`),console.log("TODO"),console.log("\u2705 Done"));const n=await(0,r.generateHeader)(t);let o=(0,r.translationsHeaders)(t);const e=(0,d.getPatterns)(t);t.options?.silent||D(c.default.resolve(t.paths.cwd),e);const i=(0,h.initProgress)(t,0)??void 0,T=await(0,u.processFiles)(e,t,i);if(o=await(0,P.taskRunner)(T,o,t,i),t.options?.json){const x={[t.slug]:{"":n,...o.toJson()}};return new f.default(x).toString()}const y={charset:(0,p.getEncodingCharset)(t.options?.charset),headers:n,translations:o.toJson()},S=g.po.compile(y).toString((0,p.getCharset)(t.options?.charset));return`${t.options?.fileComment||(0,a.getCopyright)(t.slug,t.headers?.license??"GPL v2 or later")}
|
|
7
|
+
${S}`}0&&(module.exports={exec});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var b=Object.create;var p=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var P=(n,t)=>{for(var e in t)p(n,e,{get:t[e],enumerable:!0})},h=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of J(t))!N.call(n,i)&&i!==e&&p(n,i,{get:()=>t[i],enumerable:!(s=x(t,i))||s.enumerable});return n};var m=(n,t,e)=>(e=n!=null?b(w(n)):{},h(t||!n||!n.__esModule?p(e,"default",{value:n,enumerable:!0}):e,n)),S=n=>h(p({},"__esModule",{value:!0}),n);var T={};P(T,{MakeJsonCommand:()=>v,default:()=>D});module.exports=S(T);var f=m(require("node:crypto")),c=m(require("node:fs")),o=m(require("node:path")),y=require("gettext-parser"),g=require("glob"),u=require("../const");class v{source;destination;allowedFormats;purge;prettyPrint;debug;scriptName;paths;sourceDir;constructor(t){if(this.sourceDir=o.default.relative(t.paths.cwd,t.source??""),!c.existsSync(this.sourceDir))throw console.error("Source directory not found",t),new Error(`Source directory ${this.sourceDir} not found`);this.scriptName=t.scriptName,this.source=t.source,this.destination=t.destination,this.allowedFormats=t.allowedFormats??[".ts",".tsx",".js",".jsx",".mjs",".cjs"],this.purge=t.purge,this.prettyPrint=t.prettyPrint,this.debug=t.debug,this.paths=t.paths}async invoke(){const t=await(0,g.glob)("**/*.po",{cwd:this.destination,nodir:!0});console.log("Found po files",t,"in",this.destination,"folder");const e={};for(const s of t)if(this.scriptName||(this.scriptName=await(0,g.glob)("*.js",{cwd:this.source,nodir:!0}),console.log("Found script:",this.scriptName,"in",this.source,"folder")),typeof this.scriptName=="string"){const i=this.addPot(s,this.scriptName);e[i.filename]=i.data}else if(Array.isArray(this.scriptName))for(const i of this.scriptName){const r=this.addPot(s,i);e[r.filename]=r.data}for(const[s,i]of Object.entries(e)){let r;if(this.purge)c.existsSync(o.default.join(this.destination,s))&&(console.log(`Removing ${o.default.join(this.destination,s)} as the purge option is enabled`),c.unlinkSync(o.default.join(this.destination,s))),r=JSON.stringify(i,null,this?.prettyPrint?2:0);else{const l=c.readFileSync(o.default.join(this.source,s),"utf8");r=JSON.stringify({...i,...JSON.parse(l)},null,this?.prettyPrint?2:0)}const a=o.default.join(this.destination,s);c.writeFileSync(a,r),console.log(`JSON file written to ${a} with ${s}`)}return e}processFile(t,e="utf8"){const s=c.readFileSync(t,e),i=this.extractIsoCode(t),r=this.parsePoFile(s);return this.convertToJed(r.headers,r.translations,i)}parsePoFile(t){return y.po.parse(t)}convertToJed(t,e,s){const i="messages",r={[i]:{"":{domain:i,lang:s||t.Language||"en",plural_forms:t["Plural-Forms"]||"nplurals=2; plural=(n != 1);"}}};for(const a of Object.keys(e)){const l=e[a];for(const d of Object.keys(l)){const F=l[d];if(d==="")continue;const j=a&&a!==""?`${a}${d}`:d;r[i][j]=F.msgstr}}return r}extractIsoCode(t){const e=t.match(u.IsoCodeRegex);return e?e[1]:void 0}getPluralForms(t){const e=t.match(/Plural-Forms:\s*(.*?)\n/);return e?e[1]:"nplurals=2; plural=(n != 1);"}getLanguage(t){const e=t.match(/Language:\s*(.*?)\n/);return e?e[1]:u.defaultLocale}isCompatibleFile(t){return this.allowedFormats?t.some(e=>this.allowedFormats.some(s=>e.endsWith(s))):!0}md5(t){return f.default.createHash("md5").update(t).digest("hex")}addPot(t,e){const s=this.md5(e);return{filename:t.replace(".po",`-${s}.json`),data:this.processFile(o.default.join(this.destination,t))}}}var D=v;0&&(module.exports={MakeJsonCommand});
|
package/lib/parser/makePot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var d=(e,t)=>{for(var o in t)a(e,o,{get:t[o],enumerable:!0})},x=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let m of f(t))!h.call(e,m)&&m!==o&&a(e,m,{get:()=>t[m],enumerable:!(r=s(t,m))||r.enumerable});return e};var k=e=>x(a({},"__esModule",{value:!0}),e);var y={};d(y,{makePot:()=>u});module.exports=k(y);var c=require("../extractors/headers.js"),i=require("../extractors/json.js"),n=require("../fs/fs.js"),p=require("./exec.js");async function u(e){const t=(0,i.extractPackageJson)(e),o=(0,c.extractMainFileData)(e);e.headers={...e.headers,...t,...o},(0,p.exec)(e).then(r=>((0,n.writeFile)(r,e),r)).catch(r=>(console.error(r),""))}0&&(module.exports={makePot});
|
package/lib/parser/patterns.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var n=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var h=(t,e)=>{for(var p in e)n(t,p,{get:e[p],enumerable:!0})},l=(t,e,p,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of u(e))!c.call(t,s)&&s!==p&&n(t,s,{get:()=>e[s],enumerable:!(o=i(e,s))||o.enumerable});return t};var d=t=>l(n({},"__esModule",{value:!0}),t);var a={};h(a,{getPatterns:()=>r});module.exports=d(a);function r(t){const e={include:t.patterns.include||[],exclude:t.patterns.exclude||[],mergePaths:t.patterns.mergePaths,subtractPaths:t.patterns.subtractPaths,subtractAndMerge:t.patterns.subtractAndMerge};return t.options&&(t.options.skip.blade?e.exclude.push("**/blade.php"):t.options.skip.php&&e.exclude.push("**/*.php","**/*.blade.php"),t.options.skip.js&&e.exclude.push("**/*.{js,jsx,ts,tsx,mjs,cjs}"),t.options.skip.blockJson&&e.exclude.push("block.json"),t.options.skip.themeJson&&e.exclude.push("theme.json")),e}0&&(module.exports={getPatterns});
|
package/lib/parser/process.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var S=Object.create;var m=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var x=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},h=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of g(t))!w.call(e,s)&&s!==o&&m(e,s,{get:()=>t[s],enumerable:!(r=b(t,s))||r.enumerable});return e};var F=(e,t,o)=>(o=e!=null?S(j(e)):{},h(t||!e||!e.__esModule?m(o,"default",{value:e,enumerable:!0}):o,e)),O=e=>h(m({},"__esModule",{value:!0}),e);var v={};x(v,{processFiles:()=>A});module.exports=O(v);var n=F(require("node:path")),d=require("../const.js"),u=require("../extractors/json.js"),a=require("../fs/fs.js"),k=require("../fs/glob.js"),y=require("./tree.js");async function A(e,t,o){const r=[];let s=0;const c=(0,k.getFiles)(t,e);for await(const i of c){s++;const l=n.default.basename(i),P=n.default.extname(i).replace(/^./,""),p=n.default.resolve(t.paths.cwd,i);l==="theme.json"||l==="block.json"?r.push((0,a.readFileAsync)(p).then(f=>(0,u.parseJsonCallback)(f,t.paths.cwd,l))):d.allowedFormats.includes(P)&&r.push((0,a.readFileAsync)(p).then(f=>(0,y.doTree)(f,i))),o&&(o.update(s,{filename:l}),o.setTotal(Object.values(c).length),o.render())}return r}0&&(module.exports={processFiles});
|
package/lib/parser/taskRunner.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var f=(t,o)=>{for(var s in o)n(t,s,{get:o[s],enumerable:!0})},g=(t,o,s,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of a(o))!p.call(t,e)&&e!==s&&n(t,e,{get:()=>o[e],enumerable:!(r=c(o,e))||r.enumerable});return t};var m=t=>g(n({},"__esModule",{value:!0}),t);var h={};f(h,{taskRunner:()=>u});module.exports=m(h);async function u(t,o,s,r){return await Promise.allSettled(t).then(e=>e.map(l=>l.status==="fulfilled"&&l.value).filter(Boolean)).then(e=>{if(r?.stop(),s.options?.silent!==!0)for(const l of e)l.blocks.length>0?(o.addArray(l.blocks),console.log(`\u2705 ${l.path} [${l.blocks.map(i=>i.msgid).join(", ")}]`)):console.log("\u274C ",`${l.path} has no strings`)}).catch(e=>{console.log("\u274C Failed!",e),process.exit(1)}),s.options?.silent||(console.log("\u{1F389} Done!"),console.log(`\u{1F4DD} Found ${Object.values(o.blocks).length} translation strings in ${s.paths.cwd}`)),o}0&&(module.exports={taskRunner});
|
package/lib/parser/tree.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var O=Object.create;var g=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},b=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of K(t))!F.call(e,s)&&s!==n&&g(e,s,{get:()=>t[s],enumerable:!(o=P(t,s))||o.enumerable});return e};var j=(e,t,n)=>(n=e!=null?O(L(e)):{},b(t||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e)),E=e=>b(g({},"__esModule",{value:!0}),e);var V={};M(V,{doTree:()=>U});module.exports=E(V);var k=j(require("tree-sitter")),y=require("../const.js"),a=require("gettext-merger"),w=require("../fs/glob.js"),m=require("../utils/common.js");function I(e){let t=e,n=0;for(;t&&n<6;){if(t?.previousSibling?.type==="comment"&&t?.previousSibling?.text.toLowerCase().includes("translators"))return t?.previousSibling?.text?(0,m.stripTranslationMarkup)(t.previousSibling.text):void 0;n++,t=t.parent}}function U(e,t){const n=new k.default,o=(0,w.getParser)(t);if(!o)return new a.SetOfBlocks([],t);n.setLanguage(o);const s=n.parse(e),x=new a.SetOfBlocks([],t),v=t.split(".").pop()?.toLowerCase()!=="php"?"call_expression":"function_call_expression",N=["string","string_value","variable_name","binary_expression","member_expression","subscript_expression","function_call_expression","encapsed_string"];function _(r){if(r?.children.length)for(const c of r.children)_(c);if(r?.type===v){const c=r.firstChild?.text??null;if(c===null||!Object.keys(y.i18nFunctions).includes(c))return;const p=r.lastChild;if(p===null||p.childCount===0||p.type!=="arguments")return;const[q,C]=r.children,l={},h=y.i18nFunctions[c],$=C.children.slice(1,-1);let f=0;for(const u of $){let i=u,d=i.text;if(u.type==="argument"){if(u.children.length===0)continue;i=u.children[0]}if(i?.type===",")continue;if(i?.type&&N.includes(i.type))d=d.slice(1,-1);else{console.warn(`Unexpected node type: ${i?.type} is ${h[f]} for ${d} in ${t}`);continue}const T=h[f];l[T]=d,f+=1}const S=I(p),B=new a.Block({msgctxt:l.msgctxt,msgid:l.msgid??"",msgid_plural:l.msgid_plural,msgstr:l.msgid_plural?["",""]:[""],comments:{translator:S?[S]:void 0,reference:[`${(0,m.reverseSlashes)(t)}:${r.startPosition.row+1}`]}});x.add(B)}}return _(s.rootNode),x}0&&(module.exports={doTree});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var n=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var l=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},d=(e,t,o,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of s(t))!c.call(e,r)&&r!==o&&n(e,r,{get:()=>t[r],enumerable:!(p=f(t,r))||p.enumerable});return e};var k=e=>d(n({},"__esModule",{value:!0}),e);var h={};l(h,{default:()=>a});module.exports=k(h);var i=require("./parser/makePot.js"),m=require("./utils/common");function a(e){if(Object.keys(e).length>0){(0,m.printMakePotModuleInfo)();const t=new Date;(0,i.makePot)(e).then(()=>{(0,m.printTimeElapsed)(t)}).catch(o=>{console.error(`\u{1FAE4} Make-pot - ${o}`)})}}
|
package/lib/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var p=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of i(e))!g.call(t,n)&&n!==o&&s(t,n,{get:()=>e[n],enumerable:!(r=a(e,n))||r.enumerable});return t};var l=t=>p(s({},"__esModule",{value:!0}),t);var d={};module.exports=l(d);
|