locize-cli 7.15.2 → 8.0.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,10 @@ 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.0.0](https://github.com/locize/locize-cli/compare/v7.15.2...v8.0.0) - 2023-01-18
9
+
10
+ - align json format with publish format on project: To keep the same behaviour like before with default format or `json` format, now use `--format nested`. The `--format json` (the default) will now try to "guess" if a flat or a nested format should be used.
11
+
8
12
  ## [7.15.2](https://github.com/locize/locize-cli/compare/v7.15.1...v7.15.2) - 2023-01-06
9
13
 
10
14
  - optimize --skip-empty false handling for download command
package/README.md CHANGED
@@ -81,7 +81,7 @@ or
81
81
  locize download
82
82
  ```
83
83
 
84
- or add a format like (json, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties)
84
+ or add a format like (json, nested, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties)
85
85
 
86
86
  ```sh
87
87
  locize download --project-id my-project-id-93e1-442a-ab35-24331fa294ba --ver latest --language en --namespace namespace1 --path ./backup --format android
@@ -126,7 +126,7 @@ Add your api-key and your project-id and let's go...
126
126
  locize sync --api-key my-api-key-d9de-4f55-9855-a9ef0ed44672 --project-id my-project-id-93e1-442a-ab35-24331fa294ba
127
127
  ```
128
128
 
129
- or add a format like (json, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties)
129
+ or add a format like (json, nested, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties)
130
130
 
131
131
  ```sh
132
132
  locize sync --api-key my-api-key-d9de-4f55-9855-a9ef0ed44672 --project-id my-project-id-93e1-442a-ab35-24331fa294ba --format android
@@ -184,7 +184,7 @@ Add your api-key and your project-id and let's go...
184
184
  locize save-missing --api-key my-api-key-d9de-4f55-9855-a9ef0ed44672 --project-id my-project-id-93e1-442a-ab35-24331fa294ba
185
185
  ```
186
186
 
187
- or add a format like (json, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties)
187
+ or add a format like (json, nested, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties)
188
188
 
189
189
  ```sh
190
190
  locize save-missing --api-key my-api-key-d9de-4f55-9855-a9ef0ed44672 --project-id my-project-id-93e1-442a-ab35-24331fa294ba --format android
package/bin/locize CHANGED
@@ -231,7 +231,7 @@ program
231
231
  .option('-p, --path <path>', `Specify the path that should be used (default: ${process.cwd()})`, process.cwd())
232
232
  .option('-g, --get-path <url>', `Specify the get-path url that should be used (default: ${getPathUrl})`)
233
233
  .option('-k, --api-key <apiKey>', 'The api-key that should be used')
234
- .option('-f, --format <json>', 'File format of namespaces (default: json; [flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties])', 'json')
234
+ .option('-f, --format <json>', 'File format of namespaces (default: json; [nested, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties])', 'json')
235
235
  .option('-s, --skip-empty <true|false>', 'Skips to download empty files (default: true)', 'true')
236
236
  .option('-P, --language-folder-prefix <prefix>', 'This will be added as a local folder name prefix in front of the language.', '')
237
237
  .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}}`)
@@ -357,7 +357,7 @@ program
357
357
  .option('-v, --ver <version>', 'Found namespaces will be matched to this version (default: latest)')
358
358
  .option('-p, --path <path>', `Specify the path that should be used (default: ${process.cwd()})`, process.cwd())
359
359
  .option('-A, --auto-create-path <true|false>', 'This will automatically make sure the --path is created. (default: true)', 'true')
360
- .option('-f, --format <json>', 'File format of namespaces (default: json; [flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties])', 'json')
360
+ .option('-f, --format <json>', 'File format of namespaces (default: json; [nested, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties])', 'json')
361
361
  .option('-s, --skip-empty <true|false>', 'Skips to download empty files (default: false)', 'false')
362
362
  .option('-c, --clean <true|false>', 'Removes all local files by removing the whole folder (default: false)', 'false')
363
363
  .option('-cf, --clean-local-files <true|false>', 'Removes all local files without removing any folder (default: false)', 'false')
@@ -460,7 +460,7 @@ program
460
460
  .option('-i, --project-id <projectId>', 'The project-id that should be used')
461
461
  .option('-v, --ver <version>', 'Found namespaces will be matched to this version (default: latest)')
462
462
  .option('-p, --path <path>', `Specify the path that should be used (default: ${process.cwd()})`, process.cwd())
463
- .option('-f, --format <json>', 'File format of namespaces (default: json; [flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties])', 'json')
463
+ .option('-f, --format <json>', 'File format of namespaces (default: json; [nested, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties])', 'json')
464
464
  .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}}`)
