Skip to content

Commit f906ba4

Browse files
authored
Merge pull request #3486 from tarlepp/chore(doc)/update-translation-doc
Chore(doc) - Update translation documentation
2 parents 7c0f46d + 886600b commit f906ba4

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

doc/TRANSLATIONS.md

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,30 @@ correctly.
3434

3535
### In template files [](#table-of-contents)
3636

37-
Translations are easy to use with `translate` pipe:
37+
Translations are easy to use with `transloco` pipe:
3838

3939
```html
4040
<div>
4141
<form>
42-
<button>{{ 'button.start' | translate }}</button>
42+
<button>{{ 'button.start' | transloco }}</button>
4343
</form>
4444
</div>
4545
```
4646

47+
Another way is to use _structural directive_ like:
48+
49+
```html
50+
<ng-container *transloco="let t">
51+
<div>
52+
<form>
53+
<button>{{ t('button.start') }}</button>
54+
</form>
55+
</div>
56+
</ng-container>
57+
```
58+
59+
```html
60+
4761
Sometimes we need to have params inside the translatable string:
4862

4963
```json
@@ -54,23 +68,31 @@ Sometimes we need to have params inside the translatable string:
5468
}
5569
```
5670

57-
Then we have to use `[translateParams]` in template:
71+
Then we have to use `[translocoParams]` in template:
5872

5973
```html
60-
<h1 translate
61-
[translateParams]="{name: 'Arnold'}"
62-
>example.greeting</h1>
74+
<h1 [transloco]="'example.greeting'"
75+
[translocoParams]="{ name: 'Arnold' }"
76+
></h1>
77+
```
78+
79+
Or with _structural directive_ like:
80+
81+
```html
82+
<ng-container *transloco="let t">
83+
<h1>{{ t('example.greeting', { name: 'Arnold' }) }}</h1>
84+
</ng-container
6385
```
6486

6587
### In TypeScript code [ᐞ](#table-of-contents)
6688

6789
Sometimes we have to use translatable strings straight in our code. Luckily,
6890
there is a way to easily maintain these strings with the
69-
`@biesbjerg/ngx-translate-extract` package. What you need to do in the code, is
70-
to first import the marker function:
91+
`@jsverse/transloco-keys-manager/marker` package. What you need to do in the
92+
code, is to first import the marker function:
7193

7294
```typescript
73-
import { marker } from '@biesbjerg/ngx-translate-extract-marker';
95+
import { marker } from '@jsverse/transloco-keys-manager/marker';
7496
```
7597

7698
Then, when you need to use a string in code, wrap it with the marker function.
@@ -86,7 +108,7 @@ This `message` variable can now be used as a normal translation tag in
86108
component. e.g.
87109

88110
```html
89-
<p>{{ message | translate }}</p>
111+
<p>{{ message | transloco }}</p>
90112
```
91113

92114
## Workflow [](#table-of-contents)
@@ -96,30 +118,37 @@ in the $!@. Eventually some keys will be forgotten from some of our translation
96118
files, or some keys turn out to be redundant and forgotten to be deleted.
97119

98120
**Fortunately** we have a tool to be used when working with translations.
99-
`@biesbjerg/ngx-translate-extract` is set up in the application so, that it
121+
`@jsverse/transloco-keys-manager` is set up in the application so, that it
100122
will collect all used translation keys and add them to our translation files.
101123
It'll also sort the JSON nicely, cleans up unused tags, and keeps the format
102124
just like we wanted. All that just in one command:
103125

104126
```bash
105127
yarn run extract-translations
128+
129+
OR
130+
131+
make extract-translations
106132
```
107133

108134
Neat right? So recommend workflow with translations is just following:
109135

110136
1. Add your translations to your _templates_ or _code_ using that `marker`
111137
function.
112-
2. Run `yarn run extract-translations` command.
113-
3. Open your translation files and fill out those empty spots.
138+
1. Run `yarn run extract-translations` OR `make extract-translations`
139+
command.
140+
1. Open your translation files under `translations` and fill out those
141+
empty spots.
142+
1. After that you need to run `yarn run sync-translations` OR
143+
`make sync-translations` command
114144

115145
With that workflow your translation files will always be synced between
116146
different languages and there isn't any redundant translations tags.
117147

118148
## Resources [](#table-of-contents)
119149

120-
* [Great tutorial](https://www.codeandweb.com/babeledit/tutorials/how-to-translate-your-angular7-app-with-ngx-translate)
121-
* [Github](https://github.com/ngx-translate/core)
122-
* [Ngx-Translate home page](http://www.ngx-translate.com/)
150+
* [Github](https://github.com/jsverse/transloco/)
151+
* [Transloco home page](https://jsverse.github.io/transloco/)
123152

124153
---
125154

0 commit comments

Comments
 (0)