@open-xchange/vite-plugin-i18next-gettext 0.0.1 → 0.0.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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +2 -45
- package/dist/index.js +3 -7
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2] - 2024-07-26
|
|
4
|
+
|
|
5
|
+
- fix: match po files against relative module path
|
|
6
|
+
- docs: mention `i18next-plugin-pofile-backend` package
|
|
7
|
+
- chore: remove old license headers
|
|
8
|
+
- chore: bump deps
|
|
9
|
+
|
|
3
10
|
## [0.0.1] - 2024-07-26
|
|
4
11
|
|
|
5
12
|
- initial release
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 OX Software 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
|
@@ -8,6 +8,8 @@ This plugin has the following responsibilities:
|
|
|
8
8
|
- When building the project, `.po` files will be converted to and written as i18next-compatible JSON files into the bundle.
|
|
9
9
|
- When building the project, the source code will be scanned for translation strings (`t` function calls), and a `.pot` file containing all strings will be generated into the output directory.
|
|
10
10
|
|
|
11
|
+
This plugin is designed to work together with the i18next plugin `@open-xchange/i18next-plugin-pofile-backend` that will load the `.po` files into the i18next instance.
|
|
12
|
+
|
|
11
13
|
## Usage
|
|
12
14
|
|
|
13
15
|
### Vite
|
|
@@ -45,48 +47,3 @@ export default defineConfig(() => {
|
|
|
45
47
|
| `srcFiles` | `string\|string[]` | _required_ | Glob pattern(s) for all source files to be scanned for UI strings. |
|
|
46
48
|
| `potFile` | `string` | _required_ | Path to the `.pot` file to be generated when building the project, relative to the build output directory. |
|
|
47
49
|
| `projectName` | `string` | _required_ | The project name to be inserted into the `.pot` file under the key "Project-Id-Version". |
|
|
48
|
-
|
|
49
|
-
### Source Code
|
|
50
|
-
|
|
51
|
-
Import the `.po` files directly when setting up i18next, for example:
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
// src/@types/globals.d.ts
|
|
55
|
-
|
|
56
|
-
declare module "*.po" {
|
|
57
|
-
import { ResourceKey } from "i18next"
|
|
58
|
-
const resource: ResourceKey
|
|
59
|
-
export default resource
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
// src/hooks/useTranslation.ts
|
|
65
|
-
|
|
66
|
-
import i18next from "i18next"
|
|
67
|
-
import type { BackendModule, ReadCallback } from "i18next"
|
|
68
|
-
|
|
69
|
-
class POFileBackend implements BackendModule {
|
|
70
|
-
|
|
71
|
-
// type needs to be provided statically (expected by i18next runtime), and as instance prop (for typings only)
|
|
72
|
-
static readonly type = "backend"
|
|
73
|
-
readonly type = "backend"
|
|
74
|
-
|
|
75
|
-
init(): void {
|
|
76
|
-
// nothing to do
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async read(lang: string, _ns: string, cb: ReadCallback): Promise<void> {
|
|
80
|
-
try {
|
|
81
|
-
const module = await import(`./i18n/${lang}.po`) as typeof import("*.po")
|
|
82
|
-
cb(null, module.default)
|
|
83
|
-
} catch (error) {
|
|
84
|
-
cb(error as Error, null)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
i18next.use(POFileBackend)
|
|
90
|
-
|
|
91
|
-
export default useTranslation
|
|
92
|
-
```
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright (C) Open-Xchange GmbH, Germany <info@open-xchange.com>
|
|
3
|
-
*
|
|
4
|
-
* This program is proprietary software and licensed to you under Open-Xchange
|
|
5
|
-
* GmbH's Software License Agreement.
|
|
6
|
-
*/
|
|
1
|
+
import { sep, relative, posix } from "node:path";
|
|
7
2
|
import { readFile } from "node:fs/promises";
|
|
8
3
|
import pm from "picomatch";
|
|
9
4
|
import converter from "gettext-converter";
|
|
@@ -34,7 +29,8 @@ export default function vitePluginI18nextGettext(options) {
|
|
|
34
29
|
}),
|
|
35
30
|
// convert `.po` files to i18next JSON v4
|
|
36
31
|
async load(id) {
|
|
37
|
-
|
|
32
|
+
const relPath = relative(process.cwd(), id).replaceAll(sep, posix.sep);
|
|
33
|
+
if (!pm.isMatch(relPath, options.poFiles)) {
|
|
38
34
|
return;
|
|
39
35
|
}
|
|
40
36
|
// read the `.po` file and convert it to i18next JSON
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/vite-plugin-i18next-gettext",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Vite integration of i18next using gettext",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://gitlab.open-xchange.com/fspd/npm-packages/vite-plugin-i18next-gettext"
|
|
@@ -21,8 +21,14 @@
|
|
|
21
21
|
"lint-staged": {
|
|
22
22
|
"*.{js,ts,json}": "yarn lint"
|
|
23
23
|
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"gettext-converter": "1.3.0",
|
|
26
|
+
"i18next-parser": "9.0.0",
|
|
27
|
+
"picomatch": "4.0.2",
|
|
28
|
+
"vinyl-fs": "4.0.0"
|
|
29
|
+
},
|
|
24
30
|
"devDependencies": {
|
|
25
|
-
"@open-xchange/linter-presets": "0.1.
|
|
31
|
+
"@open-xchange/linter-presets": "0.1.10",
|
|
26
32
|
"@types/node": "20.14.12",
|
|
27
33
|
"@types/vinyl-fs": "3.0.5",
|
|
28
34
|
"eslint": "9.7.0",
|
|
@@ -36,11 +42,5 @@
|
|
|
36
42
|
},
|
|
37
43
|
"resolutions": {
|
|
38
44
|
"semver": "^7.6.2"
|
|
39
|
-
},
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"gettext-converter": "1.3.0",
|
|
42
|
-
"i18next-parser": "9.0.0",
|
|
43
|
-
"picomatch": "4.0.2",
|
|
44
|
-
"vinyl-fs": "4.0.0"
|
|
45
45
|
}
|
|
46
46
|
}
|