@wp-blocks/make-pot 1.6.5 → 1.6.6
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 +2 -2
- package/lib/assets/block-i18n.js +41 -1
- package/lib/assets/package-i18n.js +38 -1
- package/lib/assets/theme-i18n.js +110 -1
- package/lib/assets/wp-plugin-i18n.js +39 -1
- package/lib/assets/wp-theme-i18n.js +37 -1
- package/lib/cli/getArgs.js +156 -1
- package/lib/cli/getArgs.js.map +2 -2
- package/lib/cli/getJsonArgs.js +82 -1
- package/lib/cli/parseCli.js +179 -1
- package/lib/cli.js +43 -1
- package/lib/const.js +111 -1
- package/lib/extractors/auditStrings.js +177 -6
- package/lib/extractors/auditStrings.js.map +2 -2
- package/lib/extractors/css.js +69 -1
- package/lib/extractors/headers.js +253 -15
- package/lib/extractors/headers.js.map +2 -2
- package/lib/extractors/json.js +70 -1
- package/lib/extractors/packageJson.js +55 -1
- package/lib/extractors/php.js +79 -2
- package/lib/extractors/php.js.map +2 -2
- package/lib/extractors/schema.js +217 -3
- package/lib/extractors/text.js +41 -1
- package/lib/fs/fs.js +114 -2
- package/lib/fs/glob.js +103 -1
- package/lib/index.js +64 -1
- package/lib/jsonCommand.js +51 -1
- package/lib/makeJson.js +28 -1
- package/lib/makePot.js +27 -1
- package/lib/parser/exec.js +94 -3
- package/lib/parser/exec.js.map +2 -2
- package/lib/parser/makeJson.js +393 -1
- package/lib/parser/makePot.js +48 -1
- package/lib/parser/patterns.js +54 -1
- package/lib/parser/process.js +85 -1
- package/lib/parser/progress.js +57 -1
- package/lib/parser/taskRunner.js +65 -2
- package/lib/parser/taskRunner.js.map +2 -2
- package/lib/parser/tree.js +228 -2
- package/lib/potCommand.js +36 -1
- package/lib/potCommand.js.map +2 -2
- package/lib/types.js +17 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/common.js +161 -8
- package/lib/utils/common.js.map +2 -2
- package/lib/utils/extractors.js +69 -1
- package/lib/utils/output.js +59 -1
- package/lib/utils/output.js.map +3 -3
- package/package.json +1 -2
- package/tests/parse-php.test.js +47 -0
package/lib/extractors/php.js
CHANGED
|
@@ -1,2 +1,79 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var php_exports = {};
|
|
30
|
+
__export(php_exports, {
|
|
31
|
+
extractPhpPluginData: () => extractPhpPluginData,
|
|
32
|
+
parsePHPFile: () => parsePHPFile
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(php_exports);
|
|
35
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
36
|
+
var import_node_path = __toESM(require("node:path"));
|
|
37
|
+
var import_const = require("../const.js");
|
|
38
|
+
var import_extractors = require("../utils/extractors.js");
|
|
39
|
+
function extractPhpPluginData(args) {
|
|
40
|
+
let fileData = {};
|
|
41
|
+
const folderPhpFile = import_node_path.default.join(args.paths.cwd, `${args.slug}.php`);
|
|
42
|
+
if (import_node_fs.default.existsSync(folderPhpFile)) {
|
|
43
|
+
const fileContent = import_node_fs.default.readFileSync(folderPhpFile, "utf8");
|
|
44
|
+
fileData = parsePHPFile(fileContent);
|
|
45
|
+
console.log(`\u{1F535} Plugin file detected. (${folderPhpFile})`);
|
|
46
|
+
args.domain = "plugin";
|
|
47
|
+
return fileData;
|
|
48
|
+
}
|
|
49
|
+
console.log("Plugin file not found.");
|
|
50
|
+
console.log(`Missing Plugin filename: ${folderPhpFile}`);
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
function parsePHPFile(phpContent) {
|
|
54
|
+
const match = phpContent.match(/\/\*\*?([\s\S]*?)\*\//);
|
|
55
|
+
if (match?.[1] && match) {
|
|
56
|
+
const commentBlock = match[1];
|
|
57
|
+
const lines = commentBlock.split("\n");
|
|
58
|
+
const pluginInfo = {};
|
|
59
|
+
for (const line of lines) {
|
|
60
|
+
const keyValueMatch = line.match(/^\s*(?:\*\s*)?([^:]+):\s*(.*)/);
|
|
61
|
+
if (!keyValueMatch) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (keyValueMatch?.[1] && keyValueMatch[2]) {
|
|
65
|
+
const header = (0, import_extractors.getKeyByValue)(import_const.pluginHeaders, keyValueMatch[1].trim());
|
|
66
|
+
if (header === void 0) continue;
|
|
67
|
+
pluginInfo[header] = keyValueMatch[2].trim();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return pluginInfo;
|
|
71
|
+
}
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
extractPhpPluginData,
|
|
77
|
+
parsePHPFile
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=php.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/extractors/php.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { pluginHeaders } from \"../const.js\";\nimport type { Args } from \"../types.js\";\nimport { getKeyByValue } from \"../utils/extractors.js\";\n\nexport function extractPhpPluginData(args: Args): Record<string, string> {\n\tlet fileData: Record<string, string> = {};\n\tconst folderPhpFile = path.join(args.paths.cwd, `${args.slug}.php`);\n\n\tif (fs.existsSync(folderPhpFile)) {\n\t\tconst fileContent = fs.readFileSync(folderPhpFile, \"utf8\");\n\t\tfileData = parsePHPFile(fileContent);\n\n\t\tconsole.log(`\uD83D\uDD35 Plugin file detected. (${folderPhpFile})`);\n\n\t\t// Set the domain\n\t\targs.domain = \"plugin\";\n\n\t\treturn fileData;\n\t}\n\n\tconsole.log(\"Plugin file not found.\");\n\tconsole.log(`Missing Plugin filename: ${folderPhpFile}`);\n\n\treturn {};\n}\n\n/**\n * Parses a PHP file and extracts the plugin information from the comment block.\n *\n * @param {string} phpContent - The content of the PHP file.\n * @return {Record<string, string>} - A record containing the plugin information.\n */\nexport function parsePHPFile(phpContent: string): Record<string, string> {\n\tconst match = phpContent.match(
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,uBAAiB;AACjB,mBAA8B;AAE9B,wBAA8B;AAEvB,SAAS,qBAAqB,MAAoC;AACxE,MAAI,WAAmC,CAAC;AACxC,QAAM,gBAAgB,iBAAAA,QAAK,KAAK,KAAK,MAAM,KAAK,GAAG,KAAK,IAAI,MAAM;AAElE,MAAI,eAAAC,QAAG,WAAW,aAAa,GAAG;AACjC,UAAM,cAAc,eAAAA,QAAG,aAAa,eAAe,MAAM;AACzD,eAAW,aAAa,WAAW;AAEnC,YAAQ,IAAI,oCAA6B,aAAa,GAAG;AAGzD,SAAK,SAAS;AAEd,WAAO;AAAA,EACR;AAEA,UAAQ,IAAI,wBAAwB;AACpC,UAAQ,IAAI,4BAA4B,aAAa,EAAE;AAEvD,SAAO,CAAC;AACT;AAQO,SAAS,aAAa,YAA4C;AACxE,QAAM,QAAQ,WAAW,MAAM,
|
|
4
|
+
"sourcesContent": ["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { pluginHeaders } from \"../const.js\";\nimport type { Args } from \"../types.js\";\nimport { getKeyByValue } from \"../utils/extractors.js\";\n\nexport function extractPhpPluginData(args: Args): Record<string, string> {\n\tlet fileData: Record<string, string> = {};\n\tconst folderPhpFile = path.join(args.paths.cwd, `${args.slug}.php`);\n\n\tif (fs.existsSync(folderPhpFile)) {\n\t\tconst fileContent = fs.readFileSync(folderPhpFile, \"utf8\");\n\t\tfileData = parsePHPFile(fileContent);\n\n\t\tconsole.log(`\uD83D\uDD35 Plugin file detected. (${folderPhpFile})`);\n\n\t\t// Set the domain\n\t\targs.domain = \"plugin\";\n\n\t\treturn fileData;\n\t}\n\n\tconsole.log(\"Plugin file not found.\");\n\tconsole.log(`Missing Plugin filename: ${folderPhpFile}`);\n\n\treturn {};\n}\n\n/**\n * Parses a PHP file and extracts the plugin information from the comment block.\n *\n * @param {string} phpContent - The content of the PHP file.\n * @return {Record<string, string>} - A record containing the plugin information.\n */\nexport function parsePHPFile(phpContent: string): Record<string, string> {\n\tconst match = phpContent.match(/\\/\\*\\*?([\\s\\S]*?)\\*\\//);\n\n\tif (match?.[1] && match) {\n\t\tconst commentBlock = match[1];\n\t\tconst lines = commentBlock.split(\"\\n\");\n\n\t\tconst pluginInfo: Record<string, string> = {};\n\n\t\tfor (const line of lines) {\n\t\t\tconst keyValueMatch = line.match(/^\\s*(?:\\*\\s*)?([^:]+):\\s*(.*)/);\n\n\t\t\tif (!keyValueMatch) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Check if the line matches the expected format\n\t\t\tif (keyValueMatch?.[1] && keyValueMatch[2]) {\n\t\t\t\t// filter the retrieved headers\n\t\t\t\tconst header = getKeyByValue(pluginHeaders, keyValueMatch[1].trim());\n\t\t\t\tif (header === undefined) continue;\n\t\t\t\tpluginInfo[header] = keyValueMatch[2].trim();\n\t\t\t}\n\t\t}\n\n\t\treturn pluginInfo;\n\t}\n\treturn {};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,uBAAiB;AACjB,mBAA8B;AAE9B,wBAA8B;AAEvB,SAAS,qBAAqB,MAAoC;AACxE,MAAI,WAAmC,CAAC;AACxC,QAAM,gBAAgB,iBAAAA,QAAK,KAAK,KAAK,MAAM,KAAK,GAAG,KAAK,IAAI,MAAM;AAElE,MAAI,eAAAC,QAAG,WAAW,aAAa,GAAG;AACjC,UAAM,cAAc,eAAAA,QAAG,aAAa,eAAe,MAAM;AACzD,eAAW,aAAa,WAAW;AAEnC,YAAQ,IAAI,oCAA6B,aAAa,GAAG;AAGzD,SAAK,SAAS;AAEd,WAAO;AAAA,EACR;AAEA,UAAQ,IAAI,wBAAwB;AACpC,UAAQ,IAAI,4BAA4B,aAAa,EAAE;AAEvD,SAAO,CAAC;AACT;AAQO,SAAS,aAAa,YAA4C;AACxE,QAAM,QAAQ,WAAW,MAAM,uBAAuB;AAEtD,MAAI,QAAQ,CAAC,KAAK,OAAO;AACxB,UAAM,eAAe,MAAM,CAAC;AAC5B,UAAM,QAAQ,aAAa,MAAM,IAAI;AAErC,UAAM,aAAqC,CAAC;AAE5C,eAAW,QAAQ,OAAO;AACzB,YAAM,gBAAgB,KAAK,MAAM,+BAA+B;AAEhE,UAAI,CAAC,eAAe;AACnB;AAAA,MACD;AAGA,UAAI,gBAAgB,CAAC,KAAK,cAAc,CAAC,GAAG;AAE3C,cAAM,aAAS,iCAAc,4BAAe,cAAc,CAAC,EAAE,KAAK,CAAC;AACnE,YAAI,WAAW,OAAW;AAC1B,mBAAW,MAAM,IAAI,cAAc,CAAC,EAAE,KAAK;AAAA,MAC5C;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACA,SAAO,CAAC;AACT;",
|
|
6
6
|
"names": ["path", "fs"]
|
|
7
7
|
}
|
package/lib/extractors/schema.js
CHANGED
|
@@ -1,3 +1,217 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var schema_exports = {};
|
|
30
|
+
__export(schema_exports, {
|
|
31
|
+
JsonSchemaExtractor: () => JsonSchemaExtractor
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(schema_exports);
|
|
34
|
+
var blocki18n = __toESM(require("../assets/block-i18n.js"));
|
|
35
|
+
var themei18n = __toESM(require("../assets/theme-i18n.js"));
|
|
36
|
+
class JsonSchemaExtractor {
|
|
37
|
+
static schemaCache = {};
|
|
38
|
+
/** Theme */
|
|
39
|
+
static themeJsonSource = "http://develop.svn.wordpress.org/trunk/src/wp-includes/theme-i18n.json";
|
|
40
|
+
static themeJsonFallback = themei18n;
|
|
41
|
+
/** Block */
|
|
42
|
+
static blockJsonSource = "http://develop.svn.wordpress.org/trunk/src/wp-includes/block-i18n.json";
|
|
43
|
+
static blockJsonFallback = blocki18n;
|
|
44
|
+
/**
|
|
45
|
+
* Load the schema from the specified URL, with a fallback URL if needed.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} url - The URL to load the schema from.
|
|
48
|
+
* @param {I18nSchema} fallback - The fallback schema to use if the main URL fails.
|
|
49
|
+
* @return {Promise<I18nSchema>} The loaded schema.
|
|
50
|
+
*/
|
|
51
|
+
static async loadSchema(url, fallback) {
|
|
52
|
+
if (JsonSchemaExtractor.schemaCache[url]) {
|
|
53
|
+
return JsonSchemaExtractor.schemaCache[url];
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const response = await fetch(url, {
|
|
57
|
+
headers: {
|
|
58
|
+
"Access-Control-Allow-Origin": "*"
|
|
59
|
+
}
|
|
60
|
+
}).then((response2) => response2.json()).catch((error) => {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`
|
|
63
|
+
Failed to load schema from ${url}. Error: ${error.message}`
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
if (!response) {
|
|
67
|
+
return fallback;
|
|
68
|
+
}
|
|
69
|
+
JsonSchemaExtractor.schemaCache[url] = response;
|
|
70
|
+
return response;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error(
|
|
73
|
+
`
|
|
74
|
+
Failed to load schema from ${url}. Using fallback. Error: ${error.message}`
|
|
75
|
+
);
|
|
76
|
+
JsonSchemaExtractor.schemaCache[url] = fallback;
|
|
77
|
+
return fallback;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Parses a string and extracts translations using the specified schema.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} text - the input string to be parsed
|
|
84
|
+
* @param {object} schema - the schema to use for parsing the input string
|
|
85
|
+
* @param {string} schema.url - the URL of the schema to use for parsing the input string
|
|
86
|
+
* @param {object} schema.schemaFallback - the fallback schema to use if the main schema fails
|
|
87
|
+
* @param {object} options - the options for parsing the input string
|
|
88
|
+
* @param {string} options.file - the name of the file being parsed
|
|
89
|
+
* @param {boolean} options.addReferences - whether to add references to the extracted strings
|
|
90
|
+
*
|
|
91
|
+
* @return {Promise<I18nSchema | undefined>} a promise that resolves with the extracted schema
|
|
92
|
+
*/
|
|
93
|
+
static async parse(text, schema, options) {
|
|
94
|
+
const parsedSchema = await JsonSchemaExtractor.loadSchema(
|
|
95
|
+
schema.url,
|
|
96
|
+
schema.fallback
|
|
97
|
+
);
|
|
98
|
+
try {
|
|
99
|
+
const json = JSON.parse(text);
|
|
100
|
+
if (!json) {
|
|
101
|
+
console.error("Could not parse JSON.");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
return JsonSchemaExtractor.extractFromJsonSchema(
|
|
105
|
+
json,
|
|
106
|
+
parsedSchema,
|
|
107
|
+
options
|
|
108
|
+
);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(`Error parsing JSON: ${error.message}`);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Extracts translatable strings from a JSON file by comparing it with a schema
|
|
116
|
+
*
|
|
117
|
+
* @param {Object} json - The JSON object to extract strings from
|
|
118
|
+
* @param {Object} schema - The schema that defines which fields contain translatable strings
|
|
119
|
+
* @param {Object} options - Options for extraction
|
|
120
|
+
* @param {string} options.filename - The name of the file being extracted (for references)
|
|
121
|
+
* @param {boolean} options.addReferences - Whether to add file references in comments
|
|
122
|
+
* @return {Array} - An array of objects with translatable strings in gettext format
|
|
123
|
+
*/
|
|
124
|
+
static extractFromJsonSchema(json, schema, options = {
|
|
125
|
+
filename: void 0,
|
|
126
|
+
addReferences: false
|
|
127
|
+
}) {
|
|
128
|
+
const { filename = "block.json", addReferences = false } = options;
|
|
129
|
+
const translations = [];
|
|
130
|
+
function extract(currentJson, currentSchema, path = []) {
|
|
131
|
+
if (!currentJson || !currentSchema) return;
|
|
132
|
+
if (typeof currentJson === "object" && !Array.isArray(currentJson) && typeof currentSchema === "object" && !Array.isArray(currentSchema)) {
|
|
133
|
+
for (const key of Object.keys(currentSchema)) {
|
|
134
|
+
if (key in currentJson) {
|
|
135
|
+
if (typeof currentJson[key] === "string") {
|
|
136
|
+
addTranslation(
|
|
137
|
+
currentJson[key],
|
|
138
|
+
currentSchema[key],
|
|
139
|
+
filename,
|
|
140
|
+
addReferences
|
|
141
|
+
);
|
|
142
|
+
} else if (Array.isArray(currentJson[key]) && Array.isArray(currentSchema[key])) {
|
|
143
|
+
handleArrays(
|
|
144
|
+
currentJson[key],
|
|
145
|
+
currentSchema[key],
|
|
146
|
+
[...path, key],
|
|
147
|
+
filename,
|
|
148
|
+
addReferences
|
|
149
|
+
);
|
|
150
|
+
} else if (typeof currentJson[key] === "object" && currentJson[key] !== null && typeof currentSchema[key] === "object") {
|
|
151
|
+
extract(
|
|
152
|
+
currentJson[key],
|
|
153
|
+
currentSchema[key],
|
|
154
|
+
[...path, key]
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function handleArrays(jsonArray, schemaArray, path, filename2, addReferences2) {
|
|
162
|
+
if (schemaArray.length > 0) {
|
|
163
|
+
const schemaTemplate = schemaArray[0];
|
|
164
|
+
for (const jsonItem of jsonArray) {
|
|
165
|
+
if (typeof jsonItem === "string") {
|
|
166
|
+
addTranslation(
|
|
167
|
+
jsonItem,
|
|
168
|
+
schemaTemplate,
|
|
169
|
+
filename2,
|
|
170
|
+
addReferences2
|
|
171
|
+
);
|
|
172
|
+
} else if (typeof jsonItem === "object" && jsonItem !== null) {
|
|
173
|
+
if (typeof schemaTemplate === "object") {
|
|
174
|
+
extract(
|
|
175
|
+
jsonItem,
|
|
176
|
+
schemaTemplate,
|
|
177
|
+
path
|
|
178
|
+
);
|
|
179
|
+
} else {
|
|
180
|
+
for (const key of Object.keys(jsonItem)) {
|
|
181
|
+
const value = jsonItem[key];
|
|
182
|
+
if (typeof value === "string") {
|
|
183
|
+
addTranslation(
|
|
184
|
+
value,
|
|
185
|
+
schemaTemplate,
|
|
186
|
+
filename2,
|
|
187
|
+
addReferences2
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function addTranslation(msgctxt, msgid, filename2, addReferences2) {
|
|
197
|
+
if (!msgctxt) return;
|
|
198
|
+
const translation = {
|
|
199
|
+
msgid,
|
|
200
|
+
msgctxt
|
|
201
|
+
};
|
|
202
|
+
if (addReferences2) {
|
|
203
|
+
translation.comments = {
|
|
204
|
+
reference: [filename2]
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
translations.push(translation);
|
|
208
|
+
}
|
|
209
|
+
extract(json, schema);
|
|
210
|
+
return translations;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
214
|
+
0 && (module.exports = {
|
|
215
|
+
JsonSchemaExtractor
|
|
216
|
+
});
|
|
217
|
+
//# sourceMappingURL=schema.js.map
|
package/lib/extractors/text.js
CHANGED
|
@@ -1 +1,41 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var text_exports = {};
|
|
20
|
+
__export(text_exports, {
|
|
21
|
+
extractFileData: () => extractFileData
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(text_exports);
|
|
24
|
+
var import_common = require("../utils/common.js");
|
|
25
|
+
function extractFileData(fileContent, separator = ":") {
|
|
26
|
+
const data = {};
|
|
27
|
+
const text = (0, import_common.removeCommentMarkup)(fileContent) ?? [];
|
|
28
|
+
for (const line of text) {
|
|
29
|
+
const parts = line.split(separator);
|
|
30
|
+
if (parts.length !== 2 && Object.values(data).length > 0 && parts[1]) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
data[parts[0]?.trim()] = parts[1].trim();
|
|
34
|
+
}
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
extractFileData
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=text.js.map
|
package/lib/fs/fs.js
CHANGED
|
@@ -1,2 +1,114 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var fs_exports = {};
|
|
30
|
+
__export(fs_exports, {
|
|
31
|
+
getCharset: () => getCharset,
|
|
32
|
+
getEncodingCharset: () => getEncodingCharset,
|
|
33
|
+
readFileAsync: () => readFileAsync,
|
|
34
|
+
writeFile: () => writeFile
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(fs_exports);
|
|
37
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
38
|
+
var import_promises = require("node:fs/promises");
|
|
39
|
+
var import_node_path = __toESM(require("node:path"));
|
|
40
|
+
function ensureFolderExists(folderPath) {
|
|
41
|
+
if (folderPath === void 0) {
|
|
42
|
+
return ".";
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
import_node_fs.default.accessSync(
|
|
46
|
+
import_node_path.default.resolve(folderPath),
|
|
47
|
+
import_node_fs.default.constants.R_OK | import_node_fs.default.constants.W_OK
|
|
48
|
+
);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (error.code === "ENOENT") {
|
|
51
|
+
import_node_fs.default.mkdirSync(folderPath, { recursive: true });
|
|
52
|
+
console.log(`Folder created: ${folderPath}`);
|
|
53
|
+
return folderPath;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return folderPath;
|
|
57
|
+
}
|
|
58
|
+
function getCharset(charset) {
|
|
59
|
+
if (!charset) {
|
|
60
|
+
return "latin1";
|
|
61
|
+
}
|
|
62
|
+
switch (charset.toLowerCase()) {
|
|
63
|
+
case "utf-8":
|
|
64
|
+
case "utf8":
|
|
65
|
+
return "utf-8";
|
|
66
|
+
default:
|
|
67
|
+
return "latin1";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function getEncodingCharset(charset) {
|
|
71
|
+
if (!charset) {
|
|
72
|
+
return "iso-8859-1";
|
|
73
|
+
}
|
|
74
|
+
switch (charset.toLowerCase()) {
|
|
75
|
+
case "utf-8":
|
|
76
|
+
case "utf8":
|
|
77
|
+
return "utf-8";
|
|
78
|
+
default:
|
|
79
|
+
return "iso-8859-1";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function getOutputFilePath(args) {
|
|
83
|
+
const { paths, headers, options } = args;
|
|
84
|
+
const out = paths.out;
|
|
85
|
+
let i18nFolder = out ?? headers?.domainPath ?? "languages";
|
|
86
|
+
i18nFolder = i18nFolder.replace(/^\/+|\/+$/g, "");
|
|
87
|
+
const extension = options?.json ? "json" : "pot";
|
|
88
|
+
return import_node_path.default.join(process.cwd(), i18nFolder, `${args.slug}.${extension}`);
|
|
89
|
+
}
|
|
90
|
+
function writeFile(fileContent, args) {
|
|
91
|
+
const dest = getOutputFilePath(args);
|
|
92
|
+
if (ensureFolderExists(import_node_path.default.dirname(dest))) {
|
|
93
|
+
const encodingCharset = getCharset(args.options?.charset);
|
|
94
|
+
console.log(`
|
|
95
|
+
Pot File created at ${dest}`);
|
|
96
|
+
const potBuffer = Buffer.from(fileContent);
|
|
97
|
+
(0, import_node_fs.writeFileSync)(dest, potBuffer.toString(encodingCharset), {
|
|
98
|
+
encoding: encodingCharset
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
console.log(`Folder ${dest} does not exist and cannot be created`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function readFileAsync(path2) {
|
|
105
|
+
return (0, import_promises.readFile)(path2, "utf-8");
|
|
106
|
+
}
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
getCharset,
|
|
110
|
+
getEncodingCharset,
|
|
111
|
+
readFileAsync,
|
|
112
|
+
writeFile
|
|
113
|
+
});
|
|
114
|
+
//# sourceMappingURL=fs.js.map
|
package/lib/fs/glob.js
CHANGED
|
@@ -1 +1,103 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var glob_exports = {};
|
|
30
|
+
__export(glob_exports, {
|
|
31
|
+
classifyExcludes: () => classifyExcludes,
|
|
32
|
+
getFiles: () => getFiles,
|
|
33
|
+
getParser: () => getParser
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(glob_exports);
|
|
36
|
+
var import_node_path = __toESM(require("node:path"));
|
|
37
|
+
var import_glob = require("glob");
|
|
38
|
+
var import_minimatch = require("minimatch");
|
|
39
|
+
var javascript = __toESM(require("tree-sitter-javascript"));
|
|
40
|
+
var php = __toESM(require("tree-sitter-php"));
|
|
41
|
+
var ts = __toESM(require("tree-sitter-typescript"));
|
|
42
|
+
var import_common = require("../utils/common.js");
|
|
43
|
+
function getParser(file) {
|
|
44
|
+
const ext = (0, import_common.getFileExtension)(file);
|
|
45
|
+
switch (ext) {
|
|
46
|
+
case "ts":
|
|
47
|
+
return ts.typescript;
|
|
48
|
+
case "tsx":
|
|
49
|
+
return ts.tsx;
|
|
50
|
+
case "js":
|
|
51
|
+
case "jsx":
|
|
52
|
+
case "mjs":
|
|
53
|
+
case "cjs":
|
|
54
|
+
return javascript;
|
|
55
|
+
case "php":
|
|
56
|
+
return php.php;
|
|
57
|
+
case "blade.php":
|
|
58
|
+
return php.php_only;
|
|
59
|
+
default:
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function classifyExcludes(excludedPatterns) {
|
|
64
|
+
const dirs = [];
|
|
65
|
+
const filePatterns = [];
|
|
66
|
+
for (const exclude of excludedPatterns) {
|
|
67
|
+
const type = (0, import_common.detectPatternType)(exclude);
|
|
68
|
+
if (type === "directory") {
|
|
69
|
+
dirs.push(exclude);
|
|
70
|
+
} else {
|
|
71
|
+
filePatterns.push(exclude);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { dirs, filePatterns };
|
|
75
|
+
}
|
|
76
|
+
async function getFiles(args, pattern) {
|
|
77
|
+
const { dirs, filePatterns } = classifyExcludes(pattern.exclude);
|
|
78
|
+
const g = new import_glob.Glob(pattern.include, {
|
|
79
|
+
ignore: {
|
|
80
|
+
// Prune entire directory subtrees — glob won't enter these dirs at all
|
|
81
|
+
childrenIgnored: (p) => dirs.some((d) => p.isNamed(d)),
|
|
82
|
+
// Filter individual files by name or glob pattern
|
|
83
|
+
ignored: (p) => filePatterns.some((fp) => {
|
|
84
|
+
const type = (0, import_common.detectPatternType)(fp);
|
|
85
|
+
if (type === "file") {
|
|
86
|
+
return p.isNamed(fp);
|
|
87
|
+
}
|
|
88
|
+
return (0, import_minimatch.minimatch)(p.relative(), fp);
|
|
89
|
+
})
|
|
90
|
+
},
|
|
91
|
+
nodir: true,
|
|
92
|
+
cwd: args.paths.cwd,
|
|
93
|
+
root: args.paths.root ? import_node_path.default.resolve(args.paths.root) : void 0
|
|
94
|
+
});
|
|
95
|
+
return g.walk();
|
|
96
|
+
}
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
classifyExcludes,
|
|
100
|
+
getFiles,
|
|
101
|
+
getParser
|
|
102
|
+
});
|
|
103
|
+
//# sourceMappingURL=glob.js.map
|
package/lib/index.js
CHANGED
|
@@ -1 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var index_exports = {};
|
|
30
|
+
__export(index_exports, {
|
|
31
|
+
MakeJsonCommand: () => import_makeJson.MakeJsonCommand,
|
|
32
|
+
StringAuditor: () => import_auditStrings.default,
|
|
33
|
+
doTree: () => import_tree.doTree,
|
|
34
|
+
extractMainFileData: () => import_headers.extractMainFileData,
|
|
35
|
+
generateHeader: () => import_headers.generateHeader,
|
|
36
|
+
getAuthorFromPackage: () => import_headers.getAuthorFromPackage,
|
|
37
|
+
makeJson: () => import_jsonCommand.default,
|
|
38
|
+
makePot: () => import_potCommand.default,
|
|
39
|
+
makePotCommand: () => import_makePot.makePot,
|
|
40
|
+
parseJsonFile: () => import_json.parseJsonFile
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(index_exports);
|
|
43
|
+
var import_auditStrings = __toESM(require("./extractors/auditStrings.js"));
|
|
44
|
+
var import_jsonCommand = __toESM(require("./jsonCommand.js"));
|
|
45
|
+
var import_potCommand = __toESM(require("./potCommand.js"));
|
|
46
|
+
var import_makeJson = require("./parser/makeJson");
|
|
47
|
+
var import_makePot = require("./parser/makePot.js");
|
|
48
|
+
var import_tree = require("./parser/tree.js");
|
|
49
|
+
var import_json = require("./extractors/json.js");
|
|
50
|
+
var import_headers = require("./extractors/headers.js");
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
MakeJsonCommand,
|
|
54
|
+
StringAuditor,
|
|
55
|
+
doTree,
|
|
56
|
+
extractMainFileData,
|
|
57
|
+
generateHeader,
|
|
58
|
+
getAuthorFromPackage,
|
|
59
|
+
makeJson,
|
|
60
|
+
makePot,
|
|
61
|
+
makePotCommand,
|
|
62
|
+
parseJsonFile
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=index.js.map
|