Skip to content

Commit aa92418

Browse files
authored
fix(transloco): 🐛 fix message format delay (#634)
1 parent 76ecfd1 commit aa92418

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

apps/transloco-playground-e2e/src/integration/transpilers.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export function testTranspilersContent(lang = 'english') {
1111
);
1212
cy.get(`[data-cy=with-message-format]`).should(
1313
'contain',
14-
`The boy named Henkie won his race - ${lang}`
14+
`The boy named Henkie won his race and ${lang === 'english' ? '€1,000.00' : '1000,00\u00A0€'} - ${lang}`
1515
);
1616
cy.get(`[data-cy=with-message-format-dynamic]`).should(
1717
'contain',
18-
`The girl named Kim won her race - ${lang}`
18+
`The girl named Kim won her race and ${lang === 'english' ? '€2,000.00' : '2000,00\u00A0€'} - ${lang}`
1919
);
2020
cy.get(`[data-cy=with-message-format-params]`).should(
2121
'contain',
22-
`Can replace transloco params and also give parse messageformat: The person named Joko won their race - ${lang}`
22+
`Can replace transloco params and also give parse messageformat: The person named Joko won their race and ${lang === 'english' ? '€3,000.00' : '3000,00\u00A0€'} - ${lang}`
2323
);
2424

2525
// Directive
@@ -34,15 +34,15 @@ export function testTranspilersContent(lang = 'english') {
3434
);
3535
cy.get(`[data-cy=d-with-message-format]`).should(
3636
'contain',
37-
`The boy named Pete won his race - ${lang}`
37+
`The boy named Pete won his race and ${lang === 'english' ? '€1,100.00' : '1100,00\u00A0€'} - ${lang}`
3838
);
3939
cy.get(`[data-cy=d-with-message-format-dynamic]`).should(
4040
'contain',
41-
`The girl named Maxime won her race - ${lang}`
41+
`The girl named Maxime won her race and ${lang === 'english' ? '€2,100.00' : '2100,00\u00A0€'} - ${lang}`
4242
);
4343
cy.get(`[data-cy=d-with-message-format-params]`).should(
4444
'contain',
45-
`Can replace transloco params and also give parse messageformat: The person named Ono won their race - ${lang}`
45+
`Can replace transloco params and also give parse messageformat: The person named Ono won their race and ${lang === 'english' ? '€3,100.00' : '3100,00\u00A0€'} - ${lang}`
4646
);
4747

4848
// Dynamic params
@@ -69,14 +69,14 @@ export function testTranspilersContent(lang = 'english') {
6969
);
7070
cy.get(`[data-cy=p-with-message-format]`).should(
7171
'contain',
72-
`The boy named Stef won his race - ${lang}`
72+
`The boy named Stef won his race and ${lang === 'english' ? '€1,200.00' : '1200,00\u00A0€'} - ${lang}`
7373
);
7474
cy.get(`[data-cy=p-with-message-format-dynamic]`).should(
7575
'contain',
76-
`The girl named Donna won her race - ${lang}`
76+
`The girl named Donna won her race and ${lang === 'english' ? '€2,200.00' : '2200,00\u00A0€'} - ${lang}`
7777
);
7878
cy.get(`[data-cy=p-with-message-format-params]`).should(
7979
'contain',
80-
`Can replace transloco params and also give parse messageformat: The person named Mary won their race - ${lang}`
80+
`Can replace transloco params and also give parse messageformat: The person named Mary won their race and ${lang === 'english' ? '€3,200.00' : '3200,00\u00A0€'} - ${lang}`
8181
);
8282
}

