@lingui/format-po 5.7.0 → 5.8.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.
Files changed (3) hide show
  1. package/dist/po.cjs +16 -5
  2. package/dist/po.mjs +16 -5
  3. package/package.json +4 -4
package/dist/po.cjs CHANGED
@@ -38,7 +38,7 @@ function getCreateHeaders(language, customHeaderAttributes) {
38
38
  }
39
39
  const EXPLICIT_ID_FLAG = "js-lingui-explicit-id";
40
40
  const GENERATED_ID_FLAG = "js-lingui-generated-id";
41
- const serialize = (catalog, options) => {
41
+ const serialize = (catalog, options, ctx) => {
42
42
  return Object.keys(catalog).map((id) => {
43
43
  const message = catalog[id];
44
44
  const item = new PO__default.Item();
@@ -90,7 +90,11 @@ const serialize = (catalog, options) => {
90
90
  if (message.context) {
91
91
  item.msgctxt = message.context;
92
92
  }
93
- item.msgstr = [message.translation];
93
+ if (!_isGeneratedId && (ctx.locale === ctx.sourceLocale || ctx.locale === null)) {
94
+ item.msgstr = [message.translation || message.message];
95
+ } else {
96
+ item.msgstr = [message.translation];
97
+ }
94
98
  item.comments = message.extra?.translatorComments || [];
95
99
  if (options.origins !== false) {
96
100
  if (message.origin && options.lineNumbers === false) {
@@ -105,9 +109,13 @@ const serialize = (catalog, options) => {
105
109
  };
106
110
  function deserialize(items, options) {
107
111
  return items.reduce((catalog, item) => {
112
+ const comments = item.extractedComments;
108
113
  const message = {
109
114
  translation: item.msgstr[0],
110
- comments: item.extractedComments || [],
115
+ comments: comments.filter(
116
+ // drop flags from comments
117
+ (c) => c !== GENERATED_ID_FLAG && c !== EXPLICIT_ID_FLAG
118
+ ),
111
119
  context: item.msgctxt ?? null,
112
120
  obsolete: item.flags.obsolete || item.obsolete,
113
121
  origin: (item.references || []).map((ref) => splitOrigin(ref)),
@@ -117,7 +125,7 @@ function deserialize(items, options) {
117
125
  }
118
126
  };
119
127
  let id = item.msgid;
120
- if (options.explicitIdAsDefault ? item.extractedComments.includes(GENERATED_ID_FLAG) : !item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
128
+ if (options.explicitIdAsDefault ? comments.includes(GENERATED_ID_FLAG) : !comments.includes(EXPLICIT_ID_FLAG)) {
121
129
  id = generateMessageId.generateMessageId(item.msgid, item.msgctxt);
122
130
  message.message = item.msgid;
123
131
  }
@@ -150,7 +158,10 @@ function formatter(options = {}) {
150
158
  );
151
159
  po.headerOrder = Object.keys(po.headers);
152
160
  }
153
- po.items = serialize(catalog, options);
161
+ po.items = serialize(catalog, options, {
162
+ locale: ctx.locale,
163
+ sourceLocale: ctx.sourceLocale
164
+ });
154
165
  return po.toString();
155
166
  }
156
167
  };
package/dist/po.mjs CHANGED
@@ -32,7 +32,7 @@ function getCreateHeaders(language, customHeaderAttributes) {
32
32
  }
33
33
  const EXPLICIT_ID_FLAG = "js-lingui-explicit-id";
34
34
  const GENERATED_ID_FLAG = "js-lingui-generated-id";
35
- const serialize = (catalog, options) => {
35
+ const serialize = (catalog, options, ctx) => {
36
36
  return Object.keys(catalog).map((id) => {
37
37
  const message = catalog[id];
38
38
  const item = new PO.Item();
@@ -84,7 +84,11 @@ const serialize = (catalog, options) => {
84
84
  if (message.context) {
85
85
  item.msgctxt = message.context;
86
86
  }
87
- item.msgstr = [message.translation];
87
+ if (!_isGeneratedId && (ctx.locale === ctx.sourceLocale || ctx.locale === null)) {
88
+ item.msgstr = [message.translation || message.message];
89
+ } else {
90
+ item.msgstr = [message.translation];
91
+ }
88
92
  item.comments = message.extra?.translatorComments || [];
89
93
  if (options.origins !== false) {
90
94
  if (message.origin && options.lineNumbers === false) {
@@ -99,9 +103,13 @@ const serialize = (catalog, options) => {
99
103
  };
100
104
  function deserialize(items, options) {
101
105
  return items.reduce((catalog, item) => {
106
+ const comments = item.extractedComments;
102
107
  const message = {
103
108
  translation: item.msgstr[0],
104
- comments: item.extractedComments || [],
109
+ comments: comments.filter(
110
+ // drop flags from comments
111
+ (c) => c !== GENERATED_ID_FLAG && c !== EXPLICIT_ID_FLAG
112
+ ),
105
113
  context: item.msgctxt ?? null,
106
114
  obsolete: item.flags.obsolete || item.obsolete,
107
115
  origin: (item.references || []).map((ref) => splitOrigin(ref)),
@@ -111,7 +119,7 @@ function deserialize(items, options) {
111
119
  }
112
120
  };
113
121
  let id = item.msgid;
114
- if (options.explicitIdAsDefault ? item.extractedComments.includes(GENERATED_ID_FLAG) : !item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
122
+ if (options.explicitIdAsDefault ? comments.includes(GENERATED_ID_FLAG) : !comments.includes(EXPLICIT_ID_FLAG)) {
115
123
  id = generateMessageId(item.msgid, item.msgctxt);
116
124
  message.message = item.msgid;
117
125
  }
@@ -144,7 +152,10 @@ function formatter(options = {}) {
144
152
  );
145
153
  po.headerOrder = Object.keys(po.headers);
146
154
  }
147
- po.items = serialize(catalog, options);
155
+ po.items = serialize(catalog, options, {
156
+ locale: ctx.locale,
157
+ sourceLocale: ctx.sourceLocale
158
+ });
148
159
  return po.toString();
149
160
  }
150
161
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/format-po",
3
- "version": "5.7.0",
3
+ "version": "5.8.0",
4
4
  "description": "Gettext PO format for Lingui Catalogs",
5
5
  "main": "./dist/po.cjs",
6
6
  "module": "./dist/po.mjs",
@@ -43,8 +43,8 @@
43
43
  "dist/"
44
44
  ],
45
45
  "dependencies": {
46
- "@lingui/conf": "5.7.0",
47
- "@lingui/message-utils": "5.7.0",
46
+ "@lingui/conf": "5.8.0",
47
+ "@lingui/message-utils": "5.8.0",
48
48
  "date-fns": "^3.6.0",
49
49
  "pofile": "^1.1.4"
50
50
  },
@@ -53,5 +53,5 @@
53
53
  "mockdate": "^3.0.5",
54
54
  "unbuild": "2.0.0"
55
55
  },
56
- "gitHead": "e8c42d548af8fae7365094e58249148fa6a6019f"
56
+ "gitHead": "83d0513bdda9ff14003a05d376c7fedf860dd7ee"
57
57
  }