Skip to content

Commit ae3cace

Browse files
authored
feat: add files template option (#882)
1 parent 1483d8f commit ae3cace

File tree

2 files changed

+52
-43
lines changed

2 files changed

+52
-43
lines changed

tolgee-cli/project-configuration.mdx

+36-26
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ Example configuration:
1414
"format": "JSON_TOLGEE",
1515
"patterns": ["./src/**/*.ts?(x)"],
1616
"push": {
17-
"files": [{
18-
"path": "./public/i18n/en.json",
19-
"language": "en"
20-
}],
17+
"filesTemplate": "./public/i18n/{languageTag}.json",
18+
"language": ["en"],
2119
"forceMode": "OVERRIDE",
2220
},
2321
"pull": {
@@ -92,7 +90,7 @@ file.
9290

9391
### `patterns`
9492

95-
List&ltString&gt. File glob patterns to your source code, used for key extraction.
93+
List[String]. File glob patterns to your source code, used for key extraction.
9694

9795
### `strictNamespace`
9896

@@ -104,24 +102,40 @@ String. Default namespace used in extraction if not specified otherwise.
104102

105103
### `parser`
106104

107-
Enum&lt`react`|`vue`|`svelte`&gt. Tolgee detects which parser to use automatically from the extensions of matched files, with this option you can override it.
105+
Enum[`react`|`vue`|`svelte`]. Tolgee detects which parser to use automatically from the extensions of matched files, with this option you can override it.
108106

109107

110108
## Push options
111109

112110
Related to `push` command, which imports the keys into the platform.
113111

112+
### `push.filesTemplate`
113+
114+
String or String[]. A template that describes the structure of the local files and their location.
115+
116+
Example: `./public/{namespace}/{languageTag}.json`
117+
118+
Full syntax is explained [here](./push-pull-strings.mdx#file-structure-template-format)
119+
114120
### `push.files`
115121

122+
More explicit alternative to `filesTemplate`.
123+
116124
`List<{path: string, language: string, namespace?: string}>`. Define, which files should be pushed and attach language/namespace to them. By default Tolgee pushes all files specified here, you can filter them by `languages` and `namespaces` properties. Path can be a glob, if you want to include multiple files.
117125

126+
:::info `push.filesTemplate` vs `push.files`
127+
We recommend usage of [`push.filesTemplate`](#pushfilestemplate), which can describe your local localization file structure
128+
with single option. `push.files` requires you to specify each pushed file individually, but can be useful, if you have a weird file
129+
structure or you want to remap language tags.
130+
:::
131+
118132
### `push.languages`
119133

120-
List&ltString&gt. Specifies which languages should be pushed from `push.files`.
134+
List[String]. Specifies which languages should be pushed from `push.files`.
121135

122136
### `push.namespaces`
123137

124-
List&ltString&gt. Specifies which namespaces should be pushed from `push.files`.
138+
List[String]. Specifies which namespaces should be pushed from `push.files`.
125139

126140
### `push.forceMode`
127141

@@ -142,7 +156,7 @@ Boolean. Convert placeholders in local files to ICU format. (Default: `true`)
142156

143157
### `push.tagNewKeys`
144158

145-
List&ltString&gt. Specify tags that will be added to newly created keys.
159+
List[String]. Specify tags that will be added to newly created keys.
146160

147161
### `push.removeOtherKeys`
148162

@@ -165,23 +179,23 @@ behavior by specifying `null` or empty string `""`.
165179

166180
### `pull.languages`
167181

168-
List&ltString&gt. List of languages to pull. Leave unspecified to export them all.
182+
List[String]. List of languages to pull. Leave unspecified to export them all.
169183

170184
### `pull.namespaces`
171185

172-
List&ltString&gt. List of namespaces to pull. Defaults to all namespaces.
186+
List[String]. List of namespaces to pull. Defaults to all namespaces.
173187

174188
### `pull.states`
175189

176-
List&ltString&gt. List of translation states to include. Defaults all except untranslated.
190+
List[String]. List of translation states to include. Defaults all except untranslated.
177191

178192
### `pull.tags`
179193

180-
List&ltString&gt. List of tags which to include.
194+
List[String]. List of tags which to include.
181195

182196
### `pull.excludeTags`
183197

184-
List&ltString&gt. List of tags which to exclude.
198+
List[String]. List of tags which to exclude.
185199

186200
### `pull.supportArrays`
187201

@@ -191,13 +205,9 @@ Boolean. Export keys with array syntax (e.g. `item[0]`) as arrays.
191205

192206
String. This is a template that defines the structure of the resulting .zip file content.
193207

194-
The template is a string that can contain the following placeholders: `{namespace}`, `{languageTag}`, `{androidLanguageTag}`, `{snakeLanguageTag}`, `{extension}`.
195-
196-
For example, when exporting to JSON with the template `{namespace}/{languageTag}.{extension}`, the English translations of the home namespace will be stored in home/en.json.
197-
198-
The `{snakeLanguageTag}` placeholder is the same as `{languageTag}` but in snake case. (e.g., en_US).
208+
Example: `{namespace}/{languageTag}.{extension}`
199209

200-
The Android specific `{androidLanguageTag}` placeholder is the same as `{languageTag}` but in Android format. (e.g., en-rUS)
210+
Full syntax is explained [here](./push-pull-strings.mdx#file-structure-template-format)
201211

202212
### `pull.emptyDir`
203213

@@ -229,24 +239,24 @@ Boolean. Extract keys from code and filter them out.
229239

230240
### `tag.filterTag`
231241

232-
List&ltString&gt. Filter only keys with tag. Use * as a wildcard.
242+
List[String]. Filter only keys with tag. Use * as a wildcard.
233243

234244
### `tag.filterNoTag`
235245

236-
List&ltString&gt. Filter only keys without tag. Use * as a wildcard.
246+
List[String]. Filter only keys without tag. Use * as a wildcard.
237247

238248
### `tag.tag`
239249

240-
List&ltString&gt. Add tag to filtered keys.
250+
List[String]. Add tag to filtered keys.
241251

242252
### `tag.tagOther`
243253

244-
List&ltString&gt. Tag keys which are not filtered.
254+
List[String]. Tag keys which are not filtered.
245255

246256
### `tag.untag`
247257

248-
List&ltString&gt. Remove tag from filtered keys. Use * as a wildcard.
258+
List[String]. Remove tag from filtered keys. Use * as a wildcard.
249259

250260
### `tag.untagOther`
251261

252-
List&ltString&gt. Remove tag from keys which are not filtered. Use * as a wildcard.
262+
List[String]. Remove tag from keys which are not filtered. Use * as a wildcard.

tolgee-cli/push-pull-strings.mdx

+16-17
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,7 @@ Options:
3131
- `--exclude-tags <tags...>` - List of tags which to exclude. Keys tagged by at least one of these tags will be excluded.
3232
- `--support-arrays` - Export keys with array syntax (e.g. item[0]) as arrays. (default: false)
3333
- `--empty-dir` - Empty target directory before inserting pulled files.
34-
- `--file-structure-template <template>` - [Defines exported file structure](#file-structure-template-format)
35-
36-
### File structure template format
37-
This is a template that defines the structure of the resulting .zip file content.
38-
39-
The template is a string that can contain the following placeholders: `{namespace}`, `{languageTag}`, `{androidLanguageTag}`, `{snakeLanguageTag}`, `{extension}`.
40-
41-
For example, when exporting to JSON with the template `{namespace}`/`{languageTag}`.`{extension}`, the English translations of the home namespace will be stored in home/en.json.
42-
43-
The `{snakeLanguageTag}` placeholder is the same as `{languageTag}` but in snake case. (e.g., en_US).
44-
45-
The Android specific `{androidLanguageTag}` placeholder is the same as `{languageTag}` but in Android format. (e.g., en-rUS)
34+
- `--file-structure-template <template>` - [Defines exported file structure](#file-structure-template-format).
4635

4736
## Pushing strings
4837

@@ -55,16 +44,26 @@ Example usage:
5544
tolgee push --force-mode OVERRIDE
5645
```
5746

58-
:::info
59-
Push command requires [`push.files`](./project-configuration.mdx#pushfiles) in config (which specifies which files to import).
60-
:::
61-
6247
Options:
63-
48+
- `--files-template <templates...>` (short: `-ft`) - A template that describes the structure of the local files and their location with [file structure template format](#file-structure-template-format). Example: `./public/{namespace}/{languageTag}.json`
6449
- `--force-mode <mode>` (short: `-f`) – What should we do with possible conflicts? Available modes: `OVERRIDE`, `KEEP`, `NO_FORCE` (abort on conflicts). Defaults to asking the user interactively (or `NO_FORCE` if it is not possible).
6550
- `--override-key-descriptions` - Override existing key descriptions from local files (only relevant for some formats).
6651
- `--convert-placeholders-to-icu` - Convert placeholders in local files to ICU format. (Default: true)
6752
- `--languages <languages...>` (short `-l`) - Specifies which languages should be pushed (see `push.files` in config).
6853
- `--namespaces <namespaces...>` (short `-n`) - Specifies which namespaces should be pushed (see `push.files` in config).
6954
- `--tag-new-keys <tags...>` - Specify tags that will be added to newly created keys.
7055
- `--remove-other-keys` - Remove keys which are not present in the import.
56+
57+
58+
### File structure template format
59+
This is a template that defines the structure of static files and mapping them to languages/namespaces.
60+
61+
The template is a string that can contain the following placeholders: `{namespace}`, `{languageTag}`, `{androidLanguageTag}`, `{snakeLanguageTag}`, `{extension}`.
62+
63+
For example, when exporting to JSON with the template `{namespace}`/`{languageTag}`.`{extension}`, the English translations of the home namespace will be stored in home/en.json.
64+
65+
The `{snakeLanguageTag}` placeholder is the same as `{languageTag}` but in snake case. (e.g., en_US).
66+
67+
The Android specific `{androidLanguageTag}` placeholder is the same as `{languageTag}` but in Android format. (e.g., en-rUS)
68+
69+
> `--files-template` option also allows usage of glob wildcards as (`*`, `**` or `{json,yaml}`)

0 commit comments

Comments
 (0)