@lingui/cli 3.15.0 → 3.16.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 (46) hide show
  1. package/CHANGELOG.md +482 -0
  2. package/build/LICENSE +21 -0
  3. package/build/api/catalog.js +582 -0
  4. package/build/api/compile.js +89 -0
  5. package/{api → build/api}/detect.js +23 -9
  6. package/build/api/extract.js +78 -0
  7. package/build/api/extractors/babel.js +51 -0
  8. package/build/api/extractors/index.js +51 -0
  9. package/build/api/extractors/typescript.js +71 -0
  10. package/build/api/formats/csv.js +65 -0
  11. package/{api → build/api}/formats/index.js +8 -5
  12. package/build/api/formats/lingui.js +67 -0
  13. package/build/api/formats/minimal.js +63 -0
  14. package/build/api/formats/po-gettext.js +296 -0
  15. package/build/api/formats/po.js +122 -0
  16. package/{api → build/api}/help.js +6 -18
  17. package/{api → build/api}/index.js +7 -7
  18. package/build/api/locales.js +45 -0
  19. package/{api → build/api}/pseudoLocalize.js +13 -13
  20. package/build/api/stats.js +46 -0
  21. package/{api → build/api}/utils.js +21 -40
  22. package/build/lingui-add-locale.js +11 -0
  23. package/build/lingui-compile.js +192 -0
  24. package/build/lingui-extract-template.js +64 -0
  25. package/build/lingui-extract.js +181 -0
  26. package/{lingui.js → build/lingui.js} +2 -2
  27. package/{services → build/services}/translationIO.js +78 -94
  28. package/build/tests.js +78 -0
  29. package/package.json +18 -12
  30. package/api/catalog.js +0 -778
  31. package/api/compile.js +0 -172
  32. package/api/extract.js +0 -192
  33. package/api/extractors/babel.js +0 -61
  34. package/api/extractors/index.js +0 -130
  35. package/api/extractors/typescript.js +0 -77
  36. package/api/formats/csv.js +0 -71
  37. package/api/formats/lingui.js +0 -64
  38. package/api/formats/minimal.js +0 -63
  39. package/api/formats/po-gettext.js +0 -331
  40. package/api/formats/po.js +0 -130
  41. package/api/locales.js +0 -43
  42. package/api/stats.js +0 -51
  43. package/lingui-add-locale.js +0 -11
  44. package/lingui-compile.js +0 -198
  45. package/lingui-extract-template.js +0 -123
  46. package/lingui-extract.js +0 -286
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -19,33 +17,33 @@ var _glob = _interopRequireDefault(require("glob"));
19
17
 
20
18
  var _dateFns = require("date-fns");
21
19
 
22
- var getCreateHeaders = function getCreateHeaders(language) {
23
- return {
24
- "POT-Creation-Date": (0, _dateFns.format)(new Date(), "yyyy-MM-dd HH:mmxxxx"),
25
- "MIME-Version": "1.0",
26
- "Content-Type": "text/plain; charset=utf-8",
27
- "Content-Transfer-Encoding": "8bit",
28
- "X-Generator": "@lingui/cli",
29
- Language: language
30
- };
31
- }; // Main sync method, call "Init" or "Sync" depending on the project context
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ const getCreateHeaders = language => ({
23
+ "POT-Creation-Date": (0, _dateFns.format)(new Date(), "yyyy-MM-dd HH:mmxxxx"),
24
+ "MIME-Version": "1.0",
25
+ "Content-Type": "text/plain; charset=utf-8",
26
+ "Content-Transfer-Encoding": "8bit",
27
+ "X-Generator": "@lingui/cli",
28
+ Language: language
29
+ }); // Main sync method, call "Init" or "Sync" depending on the project context
32
30
 
33
31
 
