Skip to content

Commit 5154752

Browse files
committed
Make placeholder generation right
1 parent 9e095ec commit 5154752

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

config/reference.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,11 +1548,6 @@
15481548
* dump_destination?: scalar|null, // A stream URL where dumps should be written to. // Default: null
15491549
* theme?: "dark"|"light", // Changes the color of the dump() output when rendered directly on the templating. "dark" (default) or "light". // Default: "dark"
15501550
* }
1551-
* @psalm-type MakerConfig = array{
1552-
* root_namespace?: scalar|null, // Default: "App"
1553-
* generate_final_classes?: bool, // Default: true
1554-
* generate_final_entities?: bool, // Default: false
1555-
* }
15561551
* @psalm-type WebpackEncoreConfig = array{
15571552
* output_path: scalar|null, // The path where Encore is building the assets - i.e. Encore.setOutputPath()
15581553
* crossorigin?: false|"anonymous"|"use-credentials", // crossorigin value when Encore.enableIntegrityHashes() is used, can be false (default), anonymous or use-credentials // Default: false
@@ -1677,6 +1672,12 @@
16771672
* post_processors?: array<string, array<string, mixed>>,
16781673
* },
16791674
* }
1675+
* @psalm-type DamaDoctrineTestConfig = array{
1676+
* enable_static_connection?: mixed, // Default: true
1677+
* enable_static_meta_data_cache?: bool, // Default: true
1678+
* enable_static_query_cache?: bool, // Default: true
1679+
* connection_keys?: list<mixed>,
1680+
* }
16801681
* @psalm-type TwigExtraConfig = array{
16811682
* cache?: bool|array{
16821683
* enabled?: bool, // Default: false
@@ -2372,13 +2373,6 @@
23722373
* invalidate_on_env_change?: bool, // Default: true
23732374
* },
23742375
* }
2375-
* @psalm-type JbtronicsTranslationEditorConfig = array{
2376-
* translations_path?: scalar|null, // Default: "%translator.default_path%"
2377-
* format?: scalar|null, // Default: "xlf"
2378-
* xliff_version?: scalar|null, // Default: "2.0"
2379-
* use_intl_icu_format?: bool, // Default: false
2380-
* writer_options?: list<scalar|null>,
2381-
* }
23822376
* @psalm-type ApiPlatformConfig = array{
23832377
* title?: scalar|null, // The title of the API. // Default: ""
23842378
* description?: scalar|null, // The description of the API. // Default: ""
@@ -2634,11 +2628,17 @@
26342628
* ...<mixed>
26352629
* },
26362630
* }
2637-
* @psalm-type DamaDoctrineTestConfig = array{
2638-
* enable_static_connection?: mixed, // Default: true
2639-
* enable_static_meta_data_cache?: bool, // Default: true
2640-
* enable_static_query_cache?: bool, // Default: true
2641-
* connection_keys?: list<mixed>,
2631+
* @psalm-type MakerConfig = array{
2632+
* root_namespace?: scalar|null, // Default: "App"
2633+
* generate_final_classes?: bool, // Default: true
2634+
* generate_final_entities?: bool, // Default: false
2635+
* }
2636+
* @psalm-type JbtronicsTranslationEditorConfig = array{
2637+
* translations_path?: scalar|null, // Default: "%translator.default_path%"
2638+
* format?: scalar|null, // Default: "xlf"
2639+
* xliff_version?: scalar|null, // Default: "2.0"
2640+
* use_intl_icu_format?: bool, // Default: false
2641+
* writer_options?: list<scalar|null>,
26422642
* }
26432643
* @psalm-type ConfigType = array{
26442644
* imports?: ImportsConfig,

src/EventListener/RegisterSynonymsAsTranslationParametersListener.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,14 @@ public function getSynonymPlaceholders(): array
6060

6161
//Generate a placeholder for each element type
6262
foreach (ElementTypes::cases() as $elementType) {
63-
// Get the capitalized labels
64-
$capitalizedSingular = $this->typeNameGenerator->typeLabel($elementType);
65-
$capitalizedPlural = $this->typeNameGenerator->typeLabelPlural($elementType);
66-
67-
// Curly braces for lowercase versions
68-
$placeholders['{' . $elementType->value . '}'] = mb_strtolower($capitalizedSingular);
69-
$placeholders['{{' . $elementType->value . '}}'] = mb_strtolower($capitalizedPlural);
63+
//Versions with capitalized first letter
64+
$capitalized = ucfirst($elementType->value); //We have only ASCII element type values, so this is sufficient
65+
$placeholders['[' . $capitalized . ']'] = $this->typeNameGenerator->typeLabel($elementType);
66+
$placeholders['[[' . $capitalized . ']]'] = $this->typeNameGenerator->typeLabelPlural($elementType);
7067

71-
// Square brackets for capitalized versions (with capital first letter in placeholder)
72-
// Use mb_strtoupper for the first character to handle multibyte strings consistently
73-
$capitalizedKey = mb_strtoupper(mb_substr($elementType->value, 0, 1)) . mb_substr($elementType->value, 1);
74-
$placeholders['[' . $capitalizedKey . ']'] = $capitalizedSingular;
75-
$placeholders['[[' . $capitalizedKey . ']]'] = $capitalizedPlural;
68+
//And we have lowercase versions for both
69+
$placeholders['[' . $elementType->value . ']'] = mb_strtolower($this->typeNameGenerator->typeLabel($elementType));
70+
$placeholders['[[' . $elementType->value . ']]'] = mb_strtolower($this->typeNameGenerator->typeLabelPlural($elementType));
7671
}
7772

7873
return $placeholders;

tests/EventListener/RegisterSynonymsAsTranslationParametersTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function testGetSynonymPlaceholders(): void
4141

4242
$this->assertIsArray($placeholders);
4343
// Curly braces for lowercase versions
44-
$this->assertSame('part', $placeholders['{part}']);
45-
$this->assertSame('parts', $placeholders['{{part}}']);
44+
$this->assertSame('part', $placeholders['[part]']);
45+
$this->assertSame('parts', $placeholders['[[part]]']);
4646
// Square brackets for capitalized versions (with capital first letter in placeholder)
4747
$this->assertSame('Part', $placeholders['[Part]']);
4848
$this->assertSame('Parts', $placeholders['[[Part]]']);

0 commit comments

Comments
 (0)