@gjsify/vite-plugin-gettext 0.2.5 → 0.2.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/dist/msgfmt.js +27 -1
- package/dist/msgfmt.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
- package/src/msgfmt.ts +29 -0
- package/src/types.ts +2 -0
package/dist/msgfmt.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import {} from "vite";
|
|
2
2
|
import { execa } from "execa";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
4
5
|
import { checkDependencies, findAvailableLanguages, ensureDirectory, } from "./utils.js";
|
|
6
|
+
/**
|
|
7
|
+
* Remove XML comments from a file content
|
|
8
|
+
* @param content The XML content as string
|
|
9
|
+
* @returns The content with comments removed
|
|
10
|
+
*/
|
|
11
|
+
function removeXmlComments(content) {
|
|
12
|
+
// Remove XML comments <!-- ... -->
|
|
13
|
+
return content.replace(/<!--[\s\S]*?-->/g, '');
|
|
14
|
+
}
|
|
5
15
|
/**
|
|
6
16
|
* Get output file extension based on the format
|
|
7
17
|
* @param format The output format
|
|
@@ -39,7 +49,7 @@ function getOutputExtension(format) {
|
|
|
39
49
|
* @returns A Vite plugin that handles PO compilation
|
|
40
50
|
*/
|
|
41
51
|
export function msgfmtPlugin(options) {
|
|
42
|
-
const { poDirectory, outputDirectory, domain = "messages", format = "mo", templateFile, verbose = false, msgfmtOptions = [], useLocaleStructure = true, } = options;
|
|
52
|
+
const { poDirectory, outputDirectory, domain = "messages", format = "mo", templateFile, verbose = false, msgfmtOptions = [], useLocaleStructure = true, removeComments = true, } = options;
|
|
43
53
|
const pluginName = "vite-plugin-msgfmt";
|
|
44
54
|
async function compilePoFiles() {
|
|
45
55
|
try {
|
|
@@ -76,6 +86,22 @@ export function msgfmtPlugin(options) {
|
|
|
76
86
|
console.log(`[${pluginName}] Running msgfmt with: ${args.join(" ")}`);
|
|
77
87
|
}
|
|
78
88
|
await execa("msgfmt", args);
|
|
89
|
+
// Remove comments from XML output if requested
|
|
90
|
+
if (removeComments !== false) {
|
|
91
|
+
try {
|
|
92
|
+
const content = await fs.readFile(outputFile, 'utf-8');
|
|
93
|
+
const cleanedContent = removeXmlComments(content);
|
|
94
|
+
await fs.writeFile(outputFile, cleanedContent, 'utf-8');
|
|
95
|
+
if (verbose) {
|
|
96
|
+
console.log(`[${pluginName}] Removed comments from ${outputFile}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (verbose) {
|
|
101
|
+
console.warn(`[${pluginName}] Failed to remove comments: ${error}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
79
105
|
}
|
|
80
106
|
else {
|
|
81
107
|
// Find available languages for individual processing
|
package/dist/msgfmt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"msgfmt.js","sourceRoot":"","sources":["../src/msgfmt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"msgfmt.js","sourceRoot":"","sources":["../src/msgfmt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAElC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,SAAS,iBAAiB,CAAC,OAAe;IACxC,mCAAmC;IACnC,OAAO,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AACjD,CAA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AAC;oBACzB,IAAI,OAAO,EAAE,CAAC;wBACZ,OAAO,CAAC,GAAG,CACT,IAAI,UAAU,sBAAsB,IAAI,eAAe,CACxD,CAAC;oBACJ,CAAC;oBACD,MAAM,cAAc,EAAE,CAAC;gBACzB,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -81,6 +81,8 @@ export interface MsgfmtPluginOptions {
|
|
|
81
81
|
msgfmtOptions?: string[];
|
|
82
82
|
/** Whether to use the standard locale structure (locale/LANG/LC_MESSAGES/domain.mo) */
|
|
83
83
|
useLocaleStructure?: boolean;
|
|
84
|
+
/** Whether to remove XML comments from output files, defaults to true */
|
|
85
|
+
removeComments?: boolean;
|
|
84
86
|
}
|
|
85
87
|
export interface PluginOptions {
|
|
86
88
|
pluginName: string;
|
package/package.json
CHANGED
package/src/msgfmt.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Plugin } from "vite";
|
|
2
2
|
import { execa } from "execa";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
4
5
|
import type { MsgfmtPluginOptions, MsgfmtFormat } from "./types.js";
|
|
5
6
|
import {
|
|
6
7
|
checkDependencies,
|
|
@@ -8,6 +9,16 @@ import {
|
|
|
8
9
|
ensureDirectory,
|
|
9
10
|
} from "./utils.js";
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Remove XML comments from a file content
|
|
14
|
+
* @param content The XML content as string
|
|
15
|
+
* @returns The content with comments removed
|
|
16
|
+
*/
|
|
17
|
+
function removeXmlComments(content: string): string {
|
|
18
|
+
// Remove XML comments <!-- ... -->
|
|
19
|
+
return content.replace(/<!--[\s\S]*?-->/g, '');
|
|
20
|
+
}
|
|
21
|
+
|
|
11
22
|
/**
|
|
12
23
|
* Get output file extension based on the format
|
|
13
24
|
* @param format The output format
|
|
@@ -55,6 +66,7 @@ export function msgfmtPlugin(options: MsgfmtPluginOptions): Plugin {
|
|
|
55
66
|
verbose = false,
|
|
56
67
|
msgfmtOptions = [],
|
|
57
68
|
useLocaleStructure = true,
|
|
69
|
+
removeComments = true,
|
|
58
70
|
} = options;
|
|
59
71
|
|
|
60
72
|
const pluginName = "vite-plugin-msgfmt";
|
|
@@ -107,6 +119,23 @@ export function msgfmtPlugin(options: MsgfmtPluginOptions): Plugin {
|
|
|
107
119
|
}
|
|
108
120
|
|
|
109
121
|
await execa("msgfmt", args);
|
|
122
|
+
|
|
123
|
+
// Remove comments from XML output if requested
|
|
124
|
+
if (removeComments !== false) {
|
|
125
|
+
try {
|
|
126
|
+
const content = await fs.readFile(outputFile, 'utf-8');
|
|
127
|
+
const cleanedContent = removeXmlComments(content);
|
|
128
|
+
await fs.writeFile(outputFile, cleanedContent, 'utf-8');
|
|
129
|
+
|
|
130
|
+
if (verbose) {
|
|
131
|
+
console.log(`[${pluginName}] Removed comments from ${outputFile}`);
|
|
132
|
+
}
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (verbose) {
|
|
135
|
+
console.warn(`[${pluginName}] Failed to remove comments: ${error}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
110
139
|
} else {
|
|
111
140
|
// Find available languages for individual processing
|
|
112
141
|
const languages = await findAvailableLanguages(
|
package/src/types.ts
CHANGED
|
@@ -94,6 +94,8 @@ export interface MsgfmtPluginOptions {
|
|
|
94
94
|
msgfmtOptions?: string[];
|
|
95
95
|
/** Whether to use the standard locale structure (locale/LANG/LC_MESSAGES/domain.mo) */
|
|
96
96
|
useLocaleStructure?: boolean;
|
|
97
|
+
/** Whether to remove XML comments from output files, defaults to true */
|
|
98
|
+
removeComments?: boolean;
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
export interface PluginOptions {
|