@lingui/cli 4.11.0 → 4.11.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.
@@ -57,12 +57,11 @@ function buildExportStatement(expression, namespace) {
57
57
  // import type { Messages } from "@lingui/core";
58
58
  const importMessagesTypeDeclaration = t.importDeclaration([t.importSpecifier(t.identifier("Messages"), t.identifier("Messages"))], t.stringLiteral("@lingui/core"));
59
59
  importMessagesTypeDeclaration.importKind = "type";
60
- // Create the exported `messages` identifier with a `Messages` TS type annotation
61
- const messagesIdentifier = t.identifier("messages");
62
- messagesIdentifier.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier("Messages")));
63
- // export const messages:Messages = { message: "Translation" }
60
+ // Cast the expression to `Messages`
61
+ const castExpression = t.tsAsExpression(expression, t.tsTypeReference(t.identifier("Messages")));
62
+ // export const messages = ({ message: "Translation" } as Messages)
64
63
  const exportDeclaration = t.exportNamedDeclaration(t.variableDeclaration("const", [
65
- t.variableDeclarator(messagesIdentifier, expression),
64
+ t.variableDeclarator(t.identifier("messages"), castExpression),
66
65
  ]));
67
66
  return t.program([importMessagesTypeDeclaration, exportDeclaration]);
68
67
  }
@@ -9,6 +9,8 @@ const pofile_1 = __importDefault(require("pofile"));
9
9
  const https_1 = __importDefault(require("https"));
10
10
  const glob_1 = __importDefault(require("glob"));
11
11
  const date_fns_1 = require("date-fns");
12
+ const EXPLICIT_ID_FLAG = "js-lingui-explicit-id";
13
+ const EXPLICIT_ID_AND_CONTEXT_FLAG = "js-lingui-explicit-id-and-context";
12
14
  const getCreateHeaders = (language) => ({
13
15
  "POT-Creation-Date": (0, date_fns_1.format)(new Date(), "yyyy-MM-dd HH:mmxxxx"),
14
16
  "MIME-Version": "1.0",
@@ -141,32 +143,64 @@ function sync(config, options, successCallback, failCallback) {
141
143
  });
142
144
  }
143
145
  function createSegmentFromPoItem(item) {
144
- const itemHasId = item.msgid != item.msgstr[0] && item.msgstr[0].length;
146
+ const itemHasExplicitId = item.extractedComments.includes(EXPLICIT_ID_FLAG);
147
+ const itemHasContext = item.msgctxt != null;
145
148
  const segment = {
146
149
  type: "source",
147
- source: itemHasId ? item.msgstr[0] : item.msgid,
150
+ source: "",
148
151
  context: "",
149
152
  references: [],
150
153
  comment: "",
151
154
  };
152
- if (itemHasId) {
155
+ // For segment.source & segment.context, we must remain compatible with projects created/synced before Lingui V4
156
+ if (itemHasExplicitId) {
157
+ segment.source = item.msgstr[0];
153
158
  segment.context = item.msgid;
154
159
  }
160
+ else {
161
+ segment.source = item.msgid;
162
+ if (itemHasContext) {
163
+ segment.context = item.msgctxt;
164
+ }
165
+ }
155
166
  if (item.references.length) {
156
167
  segment.references = item.references;
157
168
  }
169
+ // Since Lingui v4, when using explicit IDs, Lingui automatically adds 'js-lingui-explicit-id' to the extractedComments array
158
170
  if (item.extractedComments.length) {
159
171
  segment.comment = item.extractedComments.join(" | ");
172
+ if (itemHasExplicitId && itemHasContext) {
173
+ // segment.context is already used for the explicit ID, so we need to pass the context (for translators) in segment.comment
174
+ segment.comment = `${item.msgctxt} | ${segment.comment}`;
175
+ // Replace the flag to let us know how to recompose a target PO Item that is consistent with the source PO Item
176
+ segment.comment = segment.comment.replace(EXPLICIT_ID_FLAG, EXPLICIT_ID_AND_CONTEXT_FLAG);
177
+ }
160
178
  }
161
179
  return segment;
162
180
  }
163
181
  function createPoItemFromSegment(segment) {
182
+ var _a, _b;
183
+ const segmentHasExplicitId = (_a = segment.comment) === null || _a === void 0 ? void 0 : _a.includes(EXPLICIT_ID_FLAG);
184
+ const segmentHasExplicitIdAndContext = (_b = segment.comment) === null || _b === void 0 ? void 0 : _b.includes(EXPLICIT_ID_AND_CONTEXT_FLAG);
164
185
  const item = new pofile_1.default.Item();
165
- item.msgid = segment.context ? segment.context : segment.source;
186
+ if (segmentHasExplicitId || segmentHasExplicitIdAndContext) {
187
+ item.msgid = segment.context;
188
+ }
189
+ else {
190
+ item.msgid = segment.source;
191
+ item.msgctxt = segment.context;
192
+ }
166
193
  item.msgstr = [segment.target];
167
194
  item.references =
168
195
  segment.references && segment.references.length ? segment.references : [];
169
- item.extractedComments = segment.comment ? segment.comment.split(" | ") : [];
196
+ if (segment.comment) {
197
+ segment.comment = segment.comment.replace(EXPLICIT_ID_AND_CONTEXT_FLAG, EXPLICIT_ID_FLAG);
198
+ item.extractedComments = segment.comment ? segment.comment.split(" | ") : [];
199
+ // We recompose a target PO Item that is consistent with the source PO Item
200
+ if (segmentHasExplicitIdAndContext) {
201
+ item.msgctxt = item.extractedComments.shift();
202
+ }
203
+ }
170
204
  return item;
171
205
  }
172
206
  function saveSegmentsToTargetPos(config, paths, segmentsPerLocale) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "4.11.0",
3
+ "version": "4.11.2",
4
4
  "description": "CLI for working wit message catalogs",
5
5
  "keywords": [
6
6
  "cli",
@@ -53,11 +53,11 @@
53
53
  "@babel/parser": "^7.21.2",
54
54
  "@babel/runtime": "^7.21.0",
55
55
  "@babel/types": "^7.21.2",
56
- "@lingui/babel-plugin-extract-messages": "4.11.0",
57
- "@lingui/conf": "4.11.0",
58
- "@lingui/core": "4.11.0",
59
- "@lingui/format-po": "4.11.0",
60
- "@lingui/message-utils": "4.11.0",
56
+ "@lingui/babel-plugin-extract-messages": "4.11.2",
57
+ "@lingui/conf": "4.11.2",
58
+ "@lingui/core": "4.11.2",
59
+ "@lingui/format-po": "4.11.2",
60
+ "@lingui/message-utils": "4.11.2",
61
61
  "babel-plugin-macros": "^3.0.1",
62
62
  "chalk": "^4.1.0",
63
63
  "chokidar": "3.5.1",
@@ -80,7 +80,7 @@
80
80
  },
81
81
  "devDependencies": {
82
82
  "@lingui/jest-mocks": "*",
83
- "@lingui/macro": "4.11.0",
83
+ "@lingui/macro": "4.11.2",
84
84
  "@types/convert-source-map": "^2.0.0",
85
85
  "@types/glob": "^8.1.0",
86
86
  "@types/micromatch": "^4.0.1",
@@ -88,5 +88,5 @@
88
88
  "mock-fs": "^5.2.0",
89
89
  "mockdate": "^3.0.5"
90
90
  },
91
- "gitHead": "8668ba8ef405d99d496949ff9681247deb97063d"
91
+ "gitHead": "17e0af54b0b9d9577db2cef1be680a6d871611e7"
92
92
  }