rollup-plugin-gettext 0.1.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/LICENSE +18 -0
- package/README.md +67 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +132 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
- package/types.d.ts +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kisaragi Hiu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
15
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
16
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# rollup-plugin-gettext
|
|
2
|
+
|
|
3
|
+
Import PO or MO files when using Rollup or Vite, parsing translation catalogs through [gettext-parser](https://github.com/smhg/gettext-parser).
|
|
4
|
+
|
|
5
|
+
This does not handle extraction or translating at runtime.
|
|
6
|
+
|
|
7
|
+
## Config
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// vite.config.js or rollup.config.js
|
|
11
|
+
import { mo, po } from "rollup-plugin-gettext";
|
|
12
|
+
export default {
|
|
13
|
+
plugins: [mo(), po()] // order doesn't matter, pick either or both
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
// astro.config.js
|
|
19
|
+
import { mo, po } from "rollup-plugin-gettext";
|
|
20
|
+
export default {
|
|
21
|
+
vite: {
|
|
22
|
+
plugins: [mo(), po()] // order doesn't matter, pick either or both
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
To get types for the data imported with this plugin, add a `/// <reference types="rollup-plugin-gettext/types />"` to a global declaration file or to the file where you're importing them, or put `"rollup-plugin-gettext/types"` into `lib` in `tsconfig.json`.
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import de from "./locale/de.po"
|
|
33
|
+
import de from "po:./locale/de.po"
|
|
34
|
+
import de from "./locale/de.mo"
|
|
35
|
+
import de from "mo:./locale/de.mo"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
This is equivalent to `(await import("gettext-parser")).po.parse(readFileSync("./locale/de.po"))`, except Vite/Rollup will bundle the value making it usable eg. on the client side.
|
|
39
|
+
|
|
40
|
+
Note that using MO files doesn't really have a difference in performance here.
|
|
41
|
+
|
|
42
|
+
Or, more usefully:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import translations1 from "po:./dir/with/po/files"
|
|
46
|
+
import translations2 from "mo:./dir/with/mo/files"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
this will import each of the PO files in the directory, and make them available as an object with keys being their basenames without extensions, and values being `{messages: GetTextTranslations}`. (“messages” is temporary and will be removed. That's a gettext domain but it's not actually read from anything.)
|
|
50
|
+
|
|
51
|
+
The translations imported this way can be passed directly into the `@kemdict/gettext` runtime.
|
|
52
|
+
|
|
53
|
+
## Options
|
|
54
|
+
|
|
55
|
+
- po:
|
|
56
|
+
- parserOptions: options to pass to the PO file parser from `gettext-parser`.
|
|
57
|
+
|
|
58
|
+
This is a nested object *just in case* it turns out the plugin could use some other options. (Currently this just has `defaultCharset` and `validation` in it, see the docs for `gettext-parser`.)
|
|
59
|
+
|
|
60
|
+
- mo:
|
|
61
|
+
- defaultCharset: passed into the MO file parser from `gettext-parser`.
|
|
62
|
+
|
|
63
|
+
## Acknowledgements
|
|
64
|
+
|
|
65
|
+
- I referenced [@miyaneee/rollup-plugin-json5](https://github.com/Miyaneee/rollup-plugin-json5) for how a Rollup plugin like this should be structured (that plugin seems to also be based on @rollup/json)
|
|
66
|
+
- I referenced @rollup/data-uri and [rollup-plugin-glob-import](https://github.com/gjbkz/rollup-plugin-glob-import) as well as @rollup/image for how to load data
|
|
67
|
+
- https://github.com/figma/vite-plugin-yaml for how to set up types
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type GetTextPoParserOptions } from "gettext-parser";
|
|
2
|
+
import type { Plugin } from "rollup";
|
|
3
|
+
interface MoPluginOptions {
|
|
4
|
+
defaultCharset?: string;
|
|
5
|
+
}
|
|
6
|
+
interface PoPluginOptions {
|
|
7
|
+
parserOptions?: GetTextPoParserOptions;
|
|
8
|
+
}
|
|
9
|
+
export declare function po(options?: PoPluginOptions): Plugin;
|
|
10
|
+
export declare function mo(options?: MoPluginOptions): Plugin;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAIA,OAAO,EAGH,KAAK,sBAAsB,EAE9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,UAAU,eAAe;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,UAAU,eAAe;IACrB,aAAa,CAAC,EAAE,sBAAsB,CAAC;CAC1C;AAED,wBAAgB,EAAE,CAAC,OAAO,GAAE,eAAoB,GAAG,MAAM,CAyExD;AAED,wBAAgB,EAAE,CAAC,OAAO,GAAE,eAAoB,GAAG,MAAM,CAqExD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import { dataToEsm } from "@rollup/pluginutils";
|
|
4
|
+
import { po as poParser, mo as moParser, } from "gettext-parser";
|
|
5
|
+
export function po(options = {}) {
|
|
6
|
+
const parsedMap = new Map();
|
|
7
|
+
return {
|
|
8
|
+
name: "po",
|
|
9
|
+
// This is just for a directory of PO files. A single PO file gets the
|
|
10
|
+
// standard resolution.
|
|
11
|
+
resolveId: {
|
|
12
|
+
filter: { id: /^po:/ },
|
|
13
|
+
// handle prefixed directory imports and prefixed file imports
|
|
14
|
+
async handler(source, importer) {
|
|
15
|
+
if (!importer)
|
|
16
|
+
return null;
|
|
17
|
+
const fullpath = path.join(path.dirname(importer), source.slice("po:".length));
|
|
18
|
+
try {
|
|
19
|
+
// prefixed directories
|
|
20
|
+
const files = await fs.readdir(fullpath);
|
|
21
|
+
const catalogs = {};
|
|
22
|
+
for (const file of files) {
|
|
23
|
+
if (!file.endsWith(".po"))
|
|
24
|
+
continue;
|
|
25
|
+
const content = await fs.readFile(path.join(fullpath, file), {
|
|
26
|
+
encoding: "utf8",
|
|
27
|
+
});
|
|
28
|
+
const key = path.basename(file, ".po");
|
|
29
|
+
catalogs[key] = poParser.parse(content);
|
|
30
|
+
}
|
|
31
|
+
if (Object.keys(catalogs).length === 0) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
parsedMap.set(fullpath, catalogs);
|
|
35
|
+
return fullpath + "?gettext-po-dir";
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
if (e.code !== "ENOTDIR")
|
|
39
|
+
return null;
|
|
40
|
+
// prefixed files, we need to resolve this here for
|
|
41
|
+
// absolute paths
|
|
42
|
+
return fullpath + "?gettext-po-file";
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
load: {
|
|
47
|
+
filter: {
|
|
48
|
+
id: /(?:\.po|\?gettext-po-dir|\?gettext-po-file)$/,
|
|
49
|
+
},
|
|
50
|
+
async handler(id) {
|
|
51
|
+
// 3 cases:
|
|
52
|
+
const parsed = id.endsWith("?gettext-po-dir")
|
|
53
|
+
? // 1: prefixed directory imports, which would have the ID
|
|
54
|
+
// resolved like this in our resolveId
|
|
55
|
+
parsedMap.get(id.slice(0, -1 * "?gettext-po-dir".length))
|
|
56
|
+
: poParser.parse(await fs.readFile(id.endsWith("?gettext-po-file")
|
|
57
|
+
? // 2: prefixed file imports, strip the prefix
|
|
58
|
+
id.slice(0, -1 * "?gettext-po-file".length)
|
|
59
|
+
: // 3: unprefixed file imports, use the file
|
|
60
|
+
// path directly
|
|
61
|
+
id, { encoding: "utf8" }), options.parserOptions);
|
|
62
|
+
return dataToEsm(parsed, {
|
|
63
|
+
preferConst: true,
|
|
64
|
+
compact: true,
|
|
65
|
+
namedExports: false,
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function mo(options = {}) {
|
|
72
|
+
const parsedMap = new Map();
|
|
73
|
+
return {
|
|
74
|
+
name: "mo",
|
|
75
|
+
resolveId: {
|
|
76
|
+
filter: { id: /^mo:/ },
|
|
77
|
+
async handler(source, importer) {
|
|
78
|
+
if (!importer)
|
|
79
|
+
return null;
|
|
80
|
+
const fullpath = path.join(path.dirname(importer), source.slice("mo:".length));
|
|
81
|
+
try {
|
|
82
|
+
// prefixed directories
|
|
83
|
+
const files = await fs.readdir(fullpath);
|
|
84
|
+
const catalogs = {};
|
|
85
|
+
for (const file of files) {
|
|
86
|
+
if (!file.endsWith(".mo"))
|
|
87
|
+
continue;
|
|
88
|
+
const content = await fs.readFile(path.join(fullpath, file));
|
|
89
|
+
const key = path.basename(file, ".mo");
|
|
90
|
+
catalogs[key] = moParser.parse(content, options.defaultCharset);
|
|
91
|
+
}
|
|
92
|
+
if (Object.keys(catalogs).length === 0) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
parsedMap.set(fullpath, catalogs);
|
|
96
|
+
return fullpath + "?gettext-mo-dir";
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
if (e.code !== "ENOTDIR")
|
|
100
|
+
return null;
|
|
101
|
+
// prefixed files, we need to resolve this here for
|
|
102
|
+
// absolute paths
|
|
103
|
+
return fullpath + "?gettext-mo-file";
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
load: {
|
|
108
|
+
filter: {
|
|
109
|
+
id: /(?:\.mo|\?gettext-mo-dir|\?gettext-mo-file)$/,
|
|
110
|
+
},
|
|
111
|
+
async handler(id) {
|
|
112
|
+
// 3 cases:
|
|
113
|
+
const parsed = id.endsWith("?gettext-mo-dir")
|
|
114
|
+
? // 1: prefixed directory imports, which would have the ID
|
|
115
|
+
// resolved like this in our resolveId
|
|
116
|
+
parsedMap.get(id.slice(0, -1 * "?gettext-mo-dir".length))
|
|
117
|
+
: moParser.parse(await fs.readFile(id.endsWith("?gettext-mo-file")
|
|
118
|
+
? // 2: prefixed file imports, strip the prefix
|
|
119
|
+
id.slice(0, -1 * "?gettext-mo-file".length)
|
|
120
|
+
: // 3: unprefixed file imports, use the file
|
|
121
|
+
// path directly
|
|
122
|
+
id), options.defaultCharset);
|
|
123
|
+
return dataToEsm(parsed, {
|
|
124
|
+
preferConst: true,
|
|
125
|
+
compact: true,
|
|
126
|
+
namedExports: false,
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EACH,EAAE,IAAI,QAAQ,EACd,EAAE,IAAI,QAAQ,GAGjB,MAAM,gBAAgB,CAAC;AAWxB,MAAM,UAAU,EAAE,CAAC,UAA2B,EAAE;IAC5C,MAAM,SAAS,GAAG,IAAI,GAAG,EAA+C,CAAC;IACzE,OAAO;QACH,IAAI,EAAE,IAAI;QACV,sEAAsE;QACtE,uBAAuB;QACvB,SAAS,EAAE;YACP,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE;YACtB,8DAA8D;YAC9D,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ;gBAC1B,IAAI,CAAC,QAAQ;oBAAE,OAAO,IAAI,CAAC;gBAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CACtB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EACtB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAC7B,CAAC;gBACF,IAAI,CAAC;oBACD,uBAAuB;oBACvB,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;oBACzC,MAAM,QAAQ,GAAwC,EAAE,CAAC;oBACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;wBACvB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;4BAAE,SAAS;wBACpC,MAAM,OAAO,GAAG,MAAM,EAAE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C;4BAC3C,gBAAgB;4BAChB,EAAE,CACX,EACD,OAAO,CAAC,cAAc,CACzB,CAAC;gBACR,OAAO,SAAS,CAAC,MAAM,EAAE;oBACrB,WAAW,EAAE,IAAI;oBACjB,OAAO,EAAE,IAAI;oBACb,YAAY,EAAE,KAAK;iBACtB,CAAC,CAAC;YACP,CAAC;SACJ;KACJ,CAAC;AACN,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rollup-plugin-gettext",
|
|
3
|
+
"description": "Rollup loader for PO and MO files via gettext-parser",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/kemdict/gettext.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/kemdict/gettext#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/kemdict/gettext/issues"
|
|
13
|
+
},
|
|
14
|
+
"author": "Kisaragi Hiu <mail@kisaragi-hiu.com>",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"files": ["dist", "types.d.ts", "README.md", "LICENSE", "package.json"],
|
|
17
|
+
"keywords": ["rollup-plugin", "vite-plugin", "gettext"],
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./types": {
|
|
26
|
+
"types": "./types.d.ts"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"rollup": ">=4.38.0"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@rollup/pluginutils": "^5.3.0",
|
|
34
|
+
"gettext-parser": "^9.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"publint": "^0.3.17",
|
|
38
|
+
"typescript": "^5.9.3",
|
|
39
|
+
"vitest": "^4.0.18"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// The imports here cannot be top level, since that turns this file into a
|
|
2
|
+
// module and the module declarations below into module augmentations.
|
|
3
|
+
declare module "*.po" {
|
|
4
|
+
import { GetTextTranslations } from "gettext-parser";
|
|
5
|
+
const value: GetTextTranslations;
|
|
6
|
+
export default value;
|
|
7
|
+
}
|
|
8
|
+
declare module "*.mo" {
|
|
9
|
+
import { GetTextTranslations } from "gettext-parser";
|
|
10
|
+
const value: GetTextTranslations;
|
|
11
|
+
export default value;
|
|
12
|
+
}
|
|
13
|
+
// Our patterns here overlap with each other.
|
|
14
|
+
// Should "po:foo.po" match "*.po" or "po:*"?
|
|
15
|
+
// I need it to match as "*.po", but typescript favors "po:*", as it favors
|
|
16
|
+
// favors matches with longer prefixes:
|
|
17
|
+
// https://github.com/microsoft/TypeScript/blob/01c23d68b1/src/compiler/core.ts#L2410
|
|
18
|
+
//
|
|
19
|
+
// Declaring "po:*.po" here will make sure "po:foo.po" gets the single-file
|
|
20
|
+
// type. It seems that when two patterns have the same prefix length, the one
|
|
21
|
+
// that is declared first is the one that is used.
|
|
22
|
+
declare module "po:*.po" {
|
|
23
|
+
import { GetTextTranslations } from "gettext-parser";
|
|
24
|
+
const value: GetTextTranslations;
|
|
25
|
+
export default value;
|
|
26
|
+
}
|
|
27
|
+
declare module "mo:*.mo" {
|
|
28
|
+
import { GetTextTranslations } from "gettext-parser";
|
|
29
|
+
const value: GetTextTranslations;
|
|
30
|
+
export default value;
|
|
31
|
+
}
|
|
32
|
+
declare module "po:*" {
|
|
33
|
+
import { GetTextTranslations } from "gettext-parser";
|
|
34
|
+
const value: Record<string, GetTextTranslations>;
|
|
35
|
+
export default value;
|
|
36
|
+
}
|
|
37
|
+
declare module "mo:*" {
|
|
38
|
+
import { GetTextTranslations } from "gettext-parser";
|
|
39
|
+
const value: Record<string, GetTextTranslations>;
|
|
40
|
+
export default value;
|
|
41
|
+
}
|