Skip to content

Commit d77ffc0

Browse files
committed
Update ux.symfony.com app
1 parent fc0ccfa commit d77ffc0

File tree

5 files changed

+40
-39
lines changed

5 files changed

+40
-39
lines changed

ux.symfony.com/assets/controllers/translator-demo-block-controller.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Controller } from '@hotwired/stimulus';
2-
3-
import * as translator from '../translator.js';
2+
import { trans } from '../translator.js';
43

54
/* stimulusFetch: 'lazy' */
65
export default class extends Controller {
@@ -39,7 +38,7 @@ export default class extends Controller {
3938
});
4039

4140
this.outputsTargets.forEach((target) => {
42-
target.textContent = translator.trans(translator[this.messageValue], Object.fromEntries(parameters), 'messages', target.dataset.locale);
41+
target.textContent = trans(this.messageValue, Object.fromEntries(parameters), 'messages', target.dataset.locale);
4342
});
4443
}
4544
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { localeFallbacks } from '@app/translations/configuration';
2-
import { trans, getLocale, setLocale, setLocaleFallbacks } from '@symfony/ux-translator';
1+
import { createTranslator } from '@symfony/ux-translator';
2+
import { messages, localeFallbacks } from '../var/translations/index.js';
3+
34
/*
45
* This file is part of the Symfony UX Translator package.
56
*
@@ -9,8 +10,9 @@ import { trans, getLocale, setLocale, setLocaleFallbacks } from '@symfony/ux-tra
910
* If you use TypeScript, you can rename this file to "translator.ts" to take advantage of types checking.
1011
*/
1112

12-
setLocaleFallbacks(localeFallbacks);
13-
14-
export { trans, setLocale };
13+
const translator = createTranslator({
14+
messages,
15+
localeFallbacks,
16+
});
1517

16-
export * from '@app/translations';
18+
export const { trans } = translator;

ux.symfony.com/config/packages/asset_mapper.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ framework:
1616
- '*/kits/**/*.md' # UX Toolkit kit documentation
1717
- '*/kits/**/manifest.json' # UX Toolkit kit manifest files
1818
importmap_polyfill: false
19+
missing_import_mode: strict
20+
21+
when@prod:
22+
framework:
23+
asset_mapper:
24+
missing_import_mode: warn
1925

2026
react:
2127
controllers_path: '%kernel.project_dir%/assets/react/dist/controllers'

ux.symfony.com/importmap.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@
5151
'@symfony/ux-translator' => [
5252
'path' => '@symfony/ux-translator/translator_controller.js',
5353
],
54-
'@app/translations' => [
55-
'path' => 'var/translations/index.js',
56-
],
57-
'@app/translations/configuration' => [
58-
'path' => 'var/translations/configuration.js',
59-
],
6054
'@symfony/ux-live-component' => [
6155
'path' => './vendor/symfony/ux-live-component/assets/dist/live_controller.js',
6256
],

ux.symfony.com/templates/ux_packages/translator.html.twig

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@
2828
{% block demo_content %}
2929

3030
{% embed 'ux_packages/translator/_translator_demo_block.html.twig' with {
31-
message: 'HELLO',
31+
message: 'hello',
3232
} %}
3333
{% endembed %}
3434

3535
{% embed 'ux_packages/translator/_translator_demo_block.html.twig' with {
36-
message: 'SAY_HELLO',
36+
message: 'say_hello',
3737
parameters: {
3838
name: 'Fabien'
3939
},
4040
} %}
4141
{% block parameters %}
4242
<div>
43-
<label for="SAY_HELLO-name" class="small opacity-50">Name</label>
44-
<input id="SAY_HELLO-name" class="form-control"
43+
<label for="say_hello-name" class="small opacity-50">Name</label>
44+
<input id="say_hello-name" class="form-control"
4545
type="text" name="name" value="Fabien"
4646
data-translator-demo-block-target="parameters"
4747
data-action="translator-demo-block#render"
@@ -51,16 +51,16 @@
5151
{% endembed %}
5252

5353
{% embed 'ux_packages/translator/_translator_demo_block.html.twig' with {
54-
message: 'INVITATION_TITLE',
54+
message: 'invitation_title',
5555
parameters: {
5656
organizer_gender: 'Fabien',
5757
organizer_name: 'Clara',
5858
},
5959
} %}
6060
{% block parameters %}
6161
<div>
62-
<label for="INVITATION_TITLE-organizer_gender" class="small opacity-50">Gender</label>
63-
<select id="INVITATION_TITLE-organizer_gender" class="form-select"
62+
<label for="invitation_title-organizer_gender" class="small opacity-50">Gender</label>
63+
<select id="invitation_title-organizer_gender" class="form-select"
6464
name="organizer_gender"
6565
data-translator-demo-block-target="parameters"
6666
data-action="translator-demo-block#render"
@@ -72,8 +72,8 @@
7272
</select>
7373
</div>
7474
<div>
75-
<label for="INVITATION_TITLE-organizer_name" class="small opacity-50">Name</label>
76-
<input id="INVITATION_TITLE-organizer_name" class="form-control"
75+
<label for="invitation_title-organizer_name" class="small opacity-50">Name</label>
76+
<input id="invitation_title-organizer_name" class="form-control"
7777
name="organizer_name"
7878
value="Clara"
7979
data-translator-demo-block-target="parameters"
@@ -84,15 +84,15 @@
8484
{% endembed %}
8585

