Skip to content

Commit 12b8ba7

Browse files
Docs: added documentation for "custom-label-translations" command
1 parent f89eb6c commit 12b8ba7

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# hardis:misc:custom-label-translations
2+
3+
## Description
4+
5+
Extract selected custom labels, or of a given Lightning Web Component (LWC), from all language translation files. This command generates translation files (`*.translation-meta.xml`) for each language already retrieved in the current project, containing only the specified custom labels.
6+
7+
This makes it easier to:
8+
- Translate specific custom labels
9+
- Deploy specific custom label translations to another org
10+
- Manage translations for LWC components
11+
12+
## Parameters
13+
14+
| Name | Type | Description | Default | Required | Options |
15+
|:------------------|:-------:|:--------------------------------------------------------------|:-------:|:--------:|:-------:|
16+
| label<br/>-l | string | Developer name(s) of the custom label(s), comma-separated | | * | |
17+
| lwc<br/>-c | string | Developer name of the Lightning Web Component | | * | |
18+
| debug<br/>-d | boolean | Activate debug mode (more logs) | false | | |
19+
| websocket | string | Websocket host:port for VsCode SFDX Hardis UI integration | | | |
20+
| skipauth | boolean | Skip authentication check when a default username is required | | | |
21+
22+
\* Either `label` or `lwc` must be provided, not both
23+
24+
## Examples
25+
26+
```shell
27+
# Extract specific custom labels
28+
sf hardis:misc:custom-label-translations --label CustomLabelName
29+
sf hardis:misc:custom-label-translations --label Label1,Label2
30+
31+
# Extract custom labels used in a Lightning Web Component
32+
sf hardis:misc:custom-label-translations --lwc MyComponent
33+
```
34+
35+
## How It Works
36+
37+
### Example 1: Extract specific Custom Labels
38+
39+
If you have the following translation files in your project:
40+
41+
**pt_BR.translation-meta.xml** 🇧🇷
42+
```xml
43+
<?xml version="1.0" encoding="UTF-8"?>
44+
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
45+
<customLabels>
46+
<label>Teste</label>
47+
<name>Test</name>
48+
</customLabels>
49+
<customLabels>
50+
<label>Olá</label>
51+
<name>Hello</name>
52+
</customLabels>
53+
</Translations>
54+
```
55+
56+
**es.translation-meta.xml** 🇪🇸
57+
```xml
58+
<?xml version="1.0" encoding="UTF-8"?>
59+
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
60+
<customLabels>
61+
<label>Teste</label>
62+
<name>Test</name>
63+
</customLabels>
64+
<customLabels>
65+
<label>Hola</label>
66+
<name>Hello</name>
67+
</customLabels>
68+
</Translations>
69+
```
70+
71+
Running the command:
72+
```shell
73+
sf hardis:misc:custom-label-translations --label Hello
74+
```
75+
76+
Will generate the following files in `extracted-translations/extract-{timestamp}/`:
77+
78+
**pt_BR.translation-meta.xml** 🇧🇷
79+
```xml
80+
<?xml version="1.0" encoding="UTF-8"?>
81+
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
82+
<customLabels>
83+
<label>Olá</label>
84+
<name>Hello</name>
85+
</customLabels>
86+
</Translations>
87+
```
88+
89+
**es.translation-meta.xml** 🇪🇸
90+
```xml
91+
<?xml version="1.0" encoding="UTF-8"?>
92+
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
93+
<customLabels>
94+
<label>Hola</label>
95+
<name>Hello</name>
96+
</customLabels>
97+
</Translations>
98+
```
99+
100+
### Example 2: Extract from LWC
101+
102+
For a Lightning Web Component that imports custom labels:
103+
104+
```js
105+
import error from '@salesforce/label/c.error';
106+
import success from '@salesforce/label/c.success';
107+
export default class MyComponent extends LightningElement {
108+
// Component code
109+
}
110+
```
111+
112+
Running the command:
113+
```shell
114+
sf hardis:misc:custom-label-translations --lwc MyComponent
115+
```
116+
117+
Will generate the following files in `extracted-translations/MyComponent-{timestamp}/`:
118+
119+
**pt_BR.translation-meta.xml** 🇧🇷
120+
```xml
121+
<?xml version="1.0" encoding="UTF-8"?>
122+
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
123+
<customLabels>
124+
<label>Erro</label>
125+
<name>error</name>
126+
</customLabels>
127+
<customLabels>
128+
<label>Sucesso</label>
129+
<name>success</name>
130+
</customLabels>
131+
</Translations>
132+
```
133+
134+
**es.translation-meta.xml** 🇪🇸
135+
```xml
136+
<?xml version="1.0" encoding="UTF-8"?>
137+
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
138+
<customLabels>
139+
<label>Error</label>
140+
<name>error</name>
141+
</customLabels>
142+
<customLabels>
143+
<label>Éxito</label>
144+
<name>success</name>
145+
</customLabels>
146+
</Translations>
147+
```
148+
149+
## Notes
150+
151+
- The command searches for translation files in the `**/translations/` directory
152+
- Output files are created in the `extracted-translations` directory with a timestamp
153+
- When extracting labels from an LWC, the output directory name includes the LWC name

0 commit comments

Comments
 (0)