Skip to content

Commit

Permalink
Fix documentation for fileWithParentDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
simonprev committed Jan 30, 2024
1 parent 1a7c261 commit 5bc633f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
19 changes: 18 additions & 1 deletion cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ Each operation section `sync` and `addTranslations` can contain the following ob
}
```

`fileWithParentDirectory`: Use the path of the file in addition to the file name. This is useful if you want to keep your file i multiple nested directories, per language. Use the position of the `%slug%` placeholder in the `target` as the root of the path.
`fileWithParentDirectory`: Use the path of the file in addition to the file name. This is useful if you want to keep your file in multiple nested directories, per language. Use the position of the `%slug%` placeholder in the `target` as the root of the path.

```
{
"files": [
Expand All @@ -141,6 +142,22 @@ Each operation section `sync` and `addTranslations` can contain the following ob
}
```

Given this configuration and a file layout like this:

```
my-project/
accent.json
translations/
en/
foo/
locales.json
fr/
foo/
locales.json
```

The document name in Accent will be named `foo/locales`.

## Hooks

Here is a list of available hooks. Those are self-explanatory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"key": "value"
}
}
9 changes: 7 additions & 2 deletions cli/src/services/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,13 @@ export default class Document {
if (config.namePattern === NamePattern.fileWithParentDirectory) {
const languageIndex = config.target.split(path.sep).indexOf('%slug%') + 1;
const pathParts = file.split(path.sep);
const resultPath = pathParts.splice(languageIndex, pathParts.length - languageIndex - 1);
return resultPath.length > 0 ? resultPath.join(path.sep).concat(path.sep).concat(basename) : basename;
const resultPath = pathParts.splice(
languageIndex,
pathParts.length - languageIndex - 1
);
return resultPath.length > 0
? resultPath.join(path.sep).concat(path.sep).concat(basename)
: basename;
}

if (config.namePattern === NamePattern.fileWithSlugSuffix) {
Expand Down

0 comments on commit 5bc633f

Please sign in to comment.