@open-xchange/vite-plugin-i18next-gettext 1.3.0 → 1.4.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 +9 -1
- package/LICENSE +21 -0
- package/README.md +7 -7
- package/dist/index.d.ts +9 -10
- package/dist/index.js +20 -20
- package/package.json +20 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## `1.4.0` – 2026-Mar-13
|
|
4
|
+
|
|
5
|
+
- added: support for Vite 8
|
|
6
|
+
|
|
7
|
+
## `1.3.1` – 2025-Sep-29
|
|
8
|
+
|
|
9
|
+
- chore: bump dependencies
|
|
10
|
+
|
|
3
11
|
## `1.3.0` – 2025-Sep-23
|
|
4
12
|
|
|
5
13
|
- changed: placeholder in output files changed from `$NAMESPACE` to `[NAMESPACE]`
|
|
@@ -27,7 +35,7 @@
|
|
|
27
35
|
|
|
28
36
|
## `1.0.3` – 2025-May-05
|
|
29
37
|
|
|
30
|
-
- chore: use
|
|
38
|
+
- chore: use '@open-xchange/i18next-po-parser' to generate POT file
|
|
31
39
|
|
|
32
40
|
## `1.0.2` – 2025-Feb-24
|
|
33
41
|
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Open-Xchange GmbH, Germany <info@open-xchange.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -17,8 +17,8 @@ Add the plugin to your Vite configuration:
|
|
|
17
17
|
```ts
|
|
18
18
|
// vite.config.ts
|
|
19
19
|
|
|
20
|
-
import { defineConfig } from
|
|
21
|
-
import i18nextPlugin from
|
|
20
|
+
import { defineConfig } from 'vite' // or 'vitest/config'
|
|
21
|
+
import i18nextPlugin from '@open-xchange/vite-plugin-i18next-gettext'
|
|
22
22
|
|
|
23
23
|
export default defineConfig(() => {
|
|
24
24
|
|
|
@@ -28,10 +28,10 @@ export default defineConfig(() => {
|
|
|
28
28
|
// ...
|
|
29
29
|
|
|
30
30
|
i18nextPlugin({
|
|
31
|
-
poFiles:
|
|
32
|
-
srcFiles:
|
|
33
|
-
potFile:
|
|
34
|
-
projectName:
|
|
31
|
+
poFiles: 'i18n/*.po',
|
|
32
|
+
srcFiles: 'src/**/*.{js,jsx,ts,tsx}',
|
|
33
|
+
potFile: 'dist/[NAMESPACE].pot',
|
|
34
|
+
projectName: 'My Project',
|
|
35
35
|
}),
|
|
36
36
|
],
|
|
37
37
|
})
|
|
@@ -44,4 +44,4 @@ export default defineConfig(() => {
|
|
|
44
44
|
| `poFiles` | `string\|string[]` | _required_ | Glob pattern(s) for all PO files containing the translations. |
|
|
45
45
|
| `srcFiles` | `string\|string[]` | _required_ | Glob pattern(s) for all source files to be scanned for UI strings. |
|
|
46
46
|
| `potFile` | `string` | _required_ | Path to the POT files to be generated when building the project, relative to the build output directory. Should contain the placeholder `[NAMESPACE]` if the project contains translation strings in different i18next namespaces. |
|
|
47
|
-
| `projectName` | `string` | _required_ | The project name to be inserted into the POT file under the key
|
|
47
|
+
| `projectName` | `string` | _required_ | The project name to be inserted into the POT file under the key 'Project-Id-Version'. May contain the placeholder `[NAMESPACE]` |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Plugin } from 'vite';
|
|
2
2
|
/**
|
|
3
|
-
* Configuration options for the plugin
|
|
3
|
+
* Configuration options for the plugin '@open-xchange/vite-plugin-i18next-gettext'.
|
|
4
4
|
*/
|
|
5
5
|
export interface VitePluginI18nextGettextOptions {
|
|
6
6
|
/**
|
|
@@ -8,7 +8,7 @@ export interface VitePluginI18nextGettextOptions {
|
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* {
|
|
11
|
-
* poFiles:
|
|
11
|
+
* poFiles: 'i18n/*.po',
|
|
12
12
|
* // ...
|
|
13
13
|
* }
|
|
14
14
|
*/
|
|
@@ -18,27 +18,26 @@ export interface VitePluginI18nextGettextOptions {
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* {
|
|
21
|
-
* srcFiles:
|
|
21
|
+
* srcFiles: 'src/*.{js,ts}',
|
|
22
22
|
* // ...
|
|
23
23
|
* }
|
|
24
24
|
*/
|
|
25
25
|
srcFiles: string | string[];
|
|
26
26
|
/**
|
|
27
|
-
* Path to the POT files generated when building the project, relative to
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* namespaces.
|
|
27
|
+
* Path to the POT files generated when building the project, relative to the
|
|
28
|
+
* build output directory. Should contain the placeholder `[NAMESPACE]` if
|
|
29
|
+
* the project contains translation strings in different i18next namespaces.
|
|
31
30
|
*
|
|
32
31
|
* @example
|
|
33
32
|
* {
|
|
34
|
-
* potFile:
|
|
33
|
+
* potFile: 'i18n/[NAMESPACE].pot',
|
|
35
34
|
* // ...
|
|
36
35
|
* }
|
|
37
36
|
*/
|
|
38
37
|
potFile: string;
|
|
39
38
|
/**
|
|
40
39
|
* The project name to be inserted into the POT files under the key
|
|
41
|
-
*
|
|
40
|
+
* 'Project-Id-Version'. May contain the placeholder `[NAMESPACE]`.
|
|
42
41
|
*/
|
|
43
42
|
projectName: string;
|
|
44
43
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { sep, relative, posix } from
|
|
2
|
-
import { readFile } from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { sep, relative, posix } from 'node:path';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { version } from 'vite';
|
|
4
|
+
import pm from 'picomatch';
|
|
5
|
+
import converter from 'gettext-converter';
|
|
6
|
+
import { parseSourceFiles } from '@open-xchange/i18next-po-parser';
|
|
6
7
|
// constants ==================================================================
|
|
7
|
-
export const PROJECT_NAME =
|
|
8
|
+
export const PROJECT_NAME = '@open-xchange/vite-plugin-i18next-gettext';
|
|
9
|
+
const VITE_VERSION = parseInt(version.split('.')[0], 10);
|
|
8
10
|
// plugin =====================================================================
|
|
9
11
|
/**
|
|
10
12
|
* Vite plugin for using i18next with gettext `.po` files under the hood.
|
|
@@ -20,11 +22,9 @@ export default function vitePluginI18nextGettext(options) {
|
|
|
20
22
|
name: PROJECT_NAME,
|
|
21
23
|
// register esbuild loader for PO files (load as plain text)
|
|
22
24
|
config: () => ({
|
|
23
|
-
optimizeDeps:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
},
|
|
25
|
+
optimizeDeps: (VITE_VERSION >= 8) ?
|
|
26
|
+
{ rolldownOptions: { moduleTypes: { '.po': 'text' } } } :
|
|
27
|
+
{ esbuildOptions: { loader: { '.po': 'text' } } },
|
|
28
28
|
}),
|
|
29
29
|
// convert PO files to i18next JSON v4
|
|
30
30
|
async load(id) {
|
|
@@ -33,24 +33,24 @@ export default function vitePluginI18nextGettext(options) {
|
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
// read the PO file and convert it to i18next JSON
|
|
36
|
-
const data = await readFile(id, { encoding:
|
|
37
|
-
const json = converter.po2i18next(data, { compatibilityJSON:
|
|
36
|
+
const data = await readFile(id, { encoding: 'utf8' });
|
|
37
|
+
const json = converter.po2i18next(data, { compatibilityJSON: 'v4' });
|
|
38
38
|
// generate a module that exports a _stringified_ JSON object
|
|
39
|
-
const code = `export default ${JSON.stringify(json)}
|
|
40
|
-
return { code, map: { mappings:
|
|
39
|
+
const code = `export default ${JSON.stringify(json)}`;
|
|
40
|
+
return { code, map: { mappings: '' } };
|
|
41
41
|
},
|
|
42
42
|
// parse source files and create POT files per namespace
|
|
43
43
|
async generateBundle() {
|
|
44
44
|
// parse all source files, extract translations, collect into POT catalogs
|
|
45
|
-
const catalogs = await
|
|
45
|
+
const catalogs = await parseSourceFiles({ project: options.projectName, files: options.srcFiles });
|
|
46
46
|
// warn when writing multiple POT files to same file location
|
|
47
|
-
if ((catalogs.size > 1) && !options.potFile.includes(
|
|
48
|
-
this.
|
|
47
|
+
if ((catalogs.size > 1) && !options.potFile.includes('[NAMESPACE]')) {
|
|
48
|
+
this.error('multiple POT files written to same file location (missing placeholder `[NAMESPACE]` in option potFile)');
|
|
49
49
|
}
|
|
50
50
|
// add all POT files as assets to the bundle
|
|
51
51
|
for (const [namespace, source] of catalogs) {
|
|
52
|
-
const fileName = options.potFile.replaceAll(
|
|
53
|
-
this.emitFile({ type:
|
|
52
|
+
const fileName = options.potFile.replaceAll('[NAMESPACE]', namespace);
|
|
53
|
+
this.emitFile({ type: 'asset', fileName, source });
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/vite-plugin-i18next-gettext",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Vite integration of i18next using gettext",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,34 +11,36 @@
|
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=20.18"
|
|
13
13
|
},
|
|
14
|
-
"packageManager": "yarn@4.9.4",
|
|
15
14
|
"type": "module",
|
|
16
15
|
"exports": "./dist/index.js",
|
|
17
16
|
"files": [
|
|
18
17
|
"dist",
|
|
19
18
|
"CHANGELOG.*"
|
|
20
19
|
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"prepack": "yarn build && yarn lint",
|
|
23
|
-
"clean": "premove dist",
|
|
24
|
-
"build": "yarn clean && tsc --project src/tsconfig.json",
|
|
25
|
-
"lint": "tsc && tsc --project src/tsconfig.json --noEmit && eslint ."
|
|
26
|
-
},
|
|
27
20
|
"dependencies": {
|
|
28
|
-
"@open-xchange/i18next-po-parser": "^1.
|
|
29
|
-
"gettext-converter": "^1.3.
|
|
21
|
+
"@open-xchange/i18next-po-parser": "^1.2.3",
|
|
22
|
+
"gettext-converter": "^1.3.1",
|
|
30
23
|
"picomatch": "^4.0.3"
|
|
31
24
|
},
|
|
32
25
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
26
|
+
"@types/picomatch": "^4.0.2",
|
|
27
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
28
|
+
"vite": "^8.0.0",
|
|
29
|
+
"vite-v6": "npm:vite@^6.4.1",
|
|
30
|
+
"vite-v7": "npm:vite@^7.3.1",
|
|
31
|
+
"vite-v8": "npm:vite@^8.0.0",
|
|
32
|
+
"vitest": "^4.1.0",
|
|
33
|
+
"@open-xchange/vitest-vite-plugin-utils": "^0.0.1",
|
|
34
|
+
"@open-xchange/linter-presets": "^1.18.4"
|
|
40
35
|
},
|
|
41
36
|
"peerDependencies": {
|
|
42
|
-
"vite": "^6.0.0 || ^7.0.0"
|
|
37
|
+
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "pnpm clean && tsc --project src/tsconfig.json",
|
|
41
|
+
"clean": "premove dist",
|
|
42
|
+
"coverage": "vitest run --coverage",
|
|
43
|
+
"lint": "tsc && tsc --project src/tsconfig.json --noEmit && eslint .",
|
|
44
|
+
"test": "vitest run"
|
|
43
45
|
}
|
|
44
46
|
}
|