Skip to content

Commit 4e7ad0b

Browse files
committed
docs(localization): document translate CLI key extraction
Move the update-translatable-keys CLI usage and config documentation from the element-translate-ng README into the localization docs and note that the CLI ships as the @siemens/element-translate-cli package.
1 parent b200ce2 commit 4e7ad0b

2 files changed

Lines changed: 53 additions & 37 deletions

File tree

docs/fundamentals/localization.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,51 @@ Note that this hash key will only be appended to the translation based JSON file
264264
### Translatable keys in Element
265265

266266
<si-docs-type name="SiTranslatableKeys"></si-docs-type>
267+
268+
### Extracting translatable keys
269+
270+
An important part of the translation tooling is the extraction of translatable keys as a TypeScript
271+
interface as well as the extraction of a JSON messages file with default translations. This is
272+
provided by the `@siemens/element-translate-cli` package, which exposes the
273+
`update-translatable-keys` command. Install it as a dev dependency:
274+
275+
```sh
276+
npm install --save-dev @siemens/element-translate-cli
277+
```
278+
279+
The extraction happens on compiled files. I.e. make sure to run the build first. Then, to run these
280+
extractions:
281+
282+
```sh
283+
npx update-translatable-keys
284+
```
285+
286+
By default, this will pick up the configuration from a file `element-translate.conf.json`. To use a
287+
different config file, pass it as the only argument to the command.
288+
289+
The config file looks like this:
290+
291+
```json
292+
{
293+
"files": "dist/@simpl/**/fesm2022/**/*.mjs",
294+
"configs": [
295+
{
296+
"name": "element",
297+
"locationPrefix": "projects/element-ng",
298+
"keysFile": "projects/element-ng/translate/si-translatable-keys.interface.ts",
299+
"keysInterfaceName": "SiTranslatableKeys",
300+
"messagesFile": "dist/@siemens/element-ng/template-i18n.json"
301+
}
302+
]
303+
}
304+
```
305+
306+
- `files` is a glob pattern for defining the files to scan.
307+
- `configs` is an array of configs. For mono-repos building multiple libraries, they can be
308+
separated into different configs. All keys are required:
309+
- `name` is a unique name.
310+
- `locationPrefix` defines the path prefix of the source files, important to distinguish between
311+
different libraries in a mono-repo.
312+
- `keysFile` defines the path of the generated TypeScript interfaces file.
313+
- `keysInterfaceName` defines the name of the TypeScript `interface`.
314+
- `messagesFile` defines the path of the generated messages JSON file.

projects/element-translate-ng/README.md

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,11 @@ Install the library as follows:
1717
npm install --save @siemens/element-translate-ng
1818
```
1919

20-
An important part of the library is the extraction of translatable keys as a TypeScript interface
21-
as well as extracting a JSON messages file with default translations. The extraction happens on
22-
compiled files. I.e. make sure to run the build first. Then, to run these extractions
23-
24-
```sh
25-
npx update-translatable-keys
26-
```
27-
28-
By default, this will pick of the configuration from a file `element-translate.conf.json`. To
29-
use a different config file, pass as the only argument to the command.
30-
31-
The config file looks like this
32-
33-
```json
34-
{
35-
"files": "dist/@simpl/**/fesm2022/**/*.mjs",
36-
"configs": [
37-
{
38-
"name": "element",
39-
"locationPrefix": "projects/element-ng",
40-
"keysFile": "projects/element-ng/translate/si-translatable-keys.interface.ts",
41-
"keysInterfaceName": "SiTranslatableKeys",
42-
"messagesFile": "dist/@siemens/element-ng/template-i18n.json"
43-
}
44-
]
45-
}
46-
```
47-
48-
- `files` is a glob pattern for defining the files to scan
49-
- `configs` is an array of configs. For mono-repos building multiple libraries, they can be
50-
separated into different configs. All keys are required:
51-
- `name` is a unique name
52-
- `locationsPrefix` defines the path prefix of the source files, important to distinguish
53-
between different libraries in a mono-repo
54-
- `keysFile` defines the path of the generated TypeScript interfaces file
55-
- `keysInterfaceName` defines the name of the TypeScript `interface`
56-
- `messagesFile` defines the path of the generated messages JSON file
20+
An important part of the translation tooling is the extraction of translatable keys as a TypeScript
21+
interface as well as extracting a JSON messages file with default translations. This is provided by
22+
the separate `@siemens/element-translate-cli` package via the `update-translatable-keys` CLI. See
23+
[Extracting translatable keys](https://element.siemens.io/fundamentals/localization/#extracting-translatable-keys)
24+
for details on how to run it and how to configure it.
5725

5826
## Testing
5927

0 commit comments

Comments
 (0)