8686
{% embed 'ux_packages/translator/_translator_demo_block.html.twig' with {
87-
message: 'NUM_OF_APPLES',
87+
message: 'num_of_apples',
8888
parameters: {
8989
apples: 2
9090
},
9191
} %}
9292
{% block parameters %}
9393
<div>
94-
<label for="NUM_OF_APPLES-apples" class="small opacity-50">Count</label>
95-
<input id="NUM_OF_APPLES-apples" class="form-control"
94+
<label for="num_of_apples-apples" class="small opacity-50">Count</label>
95+
<input id="num_of_apples-apples" class="form-control"
9696
name="apples" type="number" min="0" max="5" value="2"
9797
data-translator-demo-block-target="parameters"
9898
data-action="translator-demo-block#render"
@@ -102,15 +102,15 @@
102102
{% endembed %}
103103

104104
{% embed 'ux_packages/translator/_translator_demo_block.html.twig' with {
105-
message: 'FINISH_PLACE',
105+
message: 'finish_place',
106106
parameters: {
107107
place: 2
108108
},
109109
} %}
110110
{% block parameters %}
111111
<div>
112-
<label for="FINISH_PLACE-apples" class="small opacity-50">Place</label>
113-
<input id="FINISH_PLACE-apples" class="form-control"
112+
<label for="finish_place-place" class="small opacity-50">Place</label>
113+
<input id="finish_place-place" class="form-control"
114114
name="place" type="number" min="0" max="5" value="1"
115115
data-translator-demo-block-target="parameters"
116116
data-action="translator-demo-block#render"
@@ -120,15 +120,15 @@
120120
{% endembed %}
121121

122122
{% embed 'ux_packages/translator/_translator_demo_block.html.twig' with {
123-
message: 'PUBLISHED_AT',
123+
message: 'published_at',
124124
parameters: {
125125
publication_date: '2023-04-27 08:12'
126126
},
127127
} %}
128128
{% block parameters %}
129129
<div>
130-
<label for="PUBLISHED_AT-publication_date" class="small opacity-50">Date</label>
131-
<input id="PUBLISHED_AT-publication_date" class="form-control"
130+
<label for="published_at-publication_date" class="small opacity-50">Date</label>
131+
<input id="published_at-publication_date" class="form-control"
132132
name="publication_date" type="datetime-local" value="2023-04-27 08:12"
133133
data-translator-demo-block-target="parameters"
134134
data-action="translator-demo-block#render"
@@ -138,15 +138,15 @@
138138
{% endembed %}
139139

140140
{% embed 'ux_packages/translator/_translator_demo_block.html.twig' with {
141-
message: 'PROGRESS',
141+
message: 'progress',
142142
parameters: {
143143
progress: 42
144144
},
145145
} %}
146146
{% block parameters %}
147147
<div>
148-
<label for="PROGRESS-progress" class="small opacity-50">Place</label>
149-
<input id="PROGRESS-progress" class="form-range"
148+
<label for="progress-progress" class="small opacity-50">Place</label>
149+
<input id="progress-progress" class="form-range"
150150
name="progress" type="range" min="0" max="100" value="42"
151151
data-translator-demo-block-target="parameters"
152152
data-action="translator-demo-block#render"
@@ -156,15 +156,15 @@
156156
{% endembed %}
157157

158158
{% embed 'ux_packages/translator/_translator_demo_block.html.twig' with {
159-
message: 'VALUE_OF_OBJECT',
159+
message: 'value_of_object',
160160
parameters: {
161161
price: 30
162162
},
163163
} %}
164164
{% block parameters %}
165165
<div>
166-
<label for="VALUE_OF_OBJECT-price" class="small opacity-50">Price</label>
167-
<input id="VALUE_OF_OBJECT-price" class="form-control"
166+
<label for="value_of_object-price" class="small opacity-50">Price</label>
167+
<input id="value_of_object-price" class="form-control"
168168
name="price" type="number" min="1" value="30" step="0.1"
169169
data-translator-demo-block-target="parameters"
170170
data-action="translator-demo-block#render"

0 commit comments

Comments
 (0)