34
32
  function syncProcess(config, options) {
35
33
  if (config.format != 'po') {
36
- console.error("\n----------\nTranslation.io service is only compatible with the \"po\" format. Please update your Lingui configuration accordingly.\n----------");
34
+ console.error(`\n----------\nTranslation.io service is only compatible with the "po" format. Please update your Lingui configuration accordingly.\n----------`);
37
35
  process.exit(1);
38
36
  }
39
37
 
40
- var successCallback = function successCallback(project) {
41
- console.log("\n----------\nProject successfully synchronized. Please use this URL to translate: ".concat(project.url, "\n----------"));
38
+ const successCallback = project => {
39
+ console.log(`\n----------\nProject successfully synchronized. Please use this URL to translate: ${project.url}\n----------`);
42
40
  };
43
41
 
44
- var failCallback = function failCallback(errors) {
45
- console.error("\n----------\nSynchronization with Translation.io failed: ".concat(errors.join(', '), "\n----------"));
42
+ const failCallback = errors => {
43
+ console.error(`\n----------\nSynchronization with Translation.io failed: ${errors.join(', ')}\n----------`);
46
44
  };
47
45
 
48
- init(config, options, successCallback, function (errors) {
46
+ init(config, options, successCallback, errors => {
49
47
  if (errors.length && errors[0] === 'This project has already been initialized.') {
50
48
  sync(config, options, successCallback, failCallback);
51
49
  } else {
@@ -57,87 +55,77 @@ function syncProcess(config, options) {
57
55
 
58
56
 
59
57
  function init(config, options, successCallback, failCallback) {
60
- var sourceLocale = config.sourceLocale || 'en';
61
- var pseudoLocale = config.pseudoLocale || 'pseudo';
62
- var targetLocales = config.locales.filter(function (value) {
63
- return value != sourceLocale && value != pseudoLocale;
64
- });
65
- var paths = poPathsPerLocale(config);
66
- var segments = {};
67
- targetLocales.forEach(function (targetLocale) {
58
+ const sourceLocale = config.sourceLocale || 'en';
59
+ const pseudoLocale = config.pseudoLocale || 'pseudo';
60
+ const targetLocales = config.locales.filter(value => value != sourceLocale && value != pseudoLocale);
61
+ const paths = poPathsPerLocale(config);
62
+ let segments = {};
63
+ targetLocales.forEach(targetLocale => {
68
64
  segments[targetLocale] = [];
69
65
  }); // Create segments from source locale PO items
70
66
 
71
- paths[sourceLocale].forEach(function (path) {
72
- var raw = _fs.default.readFileSync(path).toString();
67
+ paths[sourceLocale].forEach(path => {
68
+ let raw = _fs.default.readFileSync(path).toString();
73
69
 
74
- var po = _pofile.default.parse(raw);
70
+ let po = _pofile.default.parse(raw);
75
71
 
76
- po.items.filter(function (item) {
77
- return !item['obsolete'];
78
- }).forEach(function (item) {
79
- targetLocales.forEach(function (targetLocale) {
80
- var newSegment = createSegmentFromPoItem(item);
72
+ po.items.filter(item => !item['obsolete']).forEach(item => {
73
+ targetLocales.forEach(targetLocale => {
74
+ let newSegment = createSegmentFromPoItem(item);
81
75
  segments[targetLocale].push(newSegment);
82
76
  });
83
77
  });
84
78
  }); // Add translations to segments from target locale PO items
85
79
 
86
- targetLocales.forEach(function (targetLocale) {
87
- paths[targetLocale].forEach(function (path) {
88
- var raw = _fs.default.readFileSync(path).toString();
80
+ targetLocales.forEach(targetLocale => {
81
+ paths[targetLocale].forEach(path => {
82
+ let raw = _fs.default.readFileSync(path).toString();
89
83
 
90
- var po = _pofile.default.parse(raw);
84
+ let po = _pofile.default.parse(raw);
91
85
 
92
- po.items.filter(function (item) {
93
- return !item['obsolete'];
94
- }).forEach(function (item, index) {
86
+ po.items.filter(item => !item['obsolete']).forEach((item, index) => {
95
87
  segments[targetLocale][index].target = item.msgstr[0];
96
88
  });
97
89
  });
98
90
  });
99
- var request = {
91
+ let request = {
100
92
  "client": "lingui",
101
93
  "version": require('@lingui/core/package.json').version,
102
94
  "source_language": sourceLocale,
103
95
  "target_languages": targetLocales,
104
96
  "segments": segments
105
97
  };
106
- postTio("init", request, config.service.apiKey, function (response) {
98
+ postTio("init", request, config.service.apiKey, response => {
107
99
  if (response.errors) {
108
100
  failCallback(response.errors);
109
101
  } else {
110
102
  saveSegmentsToTargetPos(config, paths, response.segments);
111
103
  successCallback(response.project);
112
104
  }
113
- }, function (error) {
114
- console.error("\n----------\nSynchronization with Translation.io failed: ".concat(error, "\n----------"));
105
+ }, error => {
106
+ console.error(`\n----------\nSynchronization with Translation.io failed: ${error}\n----------`);
115
107
  });
116
108
  } // Send all source text from PO to Translation.io and create new PO based on received translations
117
109
  // Cf. https://translation.io/docs/create-library#synchronization
118
110
 
119
111
 
120
112
  function sync(config, options, successCallback, failCallback) {
121
- var sourceLocale = config.sourceLocale || 'en';
122
- var targetLocales = config.locales.filter(function (value) {
123
- return value != sourceLocale;
124
- });
125
- var paths = poPathsPerLocale(config);
126
- var segments = []; // Create segments with correct source
113
+ const sourceLocale = config.sourceLocale || 'en';
114
+ const targetLocales = config.locales.filter(value => value != sourceLocale);
115
+ const paths = poPathsPerLocale(config);
116
+ let segments = []; // Create segments with correct source
127
117
 
128
- paths[sourceLocale].forEach(function (path) {
129
- var raw = _fs.default.readFileSync(path).toString();
118
+ paths[sourceLocale].forEach(path => {
119
+ let raw = _fs.default.readFileSync(path).toString();
130
120
 
131
- var po = _pofile.default.parse(raw);
121
+ let po = _pofile.default.parse(raw);
132
122
 
133
- po.items.filter(function (item) {
134
- return !item['obsolete'];
135
- }).forEach(function (item) {
136
- var newSegment = createSegmentFromPoItem(item);
123
+ po.items.filter(item => !item['obsolete']).forEach(item => {
124
+ let newSegment = createSegmentFromPoItem(item);
137
125
  segments.push(newSegment);
138
126
  });
139
127
  });
140
- var request = {
128
+ let request = {
141
129
  "client": "lingui",
142
130
  "version": require('@lingui/core/package.json').version,
143
131
  "source_language": sourceLocale,
@@ -149,21 +137,21 @@ function sync(config, options, successCallback, failCallback) {
149
137
  request['purge'] = true;
150
138
  }
151
139
 
152
- postTio("sync", request, config.service.apiKey, function (response) {
140
+ postTio("sync", request, config.service.apiKey, response => {
153
141
  if (response.errors) {
154
142
  failCallback(response.errors);
155
143
  } else {
156
144
  saveSegmentsToTargetPos(config, paths, response.segments);
157
145
  successCallback(response.project);
158
146
  }
159
- }, function (error) {
160
- console.error("\n----------\nSynchronization with Translation.io failed: ".concat(error, "\n----------"));
147
+ }, error => {
148
+ console.error(`\n----------\nSynchronization with Translation.io failed: ${error}\n----------`);
161
149
  });
162
150
  }
163
151
 
164
152
  function createSegmentFromPoItem(item) {
165
- var itemHasId = item.msgid != item.msgstr[0] && item.msgstr[0].length;
166
- var segment = {
153
+ let itemHasId = item.msgid != item.msgstr[0] && item.msgstr[0].length;
154
+ let segment = {
167
155
  type: 'source',
168
156
  // No way to edit text for source language (inside code), so not using "key" here
169
157
  source: itemHasId ? item.msgstr[0] : item.msgid,
@@ -189,7 +177,7 @@ function createSegmentFromPoItem(item) {
189
177
  }
190
178
 
191
179
  function createPoItemFromSegment(segment) {
192
- var item = new _pofile.default.Item();
180
+ let item = new _pofile.default.Item();
193
181
  item.msgid = segment.context ? segment.context : segment.source;
194
182
  item.msgstr = [segment.target];
195
183
  item.references = segment.references && segment.references.length ? segment.references : [];
@@ -198,13 +186,11 @@ function createPoItemFromSegment(segment) {
198
186
  }
199
187
 
200
188
  function saveSegmentsToTargetPos(config, paths, segmentsPerLocale) {
201
- var NAME = "{name}";
202
- var LOCALE = "{locale}";
203
- Object.keys(segmentsPerLocale).forEach(function (targetLocale) {
189
+ Object.keys(segmentsPerLocale).forEach(targetLocale => {
204
190
  // Remove existing target POs and JS for this target locale
205
- paths[targetLocale].forEach(function (path) {
206
- var jsPath = path.replace(/\.po?$/, "") + ".js";
207
- var dirPath = (0, _path.dirname)(path); // Remove PO, JS and empty dir
191
+ paths[targetLocale].forEach(path => {
192
+ const jsPath = path.replace(/\.po?$/, "") + ".js";
193
+ const dirPath = (0, _path.dirname)(path); // Remove PO, JS and empty dir
208
194
 
209
195
  if (_fs.default.existsSync(path)) {
210
196
  _fs.default.unlinkSync(path);
@@ -219,17 +205,17 @@ function saveSegmentsToTargetPos(config, paths, segmentsPerLocale) {
219
205
  }
220
206
  }); // Find target path (ignoring {name})
221
207
 
222
- var localePath = "".concat(config.catalogs[0].path.replace(LOCALE, targetLocale).replace(NAME, ''), ".po");
223
- var segments = segmentsPerLocale[targetLocale];
224
- var po = new _pofile.default();
208
+ const localePath = "".concat(config.catalogs[0].path.replace(/{locale}/g, targetLocale).replace(/{name}/g, ""), ".po");
209
+ const segments = segmentsPerLocale[targetLocale];
210
+ let po = new _pofile.default();
225
211
  po.headers = getCreateHeaders(targetLocale);
226
- var items = [];
227
- segments.forEach(function (segment) {
228
- var item = createPoItemFromSegment(segment);
212
+ let items = [];
213
+ segments.forEach(segment => {
214
+ let item = createPoItemFromSegment(segment);
229
215
  items.push(item);
230
216
  }); // Sort items by messageId
231
217
 
232
- po.items = items.sort(function (a, b) {
218
+ po.items = items.sort((a, b) => {
233
219
  if (a.msgid < b.msgid) {
234
220
  return -1;
235
221
  }
@@ -243,8 +229,8 @@ function saveSegmentsToTargetPos(config, paths, segmentsPerLocale) {
243
229
 
244
230
  _fs.default.promises.mkdir((0, _path.dirname)(localePath), {
245
231
  recursive: true
246
- }).then(function () {
247
- po.save(localePath, function (err) {
232
+ }).then(() => {
233
+ po.save(localePath, err => {
248
234
  if (err) {
249
235
  console.error('Error while saving target PO files:');
250
236
  console.error(err);
@@ -256,13 +242,11 @@ function saveSegmentsToTargetPos(config, paths, segmentsPerLocale) {
256
242
  }
257
243
 
258
244
  function poPathsPerLocale(config) {
259
- var NAME = "{name}";
260
- var LOCALE = "{locale}";
261
- var paths = [];
262
- config.locales.forEach(function (locale) {
245
+ const paths = [];
246
+ config.locales.forEach(locale => {
263
247
  paths[locale] = [];
264
- config.catalogs.forEach(function (catalog) {
265
- var path = "".concat(catalog.path.replace(LOCALE, locale).replace(NAME, "*"), ".po"); // If {name} is present (replaced by *), list all the existing POs
248
+ config.catalogs.forEach(catalog => {
249
+ const path = "".concat(catalog.path.replace(/{locale}/g, locale).replace(/{name}/g, "*"), ".po"); // If {name} is present (replaced by *), list all the existing POs
266
250
 
267
251
  if (path.includes('*')) {
268
252
  paths[locale] = paths[locale].concat(_glob.default.sync(path));
@@ -275,8 +259,8 @@ function poPathsPerLocale(config) {
275
259
  }
276
260
 
277
261
  function postTio(action, request, apiKey, successCallback, failCallback) {
278
- var jsonRequest = JSON.stringify(request);
279
- var options = {
262
+ let jsonRequest = JSON.stringify(request);
263
+ let options = {
280
264
  hostname: 'translation.io',
281
265
  path: '/api/v1/segments/' + action + '.json?api_key=' + apiKey,
282
266
  method: 'POST',
@@ -285,19 +269,19 @@ function postTio(action, request, apiKey, successCallback, failCallback) {
285
269
  }
286
270
  };
287
271
 
288
- var req = _https.default.request(options, function (res) {
272
+ let req = _https.default.request(options, res => {
289
273
  res.setEncoding('utf8');
290
- var body = "";
291
- res.on('data', function (chunk) {
274
+ let body = "";
275
+ res.on('data', chunk => {
292
276
  body = body.concat(chunk);
293
277
  });
294
- res.on('end', function () {
295
- var response = JSON.parse(body);
278
+ res.on('end', () => {
279
+ let response = JSON.parse(body);
296
280
  successCallback(response);
297
281
  });
298
282
  });
299
283
 
300
- req.on('error', function (e) {
284
+ req.on('error', e => {
301
285
  failCallback(e);
302
286
  });
303
287
  req.write(jsonRequest);
package/build/tests.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.copyFixture = copyFixture;
7
+ exports.makePrevMessage = makePrevMessage;
8
+ exports.makeNextMessage = makeNextMessage;
9
+ exports.makeCatalog = exports.defaultMergeOptions = exports.defaultMakeTemplateOptions = exports.defaultMakeOptions = void 0;
10
+
11
+ var _os = _interopRequireDefault(require("os"));
12
+
13
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
14
+
15
+ var _path = _interopRequireDefault(require("path"));
16
+
17
+ var _jestMocks = require("@lingui/jest-mocks");
18
+
19
+ var _catalog = require("./api/catalog");
20
+
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+
23
+ function copyFixture(fixtureDir) {
24
+ const tmpDir = _fsExtra.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), `lingui-test-${process.pid}`));
25
+
26
+ if (_fsExtra.default.existsSync(fixtureDir)) {
27
+ _fsExtra.default.copySync(fixtureDir, tmpDir);
28
+ }
29
+
30
+ return tmpDir;
31
+ }
32
+
33
+ const defaultMakeOptions = {
34
+ verbose: false,
35
+ clean: false,
36
+ overwrite: false,
37
+ locale: null,
38
+ prevFormat: null,
39
+ configPath: null,
40
+ orderBy: "messageId"
41
+ };
42
+ exports.defaultMakeOptions = defaultMakeOptions;
43
+ const defaultMakeTemplateOptions = {
44
+ verbose: false,
45
+ configPath: null,
46
+ orderBy: "messageId"
47
+ };
48
+ exports.defaultMakeTemplateOptions = defaultMakeTemplateOptions;
49
+ const defaultMergeOptions = {
50
+ overwrite: false
51
+ };
52
+ exports.defaultMergeOptions = defaultMergeOptions;
53
+
54
+ const makeCatalog = (config = {}) => {
55
+ return new _catalog.Catalog({
56
+ name: "messages",
57
+ path: "{locale}/messages",
58
+ include: [],
59
+ exclude: []
60
+ }, (0, _jestMocks.mockConfig)(config));
61
+ };
62
+
63
+ exports.makeCatalog = makeCatalog;
64
+
65
+ function makePrevMessage(message = {}) {
66
+ return {
67
+ translation: "",
68
+ ...makeNextMessage(message)
69
+ };
70
+ }
71
+
72
+ function makeNextMessage(message = {}) {
73
+ return {
74
+ origin: [["catalog.test.ts", 1]],
75
+ obsolete: false,
76
+ ...message
77
+ };
78
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "3.15.0",
3
+ "version": "3.16.0",
4
4
  "description": "CLI for working wit message catalogs",
5
5
  "keywords": [
6
6
  "cli",
@@ -18,20 +18,25 @@
18
18
  "name": "Tomáš Ehrlich",
19
19
  "email": "tomas.ehrlich@gmail.com"
20
20
  },
21
- "main": "index.js",
21
+ "main": "./build/index.js",
22
22
  "bin": {
23
- "lingui": "./lingui.js"
23
+ "lingui": "./build/lingui.js"
24
+ },
25
+ "exports": {
26
+ ".": {
27
+ "require": "./build/index.js"
28
+ },
29
+ "./api": {
30
+ "require": "./build/api/index.js"
31
+ }
24
32
  },
25
33
  "engines": {
26
- "node": ">=10.0.0"
34
+ "node": ">=14.0.0"
27
35
  },
28
36
  "files": [
29
37
  "LICENSE",
30
38
  "README.md",
31
- "api",
32
- "services",
33
- "lingui.js",
34
- "lingui-*.js"
39
+ "build/"
35
40
  ],
36
41
  "dependencies": {
37
42
  "@babel/generator": "^7.11.6",
@@ -39,8 +44,9 @@
39
44
  "@babel/plugin-syntax-jsx": "^7.10.4",
40
45
  "@babel/runtime": "^7.11.2",
41
46
  "@babel/types": "^7.11.5",
42
- "@lingui/babel-plugin-extract-messages": "^3.15.0",
43
- "@lingui/conf": "^3.15.0",
47
+ "@lingui/babel-plugin-extract-messages": "3.16.0",
48
+ "@lingui/conf": "3.16.0",
49
+ "@lingui/core": "3.16.0",
44
50
  "babel-plugin-macros": "^3.0.1",
45
51
  "bcp-47": "^1.0.7",
46
52
  "chalk": "^4.1.0",
@@ -53,7 +59,6 @@
53
59
  "glob": "^7.1.4",
54
60
  "inquirer": "^7.3.3",
55
61
  "make-plural": "^6.2.2",
56
- "messageformat-parser": "^4.1.3",
57
62
  "micromatch": "4.0.2",
58
63
  "mkdirp": "^1.0.4",
59
64
  "node-gettext": "^3.0.0",
@@ -78,5 +83,6 @@
78
83
  "@babel/core": "^7.0.0",
79
84
  "babel-plugin-macros": "2 || 3",
80
85
  "typescript": "2 || 3 || 4"
81
- }
86
+ },
87
+ "gitHead": "e8c1f518b988f45f3f6da84333550b215dcde94b"
82
88
  }