@lingui/format-po 4.0.0-next.3 → 4.0.0-next.5

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/dist/po.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const dateFns = require('date-fns');
4
4
  const PO = require('pofile');
5
- const api = require('@lingui/cli/api');
5
+ const generateMessageId = require('@lingui/message-utils/generateMessageId');
6
6
 
7
7
  const splitOrigin = (origin) => {
8
8
  const [file, line] = origin.split(":");
@@ -10,7 +10,7 @@ const splitOrigin = (origin) => {
10
10
  };
11
11
  const joinOrigin = (origin) => origin.join(":");
12
12
  function isGeneratedId(id, message) {
13
- return id === api.generateMessageId(message.message, message.context);
13
+ return id === generateMessageId.generateMessageId(message.message, message.context);
14
14
  }
15
15
  function getCreateHeaders(language) {
16
16
  return {
@@ -22,13 +22,13 @@ function getCreateHeaders(language) {
22
22
  ...language ? { Language: language } : {}
23
23
  };
24
24
  }
25
- const EXPLICIT_ID_FLAG = "explicit-id";
25
+ const EXPLICIT_ID_FLAG = "js-lingui-explicit-id";
26
26
  const serialize = (catalog, options) => {
27
27
  return Object.keys(catalog).map((id) => {
28
28
  const message = catalog[id];
29
29
  const item = new PO.Item();
30
- item.extractedComments = [...message.extractedComments || []];
31
- item.flags = (message.flags || []).reduce((acc, flag) => {
30
+ item.extractedComments = [...message.comments || []];
31
+ item.flags = (message.extra?.flags || []).reduce((acc, flag) => {
32
32
  acc[flag] = true;
33
33
  return acc;
34
34
  }, {});
@@ -41,14 +41,16 @@ const serialize = (catalog, options) => {
41
41
  }
42
42
  }
43
43
  } else {
44
- item.flags[EXPLICIT_ID_FLAG] = true;
44
+ if (!item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
45
+ item.extractedComments.push(EXPLICIT_ID_FLAG);
46
+ }
45
47
  item.msgid = id;
46
48
  }
47
49
  if (message.context) {
48
50
  item.msgctxt = message.context;
49
51
  }
50
52
  item.msgstr = [message.translation];
51
- item.comments = message.comments || [];
53
+ item.comments = message.extra?.translatorComments || [];
52
54
  if (options.origins !== false) {
53
55
  if (message.origin && options.lineNumbers === false) {
54
56
  item.references = message.origin.map(([path]) => path);
@@ -64,16 +66,18 @@ function deserialize(items) {
64
66
  return items.reduce((catalog, item) => {
65
67
  const message = {
66
68
  translation: item.msgstr[0],
67
- extractedComments: item.extractedComments || [],
68
- comments: item.comments || [],
69
+ comments: item.extractedComments || [],
69
70
  context: item.msgctxt ?? null,
70
71
  obsolete: item.flags.obsolete || item.obsolete,
71
72
  origin: (item.references || []).map((ref) => splitOrigin(ref)),
72
- flags: Object.keys(item.flags).map((flag) => flag.trim())
73
+ extra: {
74
+ translatorComments: item.comments || [],
75
+ flags: Object.keys(item.flags).map((flag) => flag.trim())
76
+ }
73
77
  };
74
78
  let id = item.msgid;
75
- if (!item.flags[EXPLICIT_ID_FLAG]) {
76
- id = api.generateMessageId(item.msgid, item.msgctxt);
79
+ if (!item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
80
+ id = generateMessageId.generateMessageId(item.msgid, item.msgctxt);
77
81
  message.message = item.msgid;
78
82
  }
79
83
  catalog[id] = message;
package/dist/po.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CatalogType } from '@lingui/conf';
1
+ import { CatalogFormatter } from '@lingui/conf';
2
2
 
3
3
  type PoFormatterOptions = {
4
4
  /**
@@ -20,14 +20,6 @@ type PoFormatterOptions = {
20
20
  */
21
21
  printLinguiId?: boolean;
22
22
  };
23
- declare function formatter(options?: PoFormatterOptions): {
24
- catalogExtension: string;
25
- templateExtension: string;
26
- parse(content: string): CatalogType;
27
- serialize(catalog: CatalogType, ctx: {
28
- locale: string;
29
- existing: string;
30
- }): string;
31
- };
23
+ declare function formatter(options?: PoFormatterOptions): CatalogFormatter;
32
24
 
33
25
  export { PoFormatterOptions, formatter };
package/dist/po.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { format } from 'date-fns';
2
2
  import PO from 'pofile';
3
- import { generateMessageId } from '@lingui/cli/api';
3
+ import { generateMessageId } from '@lingui/message-utils/generateMessageId';
4
4
 
5
5
  const splitOrigin = (origin) => {
6
6
  const [file, line] = origin.split(":");
@@ -20,13 +20,13 @@ function getCreateHeaders(language) {
20
20
  ...language ? { Language: language } : {}
21
21
  };
22
22
  }
23
- const EXPLICIT_ID_FLAG = "explicit-id";
23
+ const EXPLICIT_ID_FLAG = "js-lingui-explicit-id";
24
24
  const serialize = (catalog, options) => {
25
25
  return Object.keys(catalog).map((id) => {
26
26
  const message = catalog[id];
27
27
  const item = new PO.Item();
28
- item.extractedComments = [...message.extractedComments || []];
29
- item.flags = (message.flags || []).reduce((acc, flag) => {
28
+ item.extractedComments = [...message.comments || []];
29
+ item.flags = (message.extra?.flags || []).reduce((acc, flag) => {
30
30
  acc[flag] = true;
31
31
  return acc;
32
32
  }, {});
@@ -39,14 +39,16 @@ const serialize = (catalog, options) => {
39
39
  }
40
40
  }
41
41
  } else {
42
- item.flags[EXPLICIT_ID_FLAG] = true;
42
+ if (!item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
43
+ item.extractedComments.push(EXPLICIT_ID_FLAG);
44
+ }
43
45
  item.msgid = id;
44
46
  }
45
47
  if (message.context) {
46
48
  item.msgctxt = message.context;
47
49
  }
48
50
  item.msgstr = [message.translation];
49
- item.comments = message.comments || [];
51
+ item.comments = message.extra?.translatorComments || [];
50
52
  if (options.origins !== false) {
51
53
  if (message.origin && options.lineNumbers === false) {
52
54
  item.references = message.origin.map(([path]) => path);
@@ -62,15 +64,17 @@ function deserialize(items) {
62
64
  return items.reduce((catalog, item) => {
63
65
  const message = {
64
66
  translation: item.msgstr[0],
65
- extractedComments: item.extractedComments || [],
66
- comments: item.comments || [],
67
+ comments: item.extractedComments || [],
67
68
  context: item.msgctxt ?? null,
68
69
  obsolete: item.flags.obsolete || item.obsolete,
69
70
  origin: (item.references || []).map((ref) => splitOrigin(ref)),
70
- flags: Object.keys(item.flags).map((flag) => flag.trim())
71
+ extra: {
72
+ translatorComments: item.comments || [],
73
+ flags: Object.keys(item.flags).map((flag) => flag.trim())
74
+ }
71
75
  };
72
76
  let id = item.msgid;
73
- if (!item.flags[EXPLICIT_ID_FLAG]) {
77
+ if (!item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
74
78
  id = generateMessageId(item.msgid, item.msgctxt);
75
79
  message.message = item.msgid;
76
80
  }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@lingui/format-po",
3
- "version": "4.0.0-next.3",
3
+ "version": "4.0.0-next.5",
4
4
  "description": "Gettext PO format for Lingui Catalogs",
5
5
  "main": "./dist/po.cjs",
6
6
  "module": "./dist/po.mjs",
7
7
  "types": "./dist/po.d.ts",
8
+ "sideEffects": false,
8
9
  "license": "MIT",
9
10
  "keywords": [
10
11
  "i18n",
@@ -39,14 +40,16 @@
39
40
  "dist/"
40
41
  ],
41
42
  "dependencies": {
42
- "@lingui/cli": "^4.0.0-next.3",
43
- "@lingui/conf": "^4.0.0-next.3",
43
+ "@lingui/conf": "^4.0.0-next.5",
44
+ "@lingui/message-utils": "^4.0.0-next.5",
44
45
  "date-fns": "^2.29.3",
45
46
  "pofile": "^1.1.4"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@lingui/jest-mocks": "^3.0.3",
50
+ "mockdate": "^3.0.5",
51
+ "tsd": "^0.28.0",
49
52
  "unbuild": "^1.1.2"
50
53
  },
51
- "gitHead": "29cad1bdcc781994ac4d496e5c4937795423d405"
54
+ "gitHead": "bdbd6cf310cbcf09e1fe288f20ef530c28de481d"
52
55
  }