apps/transloco-playground/src/app/transpilers/transpilers.component.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ <h4>Structural Directive</h4>
1414
</li>
1515
<li class="list-group-item" data-cy="with-message-format">
1616
<b>Using messageformat: </b
17-
>{{ t('mf.messageFormat', { gender: 'male', name: 'Henkie' }) }}
17+
>{{ t('mf.messageFormat', { gender: 'male', name: 'Henkie', gain: 1000 }) }}
1818
</li>
1919
<li class="list-group-item" data-cy="with-message-format-dynamic">
2020
<b>Using messageformat with dynamic value: </b
21-
>{{ t('mf.messageFormat', { gender: userGender, name: 'Kim' }) }}
21+
>{{ t('mf.messageFormat', { gender: userGender, name: 'Kim', gain: 2000 }) }}
2222
</li>
2323
<li class="list-group-item" data-cy="with-message-format-params">
2424
<b>Using messageformat with transloco standard params: </b
2525
>{{
2626
t('mf.messageFormatWithParams', {
2727
value: 'transloco params',
2828
gender: '',
29-
name: 'Joko'
29+
name: 'Joko',
30+
gain: 3000
3031
})
3132
}}
3233
</li>
@@ -49,21 +50,21 @@ <h3 class="mtb">Directive</h3>
4950
<b>Using messageformat: </b>
5051
<span
5152
transloco="mf.messageFormat"
52-
[translocoParams]="{ gender: 'male', name: 'Pete' }"
53+
[translocoParams]="{ gender: 'male', name: 'Pete', gain: 1100 }"
5354
></span>
5455
</li>
5556
<li class="list-group-item" data-cy="d-with-message-format-dynamic">
5657
<b>Using messageformat with dynamic value: </b>
5758
<span
5859
transloco="mf.messageFormat"
59-
[translocoParams]="{ gender: userGender, name: 'Maxime' }"
60+
[translocoParams]="{ gender: userGender, name: 'Maxime', gain: 2100 }"
6061
></span>
6162
</li>
6263
<li class="list-group-item" data-cy="d-with-message-format-params">
6364
<b>Using messageformat with transloco standard params: </b>
6465
<span
6566
transloco="mf.messageFormatWithParams"
66-
[translocoParams]="{ value: 'transloco params', gender: '', name: 'Ono' }"
67+
[translocoParams]="{ value: 'transloco params', gender: '', name: 'Ono', gain: 3100 }"
6768
></span>
6869
</li>
6970
</ul>
@@ -81,17 +82,17 @@ <h3 class="mtb">Pipe</h3>
8182
</li>
8283
<li class="list-group-item" data-cy="p-with-message-format">
8384
<b>Using messageformat: </b
84-
>{{ 'mf.messageFormat' | transloco: { gender: 'male', name: 'Stef' } }}
85+
>{{ 'mf.messageFormat' | transloco: { gender: 'male', name: 'Stef', gain: 1200 } }}
8586
</li>
8687
<li class="list-group-item" data-cy="p-with-message-format-dynamic">
8788
<b>Using messageformat with dynamic value: </b
88-
>{{ 'mf.messageFormat' | transloco: { gender: userGender, name: 'Donna' } }}
89+
>{{ 'mf.messageFormat' | transloco: { gender: userGender, name: 'Donna', gain: 2200 } }}
8990
</li>
9091
<li class="list-group-item" data-cy="p-with-message-format-params">
9192
<b>Using messageformat with transloco standard params: </b
9293
>{{
9394
'mf.messageFormatWithParams'
94-
| transloco: { value: 'transloco params', gender: '', name: 'Mary' }
95+
| transloco: { value: 'transloco params', gender: '', name: 'Mary', gain: 3200 }
9596
}}
9697
</li>
9798
</ul>

apps/transloco-playground/src/assets/i18n/transpilers/messageformat/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"home": "Home - english",
33
"params": "Replaces standard {{value}} - english",
4-
"messageFormat": "The {gender, select, male {boy named {{name}} won his} female {girl named {{name}} won her} other {person named {{name}} won their}} race - english",
5-
"messageFormatWithParams": "Can replace {{value}} and also give parse messageformat: The {gender, select, male {boy named {{name}} won his} female {girl named {{name}} won her} other {person named {{name}} won their}} race - english",
4+
"messageFormat": "The {gender, select, male {boy named {{name}} won his} female {girl named {{name}} won her} other {person named {{name}} won their}} race and {gain, number, ::currency/EUR unit-width-narrow} - english",
5+
"messageFormatWithParams": "Can replace {{value}} and also give parse messageformat: The {gender, select, male {boy named {{name}} won his} female {girl named {{name}} won her} other {person named {{name}} won their}} race and {gain, number, ::currency/EUR unit-width-narrow} - english",
66
"fromList": "from list",
77
"a": {
88
"b": {

apps/transloco-playground/src/assets/i18n/transpilers/messageformat/es.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"home": "Home - spanish",
33
"params": "Replaces standard {{value}} - spanish",
4-
"messageFormat": "The {gender, select, male {boy named {{name}} won his} female {girl named {{name}} won her} other {person named {{name}} won their}} race - spanish",
5-
"messageFormatWithParams": "Can replace {{value}} and also give parse messageformat: The {gender, select, male {boy named {{name}} won his} female {girl named {{name}} won her} other {person named {{name}} won their}} race - spanish",
4+
"messageFormat": "The {gender, select, male {boy named {{name}} won his} female {girl named {{name}} won her} other {person named {{name}} won their}} race and {gain, number, ::currency/EUR unit-width-narrow} - spanish",
5+
"messageFormatWithParams": "Can replace {{value}} and also give parse messageformat: The {gender, select, male {boy named {{name}} won his} female {girl named {{name}} won her} other {person named {{name}} won their}} race and {gain, number, ::currency/EUR unit-width-narrow} - spanish",
66
"fromList": "from list",
77
"a": {
88
"b": {

libs/transloco/src/lib/transloco.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ export class TranslocoService implements OnDestroy {
167167
}
168168

169169
setActiveLang(lang: string) {
170-
this.lang.next(lang);
171170
this.parser.onLangChanged?.(lang);
171+
this.lang.next(lang);
172172
this.events.next({
173173
type: 'langChanged',
174174
payload: getEventPayload(lang),

0 commit comments

Comments
 (0)