Skip to content

Commit

Permalink
new format: yaml-nested
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed May 25, 2020
1 parent af29fd1 commit e9bf2eb
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
Project versioning adheres to [Semantic Versioning](http://semver.org/).
Change log format is based on [Keep a Changelog](http://keepachangelog.com/).

## [7.3.0](https://github.com/locize/locize-cli/compare/v7.2.2...v7.3.0) - 2020-05-25

- new format: yaml-nested


## [7.2.2](https://github.com/locize/locize-cli/compare/v7.2.1...v7.2.2) - 2020-05-09

- fix sync for special path-masks, when having parallel files
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ or
locize download
```

or add a format like (json, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties)
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)

```sh
locize download --project-id my-project-id-93e1-442a-ab35-24331fa294ba --ver latest --language en --namespace namespace1 --path ./backup --format android
Expand Down Expand Up @@ -116,7 +116,7 @@ Add your api-key and your project-id and let's go...
locize sync --api-key my-api-key-d9de-4f55-9855-a9ef0ed44672 --project-id my-project-id-93e1-442a-ab35-24331fa294ba
```

or add a format like (json, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties)
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)

```sh
locize sync --api-key my-api-key-d9de-4f55-9855-a9ef0ed44672 --project-id my-project-id-93e1-442a-ab35-24331fa294ba --format android
Expand Down
6 changes: 3 additions & 3 deletions bin/locize
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ program
.option('-p, --path <path>', `Specify the path that should be used (default: ${process.cwd()})`, process.cwd())
.option('-g, --get-path <url>', `Specify the get-path url that should be used (default: ${getPathUrl})`)
.option('-k, --api-key <apiKey>', 'The api-key that should be used')
.option('-f, --format <json>', 'File format of namespaces (default: json; [flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties])', 'json')
.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')
.option('-s, --skip-empty <true|false>', 'Skips to download empty files (default: true)', 'true')
.option('-P, --language-folder-prefix <prefix>', 'This will be added as a local folder name prefix in front of the language.', '')
.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}}`)
Expand Down Expand Up @@ -361,7 +361,7 @@ program
.option('-i, --project-id <projectId>', 'The project-id that should be used')
.option('-v, --ver <version>', 'Found namespaces will be matched to this version (default: latest)')
.option('-p, --path <path>', `Specify the path that should be used (default: ${process.cwd()})`, process.cwd())
.option('-f, --format <json>', 'File format of namespaces (default: json; [flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties])', 'json')
.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')
.option('-s, --skip-empty <true|false>', 'Skips to download empty files (default: false)', 'false')
.option('-c, --clean <true|false>', 'Removes all local files (default: false)', 'false')
.option('-u, --update-values <true|false>', 'This will update values of existing translations. (default: false)', 'false')
Expand Down Expand Up @@ -607,7 +607,7 @@ program
.command('format [fileOrDirectory]')
.alias('ft')
.description('format local files')
.option('-f, --format <json>', 'File format of namespaces (default: json; [flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties])', 'json')
.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')
.option('-l, --reference-language <lng>', 'Some format conversions need to know the reference language.', 'en')
.option('-d, --dry <true|false>', 'Dry run (default: false)', 'false')
.option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${workingDirectory} or ${home})`)
Expand Down
4 changes: 4 additions & 0 deletions convertToDesiredFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ const convertToDesiredFormat = (
cb(null, jsyaml.safeDump(flatten(data)));
return;
}
if (opt.format === 'yaml-nested') {
cb(null, jsyaml.safeDump(shouldUnflatten(data) ? unflatten(data) : data));
return;
}
if (opt.format === 'yaml-rails') {
var newData = {};
newData[lng] = {};
Expand Down
4 changes: 4 additions & 0 deletions convertToFlatFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ const convertToFlatFormat = (opt, data, lng, cb) => {
cb(null, flatten(jsyaml.safeLoad(data)));
return;
}
if (opt.format === 'yaml-nested') {
cb(null, flatten(jsyaml.safeLoad(data)));
return;
}
if (opt.format === 'yaml-rails') {
const jsObj = jsyaml.safeLoad(data);
cb(
Expand Down
2 changes: 1 addition & 1 deletion formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fileExtensionsMap = {
'.strings': ['strings'],
'.csv': ['csv'],
'.resx': ['resx'],
'.yaml': ['yaml', 'yaml-rails'],
'.yaml': ['yaml', 'yaml-rails', 'yaml-nested'],
'.xlsx': ['xlsx'],
'.xliff': ['xliff2', 'xliff12'],
'.xlf': ['xlf2', 'xlf12'],
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"fluent_conv": "3.0.0",
"gettext-converter": "1.0.3",
"ini": "1.3.5",
"js-yaml": "3.13.1",
"js-yaml": "3.14.0",
"laravelphp": "2.0.2",
"lodash.clonedeep": "4.5.0",
"mkdirp": "1.0.4",
Expand All @@ -28,10 +28,10 @@
"strings-file": "0.0.5",
"tmexchange": "2.0.3",
"xliff": "5.0.5",
"xlsx": "0.16.0"
"xlsx": "0.16.1"
},
"devDependencies": {
"eslint": "6.8.0",
"eslint": "7.1.0",
"gh-release": "3.5.0",
"pkg": "4.4.8"
},
Expand Down

0 comments on commit e9bf2eb

Please sign in to comment.