From 5bc633f67aa50e937b49b9ad345011454e325454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Pr=C3=A9vost?= Date: Mon, 29 Jan 2024 21:47:20 -0500 Subject: [PATCH] Fix documentation for fileWithParentDirectory --- cli/README.md | 19 ++++++++++++++++++- .../nested/fr/admin/general/general.json | 2 +- cli/src/services/document.ts | 9 +++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/cli/README.md b/cli/README.md index 62d3e81b1..065cb73f4 100644 --- a/cli/README.md +++ b/cli/README.md @@ -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": [ @@ -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 diff --git a/cli/examples/nested-per-language/nested/fr/admin/general/general.json b/cli/examples/nested-per-language/nested/fr/admin/general/general.json index d5df76e7e..7a9e86441 100644 --- a/cli/examples/nested-per-language/nested/fr/admin/general/general.json +++ b/cli/examples/nested-per-language/nested/fr/admin/general/general.json @@ -1,3 +1,3 @@ { "key": "value" -} \ No newline at end of file +} diff --git a/cli/src/services/document.ts b/cli/src/services/document.ts index a5890c908..7e7424c55 100644 --- a/cli/src/services/document.ts +++ b/cli/src/services/document.ts @@ -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) {