@@ -34,16 +34,30 @@ correctly.
34
34
35
35
### In template files [ ᐞ] ( #table-of-contents )
36
36
37
- Translations are easy to use with ` translate ` pipe:
37
+ Translations are easy to use with ` transloco ` pipe:
38
38
39
39
``` html
40
40
<div >
41
41
<form >
42
- <button >{{ 'button.start' | translate }}</button >
42
+ <button >{{ 'button.start' | transloco }}</button >
43
43
</form >
44
44
</div >
45
45
```
46
46
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
+
47
61
Sometimes we need to have params inside the translatable string:
48
62
49
63
```json
@@ -54,23 +68,31 @@ Sometimes we need to have params inside the translatable string:
54
68
}
55
69
```
56
70
57
- Then we have to use ` [translateParams ] ` in template:
71
+ Then we have to use ` [translocoParams ] ` in template:
58
72
59
73
``` 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
63
85
```
64
86
65
87
### In TypeScript code [ᐞ](#table-of-contents)
66
88
67
89
Sometimes we have to use translatable strings straight in our code. Luckily,
68
90
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:
71
93
72
94
```typescript
73
- import { marker } from ' @biesbjerg/ngx-translate-extract- marker' ;
95
+ import { marker } from ' @jsverse/transloco-keys-manager/ marker' ;
74
96
```
75
97
76
98
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
86
108
component. e.g.
87
109
88
110
```html
89
- <p >{{ message | translate }}</p >
111
+ <p >{{ message | transloco }}</p >
90
112
```
91
113
92
114
## Workflow [ ᐞ] ( #table-of-contents )
@@ -96,30 +118,37 @@ in the $!@. Eventually some keys will be forgotten from some of our translation
96
118
files, or some keys turn out to be redundant and forgotten to be deleted.
97
119
98
120
** 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
100
122
will collect all used translation keys and add them to our translation files.
101
123
It'll also sort the JSON nicely, cleans up unused tags, and keeps the format
102
124
just like we wanted. All that just in one command:
103
125
104
126
``` bash
105
127
yarn run extract-translations
128
+
129
+ OR
130
+
131
+ make extract-translations
106
132
```
107
133
108
134
Neat right? So recommend workflow with translations is just following:
109
135
110
136
1 . Add your translations to your _ templates_ or _ code_ using that ` marker `
111
137
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
114
144
115
145
With that workflow your translation files will always be synced between
116
146
different languages and there isn't any redundant translations tags.
117
147
118
148
## Resources [ ᐞ] ( #table-of-contents )
119
149
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/ )
123
152
124
153
---
125
154
0 commit comments