465
465
  .option('-P, --language-folder-prefix <prefix>', 'This will be added as a local folder name prefix in front of the language.', '')
466
466
  .option('-d, --dry <true|false>', 'Dry run (default: false)', 'false')
@@ -679,7 +679,7 @@ program
679
679
  .command('format [fileOrDirectory]')
680
680
  .alias('ft')
681
681
  .description('format local files')
682
- .option('-f, --format <json>', 'File format of namespaces (default: json; [flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties])', 'json')
682
+ .option('-f, --format <json>', 'File format of namespaces (default: json; [nested, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties])', 'json')
683
683
  .option('-l, --reference-language <lng>', 'Some format conversions need to know the reference language.', 'en')
684
684
  .option('-d, --dry <true|false>', 'Dry run (default: false)', 'false')
685
685
  .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
@@ -30,6 +30,13 @@ const convertToDesiredFormat = (
30
30
  const isEmpty = !data || Object.keys(data).length === 0;
31
31
  try {
32
32
  if (opt.format === 'json') {
33
+ try {
34
+ data = unflatten(data, true);
35
+ } catch (err) {}
36
+ cb(null, JSON.stringify(data, null, 2));
37
+ return;
38
+ }
39
+ if (opt.format === 'nested') {
33
40
  try {
34
41
  data = unflatten(data);
35
42
  } catch (err) {}
@@ -22,7 +22,7 @@ const convertToFlatFormat = (opt, data, lng, cb) => {
22
22
  lng = undefined;
23
23
  }
24
24
  try {
25
- if (opt.format === 'json' || opt.format === 'flat') {
25
+ if (opt.format === 'json' || opt.format === 'nested' || opt.format === 'flat') {
26
26
  const dataString = data.toString().trim();
27
27
  if (dataString[0] !== '{' && dataString[0] !== '[') {
28
28
  return cb(new Error(`Not a valid json file: Content starts with "${dataString[0]}" but should start with "{"`));
package/formats.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const fileExtensionsMap = {
2
- '.json': ['json', 'flat'],
2
+ '.json': ['json', 'nested', 'flat'],
3
3
  '.po': ['po', 'gettext', 'po_i18next', 'gettext_i18next'],
4
4
  '.xml': ['android'],
5
5
  '.strings': ['strings'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locize-cli",
3
- "version": "7.15.2",
3
+ "version": "8.0.0",
4
4
  "description": "locize cli to import locales",
5
5
  "main": "index.js",
6
6
  "bin": {
package/unflatten.js CHANGED
@@ -1,8 +1,13 @@
1
- module.exports = (data) => {
1
+ module.exports = (data, testNatural) => {
2
2
  const result = {};
3
3
  const shouldConvertArray = {};
4
- for (var i in data) {
5
- const keys = i.split('.');
4
+ for (const i in data) {
5
+ let keys = [];
6
+ if (testNatural && /( |,|\?)/.test(i)) {
7
+ keys = [i];
8
+ } else {
9
+ keys = i.split('.');
10
+ }
6
11
  keys.reduce((r, e, j) => {
7
12
  const isNumber = !isNaN(Number(keys[j + 1]));
8
13
  const hasLeadingZero = isNumber && keys[j + 1].length > 1 && keys[j + 1][0] === '0';