You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #945 fix(translator): generate unique constants name (fix#938) (Kocal)
This PR was merged into the 2.x branch.
Discussion
----------
fix(translator): generate unique constants name (fix#938)
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| Tickets | Fix#938 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License | MIT
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.
Additionally (see https://symfony.com/releases):
- Always add tests and ensure they pass.
- Never break backward compatibility (see https://symfony.com/bc).
- Features and deprecations must be submitted against branch main.
-->
Generating constants name with a automatic-prefix, in order to prevent conflicts when they are dumped in JS.
Commits
-------
7f12e9c fix(translator): generate unique constants name (fix#938)
Copy file name to clipboardExpand all lines: src/Translator/tests/TranslationsDumperTest.php
+20Lines changed: 20 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -40,10 +40,13 @@ public function testDump(): void
40
40
'notification.comment_created' => 'Your post received a comment!',
41
41
'notification.comment_created.description' => 'Your post "{title}" has received a new comment. You can read the comment by following <a href="{link}">this link</a>',
42
42
'post.num_comments' => '{count, plural, one {# comment} other {# comments}}',
43
+
'post.num_comments.' => '{count, plural, one {# comment} other {# comments}} (should not conflict with the previous one.)',
43
44
],
44
45
'messages' => [
45
46
'symfony.great' => 'Symfony is awesome!',
46
47
'symfony.what' => 'Symfony is %what%!',
48
+
'symfony.what!' => 'Symfony is %what%! (should not conflict with the previous one.)',
49
+
'symfony.what.' => 'Symfony is %what%. (should also not conflict with the previous one.)',
47
50
'apples.count.0' => 'There is 1 apple|There are %count% apples',
48
51
'apples.count.1' => '{1} There is one apple|]1,Inf] There are %count% apples',
49
52
'apples.count.2' => '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples',
@@ -53,6 +56,8 @@ public function testDump(): void
53
56
'what.count.2' => '{0} There are no %what%|{1} There is one %what%|]1,Inf] There are %count% %what%',
54
57
'what.count.3' => 'one: There is one %what%|more: There are %count% %what%',
55
58
'what.count.4' => 'one: There is one %what%|more: There are more than one %what%',
59
+
'animal.dog-cat' => 'Dog and cat',
60
+
'animal.dog_cat' => 'Dog and cat (should not conflict with the previous one)',
56
61
],
57
62
'foobar' => [
58
63
'post.num_comments' => 'There is 1 comment|There are %count% comments',
@@ -63,10 +68,13 @@ public function testDump(): void
63
68
'notification.comment_created' => 'Votre article a reçu un commentaire !',
64
69
'notification.comment_created.description' => 'Votre article "{title}" a reçu un nouveau commentaire. Vous pouvez lire le commentaire en suivant <a href="{link}">ce lien</a>',
65
70
'post.num_comments' => '{count, plural, one {# commentaire} other {# commentaires}}',
71
+
'post.num_comments.' => '{count, plural, one {# commentaire} other {# commentaires}} (ne doit pas rentrer en conflit avec la traduction précédente)',
66
72
],
67
73
'messages' => [
68
74
'symfony.great' => 'Symfony est génial !',
69
75
'symfony.what' => 'Symfony est %what%!',
76
+
'symfony.what!' => 'Symfony est %what%! (ne doit pas rentrer en conflit avec la traduction précédente)',
77
+
'symfony.what.' => 'Symfony est %what%. (ne doit pas non plus rentrer en conflit avec la traduction précédente)',
70
78
'apples.count.0' => 'Il y a 1 pomme|Il y a %count% pommes',
71
79
'apples.count.1' => '{1} Il y a une pomme|]1,Inf] Il y a %count% pommes',
72
80
'apples.count.2' => '{0} Il n\'y a pas de pommes|{1} Il y a une pomme|]1,Inf] Il y a %count% pommes',
@@ -76,6 +84,8 @@ public function testDump(): void
76
84
'what.count.2' => '{0} Il n\'y a pas de %what%|{1} Il y a une %what%|]1,Inf] Il y a %count% %what%',
77
85
'what.count.3' => 'one: Il y a une %what%|more: Il y a %count% %what%',
78
86
'what.count.4' => 'one: Il y a une %what%|more: Il y a more than one %what%',
87
+
'animal.dog-cat' => 'Chien et chat',
88
+
'animal.dog_cat' => 'Chien et chat (ne doit pas rentrer en conflit avec la traduction précédente)',
79
89
],
80
90
'foobar' => [
81
91
'post.num_comments' => 'Il y a 1 comment|Il y a %count% comments',
@@ -90,8 +100,11 @@ public function testDump(): void
90
100
export const NOTIFICATION_COMMENT_CREATED = {"id":"notification.comment_created","translations":{"messages+intl-icu":{"en":"Your post received a comment!","fr":"Votre article a re\u00e7u un commentaire !"}}};
91
101
export const NOTIFICATION_COMMENT_CREATED_DESCRIPTION = {"id":"notification.comment_created.description","translations":{"messages+intl-icu":{"en":"Your post \"{title}\" has received a new comment. You can read the comment by following <a href=\"{link}\">this link<\/a>","fr":"Votre article \"{title}\" a re\u00e7u un nouveau commentaire. Vous pouvez lire le commentaire en suivant <a href=\"{link}\">ce lien<\/a>"}}};
92
102
export const POST_NUM_COMMENTS = {"id":"post.num_comments","translations":{"messages+intl-icu":{"en":"{count, plural, one {# comment} other {# comments}}","fr":"{count, plural, one {# commentaire} other {# commentaires}}"},"foobar":{"en":"There is 1 comment|There are %count% comments","fr":"Il y a 1 comment|Il y a %count% comments"}}};
103
+
export const POST_NUM_COMMENTS_1 = {"id":"post.num_comments.","translations":{"messages+intl-icu":{"en":"{count, plural, one {# comment} other {# comments}} (should not conflict with the previous one.)","fr":"{count, plural, one {# commentaire} other {# commentaires}} (ne doit pas rentrer en conflit avec la traduction pr\u00e9c\u00e9dente)"}}};
93
104
export const SYMFONY_GREAT = {"id":"symfony.great","translations":{"messages":{"en":"Symfony is awesome!","fr":"Symfony est g\u00e9nial !"}}};
94
105
export const SYMFONY_WHAT = {"id":"symfony.what","translations":{"messages":{"en":"Symfony is %what%!","fr":"Symfony est %what%!"}}};
106
+
export const SYMFONY_WHAT_1 = {"id":"symfony.what!","translations":{"messages":{"en":"Symfony is %what%! (should not conflict with the previous one.)","fr":"Symfony est %what%! (ne doit pas rentrer en conflit avec la traduction pr\u00e9c\u00e9dente)"}}};
107
+
export const SYMFONY_WHAT_2 = {"id":"symfony.what.","translations":{"messages":{"en":"Symfony is %what%. (should also not conflict with the previous one.)","fr":"Symfony est %what%. (ne doit pas non plus rentrer en conflit avec la traduction pr\u00e9c\u00e9dente)"}}};
95
108
export const APPLES_COUNT0 = {"id":"apples.count.0","translations":{"messages":{"en":"There is 1 apple|There are %count% apples","fr":"Il y a 1 pomme|Il y a %count% pommes"}}};
96
109
export const APPLES_COUNT1 = {"id":"apples.count.1","translations":{"messages":{"en":"{1} There is one apple|]1,Inf] There are %count% apples","fr":"{1} Il y a une pomme|]1,Inf] Il y a %count% pommes"}}};
97
110
export const APPLES_COUNT2 = {"id":"apples.count.2","translations":{"messages":{"en":"{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples","fr":"{0} Il n'y a pas de pommes|{1} Il y a une pomme|]1,Inf] Il y a %count% pommes"}}};
@@ -101,6 +114,8 @@ public function testDump(): void
101
114
export const WHAT_COUNT2 = {"id":"what.count.2","translations":{"messages":{"en":"{0} There are no %what%|{1} There is one %what%|]1,Inf] There are %count% %what%","fr":"{0} Il n'y a pas de %what%|{1} Il y a une %what%|]1,Inf] Il y a %count% %what%"}}};
102
115
export const WHAT_COUNT3 = {"id":"what.count.3","translations":{"messages":{"en":"one: There is one %what%|more: There are %count% %what%","fr":"one: Il y a une %what%|more: Il y a %count% %what%"}}};
103
116
export const WHAT_COUNT4 = {"id":"what.count.4","translations":{"messages":{"en":"one: There is one %what%|more: There are more than one %what%","fr":"one: Il y a une %what%|more: Il y a more than one %what%"}}};
117
+
export const ANIMAL_DOG_CAT = {"id":"animal.dog-cat","translations":{"messages":{"en":"Dog and cat","fr":"Chien et chat"}}};
118
+
export const ANIMAL_DOG_CAT_1 = {"id":"animal.dog_cat","translations":{"messages":{"en":"Dog and cat (should not conflict with the previous one)","fr":"Chien et chat (ne doit pas rentrer en conflit avec la traduction pr\u00e9c\u00e9dente)"}}};
104
119
105
120
JAVASCRIPT);
106
121
@@ -110,8 +125,11 @@ public function testDump(): void
0 commit comments