@open-xchange/rolldown-plugin-i18next-gettext 0.0.1 → 1.0.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/CHANGELOG.md +4 -0
- package/README.md +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +16 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -6
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;AAaA;UAAiB,mCAAA;;;;;;;;EASf,OAAA;EA8Ba;AASf;;;EAjCE,QAAA;IAiCuB;AAMzB;;;;;IA/BI,QAAA;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;AAaA;UAAiB,mCAAA;;;;;;;;EASf,OAAA;EA8Ba;AASf;;;EAjCE,QAAA;IAiCuB;AAMzB;;;;;IA/BI,QAAA;IA4CgD;;;;;;;;IAlChD,UAAA;;;;;IAMA,WAAA;EAAA;AAAA;;;;cASS,YAAA;;;;;cAMA,iBAAA;;;;;;;;;;iBAaW,4BAAA,CAA6B,OAAA,EAAS,mCAAA,GAAsC,MAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
|
-
import
|
|
2
|
+
import { createJsonModule, exactRegex, wrapArray } from "@open-xchange/rolldown-utils";
|
|
3
3
|
import { glob } from "tinyglobby";
|
|
4
4
|
import { parsePoFile, parseSourceFiles } from "@open-xchange/i18next-po-parser";
|
|
5
5
|
//#region src/index.ts
|
|
@@ -13,22 +13,6 @@ const PROJECT_NAME = "@open-xchange/rolldown-plugin-i18next-gettext";
|
|
|
13
13
|
*/
|
|
14
14
|
const VIRTUAL_MODULE_ID = "virtual:i18next-po-catalogs";
|
|
15
15
|
/**
|
|
16
|
-
* Creates the source code of a module with a default export with the passed
|
|
17
|
-
* stringified JSON data.
|
|
18
|
-
*
|
|
19
|
-
* @param json
|
|
20
|
-
* The JSON data to be exported from the generated source file.
|
|
21
|
-
*
|
|
22
|
-
* @returns
|
|
23
|
-
* The generated source file.
|
|
24
|
-
*/
|
|
25
|
-
function createModule(json) {
|
|
26
|
-
return {
|
|
27
|
-
code: `export default ${JSON.stringify(json)}`,
|
|
28
|
-
map: { mappings: "" }
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
16
|
* Rolldown plugin for using i18next with gettext `.po` files under the hood.
|
|
33
17
|
*
|
|
34
18
|
* @param options
|
|
@@ -41,21 +25,24 @@ function rolldownPluginI18nextGettext(options) {
|
|
|
41
25
|
const RESOLVED_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
|
|
42
26
|
return {
|
|
43
27
|
name: PROJECT_NAME,
|
|
44
|
-
resolveId
|
|
45
|
-
|
|
28
|
+
resolveId: {
|
|
29
|
+
filter: { id: exactRegex(VIRTUAL_MODULE_ID) },
|
|
30
|
+
handler: () => RESOLVED_MODULE_ID
|
|
46
31
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
map
|
|
32
|
+
load: {
|
|
33
|
+
filter: { id: [exactRegex(RESOLVED_MODULE_ID), ...wrapArray(options.poFiles)] },
|
|
34
|
+
async handler(id) {
|
|
35
|
+
console.log(id);
|
|
36
|
+
if (id === RESOLVED_MODULE_ID) {
|
|
37
|
+
const map = {};
|
|
38
|
+
for (const entry of await glob(options.poFiles)) {
|
|
39
|
+
const basename = path.parse(entry).name;
|
|
40
|
+
map[basename] = await parsePoFile(entry);
|
|
41
|
+
}
|
|
42
|
+
return createJsonModule(map);
|
|
53
43
|
}
|
|
54
|
-
return
|
|
44
|
+
return createJsonModule(await parsePoFile(id));
|
|
55
45
|
}
|
|
56
|
-
const relPath = path.relative(process.cwd(), id).replaceAll(path.sep, path.posix.sep);
|
|
57
|
-
if (!pm.isMatch(relPath, options.poFiles)) return;
|
|
58
|
-
return createModule(await parsePoFile(id));
|
|
59
46
|
},
|
|
60
47
|
async generateBundle() {
|
|
61
48
|
if (!options.potFiles) return;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["\nimport * as path from 'node:path'\n\nimport type {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["\nimport * as path from 'node:path'\n\nimport type { Plugin } from 'rolldown'\nimport { exactRegex, wrapArray, createJsonModule } from '@open-xchange/rolldown-utils'\nimport { glob } from 'tinyglobby'\nimport { parsePoFile, parseSourceFiles } from '@open-xchange/i18next-po-parser'\n\n// types ======================================================================\n\n/**\n * Configuration options for the plugin '@open-xchange/rolldown-plugin-i18next-gettext'.\n */\nexport interface RolldownPluginI18nextGettextOptions {\n\n /**\n * Glob pattern(s) for all PO files containing the translations. Matching PO\n * files will be converted to i18next translation catalogs when imported in\n * source code directly, and will be included in the virtual module providing\n * a dictionary of all translation catalogs, mapped by the base names of the\n * PO files.\n */\n poFiles: string | readonly string[]\n\n /**\n * Configuration for the source code scanner and POT file generator. If\n * omitted, no POT files will be generated.\n */\n potFiles?: {\n\n /**\n * Glob pattern(s) for all source files to be scanned for UI strings.\n *\n * @default\n * 'src/**\\/*.{js,jsx,ts,tsx}'\n */\n srcFiles?: string | readonly string[]\n\n /**\n * Path to and filename of the generated POT files, relative to the build\n * output directory. Should contain the placeholder `[NAMESPACE]` if the\n * project contains translation strings in different i18next namespaces.\n *\n * @default\n * '[NAMESPACE].pot'\n */\n outputPath?: string\n\n /**\n * The project name to be inserted into the POT files under the key\n * 'Project-Id-Version'. May contain the placeholder `[NAMESPACE]`.\n */\n projectName: string\n }\n}\n\n// constants ==================================================================\n\n/**\n * Identifier of this plugin.\n */\nexport const PROJECT_NAME = '@open-xchange/rolldown-plugin-i18next-gettext'\n\n/**\n * Identifier of the virtual module providing all translation catalogs in a\n * single object.\n */\nexport const VIRTUAL_MODULE_ID = 'virtual:i18next-po-catalogs'\n\n// plugin =====================================================================\n\n/**\n * Rolldown plugin for using i18next with gettext `.po` files under the hood.\n *\n * @param options\n * Plugin configuration.\n *\n * @returns\n * The rolldown plugin object.\n */\nexport default function rolldownPluginI18nextGettext(options: RolldownPluginI18nextGettextOptions): Plugin {\n\n const RESOLVED_MODULE_ID = `\\0${VIRTUAL_MODULE_ID}`\n\n return {\n name: PROJECT_NAME,\n\n // recognize virtual module identifier\n resolveId: {\n filter: { id: exactRegex(VIRTUAL_MODULE_ID) },\n handler: () => RESOLVED_MODULE_ID,\n },\n\n // convert PO files to i18next JSON v4\n load: {\n filter: {\n id: [\n exactRegex(RESOLVED_MODULE_ID),\n ...wrapArray(options.poFiles),\n ],\n },\n async handler(id) {\n console.log(id)\n\n // virtual module: build single dictionary with all languages from PO files\n if (id === RESOLVED_MODULE_ID) {\n const map = {} as Record<string, Record<string, string>>\n for (const entry of await glob(options.poFiles)) {\n const basename = path.parse(entry).name\n map[basename] = await parsePoFile(entry)\n }\n return createJsonModule(map)\n }\n\n // read the PO file and convert it to i18next JSON\n return createJsonModule(await parsePoFile(id))\n },\n },\n\n // parse source files and create POT files per namespace\n async generateBundle() {\n\n // early exit if no POT files will be generated\n if (!options.potFiles) return\n const { srcFiles = 'src/**/*.{js,jsx,ts,tsx}', outputPath = '[NAMESPACE].pot', projectName } = options.potFiles\n\n // parse all source files and extract translations\n const catalogs = await parseSourceFiles({ files: srcFiles, project: projectName })\n\n // warn when writing multiple POT files to same file location\n if ((catalogs.size > 1) && !outputPath.includes('[NAMESPACE]')) {\n this.error('multiple POT files written to same file location (missing placeholder `[NAMESPACE]` in option potFile)')\n }\n\n // add all POT files as assets to the bundle\n for (const [namespace, source] of catalogs) {\n const fileName = outputPath.replaceAll('[NAMESPACE]', namespace)\n this.emitF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
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Rolldown integration of i18next using gettext",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,19 +25,18 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@open-xchange/i18next-po-parser": "^1.4.0",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
28
|
+
"tinyglobby": "^0.2.16",
|
|
29
|
+
"@open-xchange/rolldown-utils": "^1.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/picomatch": "^4.0.3",
|
|
33
32
|
"@vitest/coverage-v8": "^4.1.3",
|
|
34
33
|
"i18next": "^26.0.4",
|
|
35
|
-
"rolldown": "1.0.0-rc.15",
|
|
34
|
+
"rolldown": "^1.0.0-rc.15",
|
|
36
35
|
"tsdown": "^0.21.7",
|
|
37
36
|
"vitest": "^4.1.3",
|
|
38
37
|
"@open-xchange/linter-presets": "^1.22.0",
|
|
39
|
-
"@open-xchange/vitest-plugin-extended": "^1.6.0",
|
|
40
38
|
"@open-xchange/tsconfig": "^0.0.3",
|
|
39
|
+
"@open-xchange/vitest-plugin-extended": "^1.6.0",
|
|
41
40
|
"@open-xchange/vitest-plugin-utils": "^0.0.3"
|
|
42
41
|
},
|
|
43
42
|
"peerDependencies": {
|