@wp-blocks/make-pot 1.5.1 → 1.6.2
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 -1
- package/lib/assets/block-i18n.js.map +1 -7
- package/lib/assets/package-i18n.js.map +1 -7
- package/lib/assets/theme-i18n.js.map +1 -7
- package/lib/assets/wp-plugin-i18n.js.map +1 -7
- package/lib/assets/wp-theme-i18n.js.map +1 -7
- package/lib/cli/getArgs.js +1 -1
- package/lib/cli/getArgs.js.map +1 -7
- package/lib/cli/getJsonArgs.js +1 -1
- package/lib/cli/getJsonArgs.js.map +1 -7
- package/lib/cli/parseCli.js +1 -1
- package/lib/cli/parseCli.js.map +1 -7
- package/lib/cli.js.map +1 -7
- package/lib/const.js +1 -1
- package/lib/const.js.map +1 -7
- package/lib/extractors/auditStrings.js +5 -0
- package/lib/extractors/auditStrings.js.map +1 -0
- package/lib/extractors/css.js +1 -1
- package/lib/extractors/css.js.map +1 -7
- package/lib/extractors/headers.js +12 -4
- package/lib/extractors/headers.js.map +1 -7
- package/lib/extractors/json.js.map +1 -7
- package/lib/extractors/packageJson.js.map +1 -7
- package/lib/extractors/php.js.map +1 -7
- package/lib/extractors/schema.js.map +1 -7
- package/lib/extractors/text.js.map +1 -7
- package/lib/fs/fs.js +2 -2
- package/lib/fs/fs.js.map +1 -7
- package/lib/fs/glob.js +1 -1
- package/lib/fs/glob.js.map +1 -7
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -7
- package/lib/jsonCommand.js +1 -1
- package/lib/jsonCommand.js.map +1 -7
- package/lib/makeJson.js.map +1 -7
- package/lib/makePot.js.map +1 -7
- package/lib/parser/exec.js +3 -7
- package/lib/parser/exec.js.map +1 -7
- package/lib/parser/makeJson.js +1 -1
- package/lib/parser/makeJson.js.map +1 -7
- package/lib/parser/makePot.js +1 -1
- package/lib/parser/makePot.js.map +1 -7
- package/lib/parser/patterns.js +1 -1
- package/lib/parser/patterns.js.map +1 -7
- package/lib/parser/process.js +1 -1
- package/lib/parser/process.js.map +1 -7
- package/lib/parser/progress.js.map +1 -7
- package/lib/parser/taskRunner.js.map +1 -7
- package/lib/parser/tree.js +1 -1
- package/lib/parser/tree.js.map +1 -7
- package/lib/potCommand.js +1 -1
- package/lib/potCommand.js.map +1 -7
- package/lib/types.js +1 -1
- package/lib/types.js.map +1 -7
- package/lib/utils/common.js +8 -4
- package/lib/utils/common.js.map +1 -7
- package/lib/utils/extractors.js.map +1 -7
- package/lib/utils/output.js +1 -0
- package/lib/utils/output.js.map +1 -0
- package/package.json +9 -7
- package/tests/audit.test.js +50 -0
- package/tests/compare-json.test.js +81 -0
- package/tests/extract.test.js +38 -0
- package/tests/parse-headers.test.js +7 -6
- package/tests/tree.test.js +21 -0
package/lib/utils/common.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/common.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from \"node:fs\";\nimport { cpus, totalmem } from \"node:os\";\nimport path from \"node:path\";\nimport { modulePath } from \"../const.js\";\n\n/**\n * A function that removes comment markup from a given string.\n *\n * @param {string} input - The input string with comment markup.\n * @return {string} - The input string without comment markup.\n */\nexport function getCommentBlock(input: string): string {\n\tconst commentBlock = input.match(/\\/\\*\\*?[\\s\\S]*?\\*\\//);\n\treturn commentBlock !== null ? commentBlock[0] : input;\n}\n\n/**\n * A function that starts to capture the text after the first letter.\n *\n * @param {string} input - The input string with comment markup.\n * @return {string} - The input string without comment markup.\n */\nexport function removeCommentMarkup(input: string): string[] | null {\n\treturn input.match(/[a-zA-Z].*/gm);\n}\n\n/**\n * Removes the markup from a comment string.\n *\n * @param {string} comment - The comment string to remove markup from.\n * @return {string} The comment text without the markers.\n */\nexport function stripTranslationMarkup(comment: string): string {\n\tconst commentPattern =\n\t\t/\\/\\*\\*?\\s*(?:translators:)\\s*([\\s\\S]*?)\\s*\\*\\/|\\/\\/\\s*(?:translators:)\\s*(.*)$/i;\n\tconst matches = comment.match(commentPattern);\n\treturn matches ? matches[1] : comment;\n}\n\n/**\n * Splits a string into an array of strings based on the presence of a comma.\n *\n * @param {string} string - The string to be split.\n * @return {string[]} An array of strings after splitting the input string.\n */\nexport function stringstring(string: string | string[] | undefined): string[] {\n\tif (typeof string === \"string\") {\n\t\tif (string.includes(\",\")) {\n\t\t\treturn string.split(\",\");\n\t\t}\n\t\treturn [string];\n\t}\n\treturn [];\n}\n\n/**\n * Determines if a pattern represents a file, a directory, or a glob pattern.\n * @param pattern - The pattern string to evaluate.\n * @returns 'file', 'directory', or 'glob'.\n */\nexport function detectPatternType(\n\tpattern: string,\n): \"file\" | \"directory\" | \"glob\" {\n\tconst containsFileExtension = pattern.includes(\".\");\n\tconst containsDirectorySeparator = pattern.includes(path.sep);\n\n\tif (pattern.includes(\"*\")) {\n\t\treturn \"glob\";\n\t}\n\tif (!containsFileExtension && !containsDirectorySeparator) {\n\t\treturn \"directory\";\n\t}\n\tif (containsFileExtension && !containsDirectorySeparator) {\n\t\treturn \"file\";\n\t}\n\treturn \"glob\";\n}\n\n/**\n * Generates a copyright comment for the specified slug and license.\n *\n * @param slug - The slug to include in the copyright comment\n * @param [license='GPL v2 or later'] - The license to use in the copyright comment\n * @return The generated copyright comment\n */\nexport function getCopyright(\n\tslug: string,\n\tlicense = \"GPL v2 or later\",\n): string {\n\treturn (\n\t\t`# Copyright (C) ${new Date().getFullYear()} ${slug}\\n` +\n\t\t`# This file is distributed under the ${license} license.`\n\t);\n}\n\n/**\n * Reverse slashes in a path, and replace backward slashes with forward slashes\n *\n * @param filePath - The path to be reversed.\n * @return {string} The reversed path.\n */\nexport function reverseSlashes(filePath: string): string {\n\t// Replace backward slashes with forward slashes\n\treturn filePath.replace(/\\\\/g, \"/\");\n}\n\n/**\n * The makepot package.json file data\n * @arguments {string[]} fields - The fields to extract\n * @return {Record<string, unknown>} - The package.json data\n */\nexport function getPkgJsonData(\n\tlocation?: string,\n\t...fields: string[]\n): Record<string, unknown> {\n\tconst requested: Record<string, unknown> = {};\n\t// read the package.json file the is in the root directory\n\tconst pkgJsonPath = path.join(location || process.cwd(), \"package.json\");\n\t// read the package.json file or return an empty object\n\tconst pkgJson: Record<string, unknown> = fs.existsSync(pkgJsonPath)\n\t\t? require(pkgJsonPath)\n\t\t: {};\n\t// extract the requested fields from the package.json\n\tfor (const field of fields) {\n\t\tif (pkgJson[field]) {\n\t\t\trequested[field] = pkgJson[field];\n\t\t}\n\t}\n\treturn requested;\n}\n\n/**\n * Print the module header with the current version and name\n */\nexport function printMakePotModuleInfo() {\n\tconst { version, name } = getPkgJsonData(modulePath, \"name\", \"version\");\n\t/* print the version */\n\tconsole.log(`${name} version: ${version}`);\n}\n\n/**\n * Output to the console the time elapsed in milliseconds between two dates\n * @param scriptName the name of the script\n * @param timeStart the start time\n * @param timeEnd the end time\n */\nexport function printTimeElapsed(\n\tscriptName: \"Make-Pot\" | \"Make-Json\",\n\ttimeStart: Date,\n\ttimeEnd: Date = new Date(),\n) {\n\tconsole.log(\n\t\t`\\n\uD83D\uDE80 ${scriptName}: Job completed! ${scriptName.split(\"-\")[1]} file created in ${\n\t\t\ttimeEnd.getTime() - timeStart.getTime()\n\t\t}ms`,\n\t);\n}\n\n/**\n/**\n* Prints the memory usage and cpu usage of the system\n */\nexport function printStats() {\n\tconsole.log(\n\t\t\"Memory usage:\",\n\t\t(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2),\n\t\t\"MB (Free:\",\n\t\t(totalmem() / 1024 / 1024 / 1024).toFixed(2),\n\t\t\"GB)\\nCpu User:\",\n\t\t(process.cpuUsage().user / 1000000).toFixed(2),\n\t\t\"ms Cpu System:\",\n\t\t(process.cpuUsage().system / 1000000).toFixed(2),\n\t\t\"ms of\",\n\t\tcpus().length,\n\t\t\"cores\",\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAA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,MAAM,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAChD,OAAO,EACP,IAAA,cAAI,GAAE,CAAC,MAAM,EACb,OAAO,CACP,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,GAAW,EAAE,QAAkB;IAC9D,OAAO,kBAAkB,GAAG,SAAS,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,wBAAwB,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC;AACjH,CAAC"}
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/extractors.ts"],
|
|
4
|
-
"sourcesContent": ["import { Block, SetOfBlocks } from \"gettext-merger\";\n\n/**\n * Returns the key of an object based on its value\n *\n * @param object the object that contains the key\n * @param value the key that we want to get\n * @return {Record<string, string>} the filtered keys\n */\nexport function getKeyByValue(\n\tobject: Record<string, unknown>,\n\tvalue: string,\n): string | undefined {\n\treturn Object.keys(object).find((key) => object[key] === value) ?? undefined;\n}\n\n/**\n * Returns a gettext translation object\n *\n * @param label the label of the translation\n * @param string the string of the translation\n * @param filePath the file path of the translation\n */\nexport const buildBlock = (\n\tlabel: string,\n\tstring: string,\n\tfilePath: string[] | undefined = undefined,\n): Block => {\n\tconst block = new Block([]);\n\tblock.msgctxt = undefined;\n\tblock.msgid = string;\n\tblock.msgid_plural = \"\";\n\tblock.msgstr = [];\n\tblock.comments = {};\n\tif (label) {\n\t\tblock.comments.extracted = [label];\n\t}\n\tif (filePath?.length) {\n\t\tblock.comments.reference = filePath;\n\t}\n\treturn block;\n};\n\n/**\n * Extracts strings from parsed JSON data.\n *\n * @param {Record<string, any> | Parser.SyntaxNode} parsed - The parsed JSON data or syntax node.\n * @param {string | Parser} filename - The filename or parser.\n * @param filepath - the path to the file being parsed\n * @return {SetOfBlocks} An array of translation strings.\n */\nexport function yieldParsedData(\n\tparsed: Block[],\n\tfilename: \"block.json\" | \"theme.json\",\n\tfilepath: string,\n): SetOfBlocks {\n\tconst gettextTranslations: SetOfBlocks = new SetOfBlocks([], filepath);\n\n\tif (parsed.length === 0) {\n\t\treturn gettextTranslations;\n\t}\n\n\t// set the path of the translation\n\tgettextTranslations.path = filepath;\n\n\tfor (const item of parsed) {\n\t\tconst block = buildBlock(\n\t\t\titem.msgid,\n\t\t\titem.msgctxt as string,\n\t\t\titem.comments?.reference,\n\t\t);\n\n\t\tif (block) {\n\t\t\tgettextTranslations.blocks.push(block);\n\t\t}\n\t}\n\n\treturn gettextTranslations;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmC;AAS5B,SAAS,cACf,QACA,OACqB;AACrB,SAAO,OAAO,KAAK,MAAM,EAAE,KAAK,CAAC,QAAQ,OAAO,GAAG,MAAM,KAAK,KAAK;AACpE;AASO,MAAM,aAAa,CACzB,OACA,QACA,WAAiC,WACtB;AACX,QAAM,QAAQ,IAAI,4BAAM,CAAC,CAAC;AAC1B,QAAM,UAAU;AAChB,QAAM,QAAQ;AACd,QAAM,eAAe;AACrB,QAAM,SAAS,CAAC;AAChB,QAAM,WAAW,CAAC;AAClB,MAAI,OAAO;AACV,UAAM,SAAS,YAAY,CAAC,KAAK;AAAA,EAClC;AACA,MAAI,UAAU,QAAQ;AACrB,UAAM,SAAS,YAAY;AAAA,EAC5B;AACA,SAAO;AACR;AAUO,SAAS,gBACf,QACA,UACA,UACc;AACd,QAAM,sBAAmC,IAAI,kCAAY,CAAC,GAAG,QAAQ;AAErE,MAAI,OAAO,WAAW,GAAG;AACxB,WAAO;AAAA,EACR;AAGA,sBAAoB,OAAO;AAE3B,aAAW,QAAQ,QAAQ;AAC1B,UAAM,QAAQ;AAAA,MACb,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,UAAU;AAAA,IAChB;AAEA,QAAI,OAAO;AACV,0BAA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EAAE,EAAE,QAAQ,CAAC,CAAC;IAEvE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,mBAAmB,CAAC;IAC5B,CAAC;IAED,kCAAkC;IAClC,mBAAmB,CAAC,IAAI,GAAG,QAAQ,CAAC;IAEpC,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,IAAA,kBAAU,EACvB,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,OAAiB,EACtB,IAAI,CAAC,QAAQ,EAAE,SAAS,CACxB,CAAC;QAEF,IAAI,KAAK,EAAE,CAAC;YACX,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;IACF,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var p=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var l=(t,n)=>{for(var r in n)i(t,r,{get:n[r],enumerable:!0})},g=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of c(n))!u.call(t,s)&&s!==r&&i(t,s,{get:()=>n[s],enumerable:!(o=m(n,s))||o.enumerable});return t};var a=(t,n,r)=>(r=t!=null?p(f(t)):{},g(n||!t||!t.__esModule?i(r,"default",{value:t,enumerable:!0}):r,t)),y=t=>g(i({},"__esModule",{value:!0}),t);var d={};l(d,{outputJson:()=>S});module.exports=y(d);var e=a(require("tannin"));function S(t,n,r){const o={[t.slug]:{"":n??{},...r.toJson()}};return new e.default(o).toString()}0&&(module.exports={outputJson});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/utils/output.ts"],"names":[],"mappings":";;;;;AAYA,gCAgBC;AA3BD,oDAA4B;AAG5B;;;;;;;GAOG;AACH,SAAgB,UAAU,CACzB,IAAU,EACV,SAAwC,EACxC,iBAA8B;IAE9B,MAAM,OAAO,GAET;QACH,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACZ,EAAE,EAAE,SAAS,IAAI,EAAE;YACnB,GAAI,iBAAiB,CAAC,MAAM,EAAwC;SACpE;KACD,CAAC;IACF,MAAM,IAAI,GAAG,IAAI,gBAAM,CAAC,OAAO,CAAC,CAAC;IAEjC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-blocks/make-pot",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"license": "GPL-3.0-or-later",
|
|
5
5
|
"homepage": "https://wp-blocks.github.io/make-pot/",
|
|
6
6
|
"description": "A Node.js script for generating a POT file from source code",
|
|
@@ -47,27 +47,29 @@
|
|
|
47
47
|
],
|
|
48
48
|
"scripts": {
|
|
49
49
|
"postinstall": "npm rebuild tree-sitter tree-sitter-typescript tree-sitter-php tree-sitter-javascript --force",
|
|
50
|
-
"build": "npx esbuild ./src/**/* --format=cjs --minify --outdir=lib --platform=node",
|
|
50
|
+
"build": "npx esbuild ./src/**/* ./src/*.ts --format=cjs --minify --outdir=lib --platform=node",
|
|
51
51
|
"watch": "tsc --watch",
|
|
52
52
|
"lint": "npx @biomejs/biome check --write src",
|
|
53
53
|
"rm": "rmdir /s /q lib",
|
|
54
54
|
"test:build": "npx esbuild ./src/**/* --format=cjs --sourcemap --outdir=lib --platform=node",
|
|
55
55
|
"test": "npm run test:build && node --test",
|
|
56
|
-
"build:build-ci": "npx esbuild ./src/index.ts --format=cjs --outdir=lib --bundle --external:tree-sitter --external:tree-sitter-typescript --external:tree-sitter-php --external:tree-sitter-javascript --platform=node",
|
|
56
|
+
"build:build-ci": "npx esbuild ./src/index.ts --format=cjs --outdir=lib --bundle --external:tree-sitter --external:tree-sitter-typescript --external:tree-sitter-php --external:tree-sitter-javascript --external:@babel/preset-typescript --platform=node",
|
|
57
57
|
"test:ci": "npm run build:build-ci && npm run test",
|
|
58
58
|
"test:watch": "node --test --watch",
|
|
59
59
|
"test:coverage": "node --test --experimental-test-coverage"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
+
"@babel/core": "^7.27.1",
|
|
63
|
+
"@babel/preset-env": "^7.27.2",
|
|
62
64
|
"cli-progress": "^3.12.0",
|
|
63
65
|
"gettext-merger": "^1.2.1",
|
|
64
66
|
"gettext-parser": "^4.0.4",
|
|
65
67
|
"glob": "^11.0.2",
|
|
66
68
|
"tannin": "^1.2.0",
|
|
67
|
-
"tree-sitter": "^0.
|
|
68
|
-
"tree-sitter-javascript": "^0.
|
|
69
|
-
"tree-sitter-php": "^0.
|
|
70
|
-
"tree-sitter-typescript": "^0.
|
|
69
|
+
"tree-sitter": "^0.21.1",
|
|
70
|
+
"tree-sitter-javascript": "^0.23.1",
|
|
71
|
+
"tree-sitter-php": "^0.23.12",
|
|
72
|
+
"tree-sitter-typescript": "^0.23.2",
|
|
71
73
|
"yargs": "^17.7.1"
|
|
72
74
|
},
|
|
73
75
|
"devDependencies": {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const { describe, it, beforeEach, before } = require("node:test");
|
|
2
|
+
const assert = require("node:assert");
|
|
3
|
+
const { StringAuditor } = require("../lib");
|
|
4
|
+
|
|
5
|
+
describe("Audit", () => {
|
|
6
|
+
it("should not find any errors", () => {
|
|
7
|
+
/** @type {Block[]} */
|
|
8
|
+
const translations = [
|
|
9
|
+
{
|
|
10
|
+
comments: {
|
|
11
|
+
reference: ["tests/fixtures/block/javascript.js:7"],
|
|
12
|
+
translator: undefined,
|
|
13
|
+
},
|
|
14
|
+
msgctxt: undefined,
|
|
15
|
+
msgid: "Simple Block",
|
|
16
|
+
msgid_plural: undefined,
|
|
17
|
+
msgstr: [""],
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const SA = new StringAuditor("plugin");
|
|
22
|
+
SA.auditStrings(translations);
|
|
23
|
+
|
|
24
|
+
assert.deepStrictEqual(SA.results, []);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should find an error", () => {
|
|
28
|
+
/** @type {Block[]} */
|
|
29
|
+
const translations = [
|
|
30
|
+
{
|
|
31
|
+
comments: {
|
|
32
|
+
reference: ["tests/fixtures/block/javascript.js:7"],
|
|
33
|
+
translator: undefined,
|
|
34
|
+
},
|
|
35
|
+
msgctxt: undefined,
|
|
36
|
+
msgid: "translation with multiple %s %S %s %s %d and no comments",
|
|
37
|
+
msgid_plural: undefined,
|
|
38
|
+
msgstr: [""],
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const SA = new StringAuditor("plugin");
|
|
43
|
+
SA.auditStrings(translations);
|
|
44
|
+
|
|
45
|
+
assert.deepStrictEqual(SA.results, [
|
|
46
|
+
'The string "translation with multiple %s %S %s %s %d and no comments" contains placeholders but has no "translators:" comment to clarify their meaning. (tests/fixtures/block/javascript.js:7)',
|
|
47
|
+
"Multiple placeholders should be ordered. (tests/fixtures/block/javascript.js:7)",
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const { describe, it } = require("node:test");
|
|
3
|
+
const assert = require("node:assert");
|
|
4
|
+
const { join, resolve } = require("node:path");
|
|
5
|
+
|
|
6
|
+
describe("MakeJson", () => {
|
|
7
|
+
describe("should return the used translations", () => {
|
|
8
|
+
it("compare js translations with pot file", async () => {
|
|
9
|
+
const { MakeJsonCommand } = await require("../lib");
|
|
10
|
+
// the current working directory
|
|
11
|
+
const path = "tests/fixtures/makejson";
|
|
12
|
+
const cwd = join(process.cwd(), path);
|
|
13
|
+
const makeJson = new MakeJsonCommand({
|
|
14
|
+
source: "",
|
|
15
|
+
destination: "",
|
|
16
|
+
paths: {
|
|
17
|
+
cwd: cwd,
|
|
18
|
+
source: cwd,
|
|
19
|
+
destination: cwd,
|
|
20
|
+
},
|
|
21
|
+
stripUnused: true,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const result = await makeJson.processFile(
|
|
25
|
+
"tests/fixtures/makejson/live-search-block-it_IT.po",
|
|
26
|
+
"tests/fixtures/makejson/script.js",
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
result["translation-revision-date"] = undefined;
|
|
30
|
+
|
|
31
|
+
assert.deepStrictEqual(result.locale_data.messages, {
|
|
32
|
+
"": {
|
|
33
|
+
domain: "messages",
|
|
34
|
+
lang: "it_IT",
|
|
35
|
+
plural_forms: "nplurals=2; plural=(n != 1);",
|
|
36
|
+
},
|
|
37
|
+
Search: ["Cerca"],
|
|
38
|
+
"Type to search…": ["Digita per cercare…"],
|
|
39
|
+
"Please add %s more characters": [
|
|
40
|
+
"Aggiungere %s altri caratteri",
|
|
41
|
+
"Aggiungere %s caratteri in più",
|
|
42
|
+
],
|
|
43
|
+
"Sorry, no results found": ["Spiacente, nessun risultato trovato"],
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("compare js translations with pot file", async () => {
|
|
48
|
+
const { MakeJsonCommand } = await require("../lib");
|
|
49
|
+
// the current working directory
|
|
50
|
+
const path = "tests/fixtures/makejson-2";
|
|
51
|
+
const cwd = join(process.cwd(), path);
|
|
52
|
+
const makeJson = new MakeJsonCommand({
|
|
53
|
+
source: "",
|
|
54
|
+
destination: "",
|
|
55
|
+
paths: {
|
|
56
|
+
cwd: cwd,
|
|
57
|
+
source: cwd,
|
|
58
|
+
destination: cwd,
|
|
59
|
+
},
|
|
60
|
+
stripUnused: true,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const result = await makeJson.processFile(
|
|
64
|
+
"tests/fixtures/makejson-2/plugin2-it_IT.po",
|
|
65
|
+
"tests/fixtures/makejson-2/unminified.js",
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
result["translation-revision-date"] = undefined;
|
|
69
|
+
|
|
70
|
+
assert.deepStrictEqual(result.locale_data.messages, {
|
|
71
|
+
"": {
|
|
72
|
+
domain: "messages",
|
|
73
|
+
lang: "it_IT",
|
|
74
|
+
plural_forms: "nplurals=2; plural=(n != 1);",
|
|
75
|
+
},
|
|
76
|
+
"Grid view": ["Vista a griglia"],
|
|
77
|
+
"List view": ["Visualizzazione elenco"],
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
package/tests/extract.test.js
CHANGED
|
@@ -58,6 +58,44 @@ describe("getStrings", () => {
|
|
|
58
58
|
assert.deepStrictEqual(result.blocks[0].toJson(), expected.toJson());
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
+
it("should extract translations from blade", () => {
|
|
62
|
+
const content = `<h1>{{ __('Hello World', 'greeting') }}</h1>`;
|
|
63
|
+
|
|
64
|
+
const filename = "filename.blade.php";
|
|
65
|
+
|
|
66
|
+
const result = doTree(content, filename);
|
|
67
|
+
|
|
68
|
+
const expected = new Block([]);
|
|
69
|
+
expected.msgid = "Hello World";
|
|
70
|
+
expected.msgstr = [""];
|
|
71
|
+
expected.comments = {
|
|
72
|
+
reference: ["filename.blade.php:1"],
|
|
73
|
+
translator: [""],
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
assert.deepStrictEqual(result.blocks[0].toJson(), expected.toJson());
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should extract translations from blade @php block", () => {
|
|
80
|
+
const content = `@php
|
|
81
|
+
$greeting = __('Hello World', 'greeting');
|
|
82
|
+
@endphp`;
|
|
83
|
+
|
|
84
|
+
const filename = "filename.blade.php";
|
|
85
|
+
|
|
86
|
+
const result = doTree(content, filename);
|
|
87
|
+
|
|
88
|
+
const expected = new Block([]);
|
|
89
|
+
expected.msgid = "Hello World";
|
|
90
|
+
expected.msgstr = [""];
|
|
91
|
+
expected.comments = {
|
|
92
|
+
reference: ["filename.blade.php:2"],
|
|
93
|
+
translator: [""],
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
assert.deepStrictEqual(result.blocks[0].toJson(), expected.toJson());
|
|
97
|
+
});
|
|
98
|
+
|
|
61
99
|
it("should extract translations with context", () => {
|
|
62
100
|
const content = `<?php __('Hello World', 'greeting'); ?>`;
|
|
63
101
|
const filename = "filename.php";
|
|
@@ -34,24 +34,24 @@ describe("Header generation", () => {
|
|
|
34
34
|
|
|
35
35
|
it("from package.json data", async () => {
|
|
36
36
|
const expected = {
|
|
37
|
-
"Project-Id-Version": "
|
|
38
|
-
"Report-Msgid-Bugs-To": "
|
|
37
|
+
"Project-Id-Version": "My Plugin Name 1.0.0",
|
|
38
|
+
"Report-Msgid-Bugs-To": "https://wordpress.org/support/plugins/plugin",
|
|
39
39
|
"MIME-Version": "1.0",
|
|
40
40
|
"Content-Transfer-Encoding": "8bit",
|
|
41
41
|
"content-type": "text/plain; charset=iso-8859-1",
|
|
42
42
|
"plural-forms": "nplurals=2; plural=(n!=1);",
|
|
43
|
-
"POT-Creation-Date": undefined,
|
|
44
|
-
"PO-Revision-Date": undefined,
|
|
43
|
+
"POT-Creation-Date": undefined, // because the date is going to change every test
|
|
44
|
+
"PO-Revision-Date": undefined, // because the date is going to change every test
|
|
45
45
|
"Last-Translator": "John Doe <bbb@ccc.ddd>",
|
|
46
46
|
"Language-Team": "John Doe <bbb@ccc.ddd>",
|
|
47
|
-
"X-Generator":
|
|
47
|
+
"X-Generator": undefined, // because the version changes
|
|
48
48
|
Language: "en",
|
|
49
49
|
"X-Domain": "plugin",
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
const result = await generateHeader({
|
|
53
53
|
headers: {
|
|
54
|
-
name: "
|
|
54
|
+
name: "My Plugin Name",
|
|
55
55
|
author: "John Doe",
|
|
56
56
|
version: "1.0.0",
|
|
57
57
|
license: "MIT",
|
|
@@ -67,6 +67,7 @@ describe("Header generation", () => {
|
|
|
67
67
|
// remove the date "POT-Creation-Date"
|
|
68
68
|
result["POT-Creation-Date"] = undefined;
|
|
69
69
|
result["PO-Revision-Date"] = undefined;
|
|
70
|
+
result["X-Generator"] = undefined;
|
|
70
71
|
|
|
71
72
|
assert.deepStrictEqual(result, expected);
|
|
72
73
|
});
|
package/tests/tree.test.js
CHANGED
|
@@ -156,3 +156,24 @@ describe("doTree php test file", async () => {
|
|
|
156
156
|
assert.strictEqual(r.filter((block) => block.comments).length, 11);
|
|
157
157
|
});
|
|
158
158
|
});
|
|
159
|
+
|
|
160
|
+
describe("doTree large file", () => {
|
|
161
|
+
const filepath = "tests/fixtures/php.php";
|
|
162
|
+
const filePath = path.join(process.cwd(), filepath);
|
|
163
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
164
|
+
it("should parse and extract strings from large files", () => {
|
|
165
|
+
let content = fileContent;
|
|
166
|
+
|
|
167
|
+
// Duplicate content to go over 32 kb
|
|
168
|
+
while (content.length < 1024 * 32) {
|
|
169
|
+
content += fileContent;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const filename = "filename.php";
|
|
173
|
+
|
|
174
|
+
const r = doTree(content, filename).blocks;
|
|
175
|
+
|
|
176
|
+
assert.strictEqual(r.map((block) => block).length, 19);
|
|
177
|
+
assert.strictEqual(r.filter((block) => block.comments).length, 19);
|
|
178
|
+
});
|
|
179
|
+
});
|