locize-cli 8.3.0 → 8.4.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
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  Project versioning adheres to [Semantic Versioning](http://semver.org/).
6
6
  Change log format is based on [Keep a Changelog](http://keepachangelog.com/).
7
7
 
8
+ ## [8.4.0](https://github.com/locize/locize-cli/compare/v8.3.1...v8.4.0) - 2024-12-23
9
+
10
+ - feat: add --auto-translate option for sync command [101](https://github.com/locize/locize-cli/pull/101)
11
+
12
+ ## [8.3.1](https://github.com/locize/locize-cli/compare/v8.3.0...v8.3.1) - 2024-12-23
13
+
14
+ - special check for CVS (does not cleanup local language folders)
15
+
8
16
  ## [8.3.0](https://github.com/locize/locize-cli/compare/v8.2.0...v8.3.0) - 2024-11-25
9
17
 
10
18
  - update some deprecated dependencies (#100)
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2023 locize
3
+ Copyright (c) 2025 locize
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -146,6 +146,7 @@ locize sync --api-key my-api-key-d9de-4f55-9855-a9ef0ed44672 --project-id my-pro
146
146
  - if you have less keys (you have deleted some keys) in your local namespace it will remove them in locize too
147
147
  - all non reference languages will always be just locally replaced by what is published on locize, unless the *--skip-delete true* argument is used
148
148
  - if you change the values of existing keys in the reference language, it will not change them in locize (to change the existing values you have to change it directly in locize or use the *--update-values true* argument)
149
+ - if you update existing keys (with *--update-values true*) the automatic translation is not triggered, unless the *--auto-translate true* argument us used
149
150
  - **if you want to take into account all languages instead of the reference language only while comparing the namespace content between local and remote, you can use the command argument *--reference-language-only false***
150
151
  - **if you want to take into account the modification time while comparing the namespace content between local and remote, you can use the command argument *--compare-modification-time true***
151
152
 
package/bin/locize CHANGED
@@ -366,6 +366,7 @@ program
366
366
  .option('-c, --clean <true|false>', 'Removes all local files by removing the whole folder (default: false)', 'false')
367
367
  .option('-cf, --clean-local-files <true|false>', 'Removes all local files without removing any folder (default: false)', 'false')
368
368
  .option('-u, --update-values <true|false>', 'This will update values of existing translations. (default: false)', 'false')
369
+ .option('--auto-translate <true|false>', 'This will trigger auto-translation of updated translations. (default: false)', 'false')
369
370
  .option('-S, --skip-delete <true|false>', 'This will skip the removal of keys on locize. (default: false)', 'false')
370
371
  .option('-D, --delete-remote-namespace <true|false>', 'This will delete a complete namespace on locize, if a local file in reference language was deleted. (default: false)', 'false')
371
372
  .option('-m, --path-mask <mask>', 'This will define the folder and file structure; do not add a file extension (default: {{language}}/{{namespace}})', `{{language}}${path.sep}{{namespace}}`)
@@ -415,6 +416,7 @@ program
415
416
  const cleanLocalFiles = options.cleanLocalFiles === 'true';
416
417
  const dry = options.dry === 'true';
417
418
  const updateValues = options.updateValues === 'true';
419
+ const autoTranslate = options.autoTranslate === 'true';
418
420
  const skipDelete = options.skipDelete === 'true';
419
421
  const deleteRemoteNamespace = options.deleteRemoteNamespace === 'true';
420
422
  const languageFolderPrefix = options.languageFolderPrefix || '';
@@ -434,6 +436,7 @@ program
434
436
  path: options.path,
435
437
  format: options.format,
436
438
  updateValues: updateValues,
439
+ autoTranslate: autoTranslate,
437
440
  skipDelete: skipDelete,
438
441
  deleteRemoteNamespace: deleteRemoteNamespace,
439
442
  languageFolderPrefix: languageFolderPrefix,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locize-cli",
3
- "version": "8.3.0",
3
+ "version": "8.4.0",
4
4
  "description": "locize cli to import locales",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -15,11 +15,11 @@
15
15
  "commander": "9.5.0",
16
16
  "csvjson": "5.1.0",
17
17
  "diff": "7.0.0",
18
- "dotenv": "16.4.5",
18
+ "dotenv": "16.4.7",
19
19
  "flat": "5.0.2",
20
20
  "fluent_conv": "3.3.0",
21
21
  "gettext-converter": "1.3.0",
22
- "https-proxy-agent": "7.0.5",
22
+ "https-proxy-agent": "7.0.6",
23
23
  "ini": "4.1.3",
24
24
  "js-yaml": "4.1.0",
25
25
  "laravelphp": "2.0.4",
@@ -36,7 +36,7 @@
36
36
  "devDependencies": {
37
37
  "eslint": "8.56.0",
38
38
  "gh-release": "7.0.2",
39
- "@yao-pkg/pkg": "6.1.1"
39
+ "@yao-pkg/pkg": "6.2.0"
40
40
  },
41
41
  "scripts": {
42
42
  "lint": "eslint .",
package/sync.js CHANGED
@@ -266,7 +266,19 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
266
266
  var payloadKeysLimit = 1000;
267
267
 
268
268
  function send(d, so, clb, isRetrying) {
269
- request(opt.apiPath + '/update/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns.namespace + (so ? '?omitstatsgeneration=true' : ''), {
269
+ const queryParams = new URLSearchParams();
270
+ if (opt.autoTranslate) {
271
+ /** @See https://docs.locize.com/integration/api#optional-autotranslate */
272
+ queryParams.append('autotranslate', 'true');
273
+ }
274
+ if (so) {
275
+ // no API docs for this
276
+ queryParams.append('omitstatsgeneration', 'true');
277
+ }
278
+
279
+ const queryString = queryParams.size > 0 ? '?' + queryParams.toString() : '';
280
+
281
+ request(opt.apiPath + '/update/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns.namespace + queryString, {
270
282
  method: 'post',
271
283
  body: d,
272
284
  headers: {
@@ -318,6 +330,14 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
318
330
  send(data, shouldOmit, cb);
319
331
  };
320
332
 
333
+ const doesDirectoryExist = (p) => {
334
+ var directoryExists = false;
335
+ try {
336
+ directoryExists = fs.statSync(p).isDirectory();
337
+ } catch (e) {}
338
+ return directoryExists;
339
+ };
340
+
321
341
  const cleanupLanguages = (opt, remoteLanguages) => {
322
342
  if (opt.pathMask.lastIndexOf(path.sep) < 0) return;
323
343
  const dirs = getDirectories(opt.path).filter((dir) => dir.indexOf('.') !== 0);
@@ -338,6 +358,7 @@ const cleanupLanguages = (opt, remoteLanguages) => {
338
358
  if (filledLngMask.lastIndexOf(path.sep) > 0) {
339
359
  lngPath = filledLngMask.substring(0, filledLngMask.lastIndexOf(path.sep));
340
360
  }
361
+ if (doesDirectoryExist(path.join(opt.path, lngPath, 'CVS'))) return; // special hack for CVS
341
362
  rimraf.sync(path.join(opt.path, lngPath));
342
363
  });
343
364
  }
@@ -472,7 +493,7 @@ const handleSync = (opt, remoteLanguages, localNamespaces, cb) => {
472
493
  }
473
494
  if (opt.updateValues) {
474
495
  if (ns.diff.toUpdate.length > 0) {
475
- console.log(colors.yellow(`updating ${ns.diff.toUpdate.length} keys in ${ns.language}/${ns.namespace}...`));
496
+ console.log(colors.yellow(`updating ${ns.diff.toUpdate.length} keys in ${ns.language}/${ns.namespace}${opt.autoTranslate ? ' with automatic translation' : ''}...`));
476
497
  if (opt.dry) console.log(colors.yellow(`would update ${ns.diff.toUpdate.join(', ')} in ${ns.language}/${ns.namespace}...`));
477
498
  }
478
499
  if (ns.diff.toUpdateLocally.length > 0) {
@@ -581,11 +602,7 @@ const sync = (opt, cb) => {
581
602
  if (!opt.dry && opt.clean) rimraf.sync(path.join(opt.path, '*'));
582
603
 
583
604
  if (opt.autoCreatePath === false) {
584
- var directoryExists = false;
585
- try {
586
- directoryExists = fs.statSync(opt.path).isDirectory();
587
- } catch (e) {}
588
- if (!directoryExists) {
605
+ if (!doesDirectoryExist(opt.path)) {
589
606
  return handleError(new Error(`${opt.path} does not exist!`), cb);
590
607
  }
591
608
  }