@open-xchange/vite-plugin-i18next-gettext 1.0.3 → 1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## `1.1.0` – 2025-May-05
4
+
5
+ - added: generate separate POT files per i18next namespace
6
+
3
7
  ## `1.0.3` – 2025-May-05
4
8
 
5
9
  - chore: use "@open-xchange/i18next-po-parser" to generate POT file
@@ -30,11 +34,11 @@
30
34
 
31
35
  ## `0.0.3` – 2024-Aug-12
32
36
 
33
- - fix: bump `i18next-parser` (<https://github.com/i18next/i18next-parser/issues/1045>)
37
+ - fixed: bump `i18next-parser` (<https://github.com/i18next/i18next-parser/issues/1045>)
34
38
 
35
39
  ## `0.0.2` – 2024-Jul-26
36
40
 
37
- - fix: match po files against relative module path
41
+ - fixed: match po files against relative module path
38
42
  - docs: mention `i18next-plugin-pofile-backend` package
39
43
  - chore: remove old license headers
40
44
  - chore: bump deps
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import type { Plugin } from "vite";
4
4
  */
5
5
  export interface VitePluginI18nextGettextOptions {
6
6
  /**
7
- * Glob pattern(s) for all `.po` files containing the translations.
7
+ * Glob pattern(s) for all PO files containing the translations.
8
8
  *
9
9
  * @example
10
10
  * {
@@ -24,19 +24,21 @@ export interface VitePluginI18nextGettextOptions {
24
24
  */
25
25
  srcFiles: string | string[];
26
26
  /**
27
- * Path to the `.pot` file to be generated when building the project,
28
- * relative to the build output directory.
27
+ * Path to the POT files generated when building the project, relative to
28
+ * the build output directory. Should contain the placeholder `$NAMESPACE`
29
+ * if the project contains translation strings in different i18next
30
+ * namespaces.
29
31
  *
30
32
  * @example
31
33
  * {
32
- * potFile: "i18n/main.pot",
34
+ * potFile: "i18n/$NAMESPACE.pot",
33
35
  * // ...
34
36
  * }
35
37
  */
36
38
  potFile: string;
37
39
  /**
38
- * The project name to be inserted into the `.pot` file under the key
39
- * "Project-Id-Version".
40
+ * The project name to be inserted into the POT files under the key
41
+ * "Project-Id-Version". May contain the placeholder `$NAMESPACE`.
40
42
  */
41
43
  projectName: string;
42
44
  }
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ export const PROJECT_NAME = "@open-xchange/vite-plugin-i18next-gettext";
18
18
  export default function vitePluginI18nextGettext(options) {
19
19
  return {
20
20
  name: PROJECT_NAME,
21
- // register esbuild loader for `.po` files (load as plain text)
21
+ // register esbuild loader for PO files (load as plain text)
22
22
  config: () => ({
23
23
  optimizeDeps: {
24
24
  esbuildOptions: {
@@ -26,23 +26,32 @@ export default function vitePluginI18nextGettext(options) {
26
26
  },
27
27
  },
28
28
  }),
29
- // convert `.po` files to i18next JSON v4
29
+ // convert PO files to i18next JSON v4
30
30
  async load(id) {
31
31
  const relPath = relative(process.cwd(), id).replaceAll(sep, posix.sep);
32
32
  if (!pm.isMatch(relPath, options.poFiles)) {
33
33
  return;
34
34
  }
35
- // read the `.po` file and convert it to i18next JSON
35
+ // read the PO file and convert it to i18next JSON
36
36
  const data = await readFile(id, { encoding: "utf8" });
37
37
  const json = converter.po2i18next(data, { compatibilityJSON: "v4" });
38
38
  // generate a module that exports a _stringified_ JSON object
39
39
  const code = `export default ${JSON.stringify(json)};`;
40
40
  return { code, map: { mappings: "" } };
41
41
  },
42
- // parse source files and create a `.pot` file
42
+ // parse source files and create POT files per namespace
43
43
  async generateBundle() {
44
- const source = await parse({ project: options.projectName, files: options.srcFiles });
45
- this.emitFile({ type: "asset", fileName: options.potFile, source });
44
+ // parse all source files, extract translations, collect into POT catalogs
45
+ const catalogs = await parse({ project: options.projectName, files: options.srcFiles });
46
+ // warn when writing multiple POT files to same file location
47
+ if ((catalogs.size > 1) && !options.potFile.includes("$NAMESPACE")) {
48
+ this.warn("multiple POT files written to same file location (missing placeholder '$NAMESPACE' in option 'potFile')");
49
+ }
50
+ // add all POT files as assets to the bundle
51
+ for (const [namespace, source] of catalogs) {
52
+ const fileName = options.potFile.replaceAll("$NAMESPACE", namespace);
53
+ this.emitFile({ type: "asset", fileName, source });
54
+ }
46
55
  },
47
56
  };
48
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/vite-plugin-i18next-gettext",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "Vite integration of i18next using gettext",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,7 @@
25
25
  "lint": "tsc && tsc --project src/tsconfig.json --noEmit && eslint ."
26
26
  },
27
27
  "dependencies": {
28
- "@open-xchange/i18next-po-parser": "^0.0.1",
28
+ "@open-xchange/i18next-po-parser": "^0.0.2",
29
29
  "gettext-converter": "^1.3.0",
30
30
  "picomatch": "^4.0.2"
31
31
  },