Make placeholder generation right

This commit is contained in:
Jan Böhmer 2025-12-06 23:27:12 +01:00
parent 9e095ec1c8
commit 5154752368
3 changed files with 26 additions and 31 deletions

View file

@ -1548,11 +1548,6 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
* dump_destination?: scalar|null, // A stream URL where dumps should be written to. // Default: null
* theme?: "dark"|"light", // Changes the color of the dump() output when rendered directly on the templating. "dark" (default) or "light". // Default: "dark"
* }
* @psalm-type MakerConfig = array{
* root_namespace?: scalar|null, // Default: "App"
* generate_final_classes?: bool, // Default: true
* generate_final_entities?: bool, // Default: false
* }
* @psalm-type WebpackEncoreConfig = array{
* output_path: scalar|null, // The path where Encore is building the assets - i.e. Encore.setOutputPath()
* 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 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
* post_processors?: array<string, array<string, mixed>>,
* },
* }
* @psalm-type DamaDoctrineTestConfig = array{
* enable_static_connection?: mixed, // Default: true
* enable_static_meta_data_cache?: bool, // Default: true
* enable_static_query_cache?: bool, // Default: true
* connection_keys?: list<mixed>,
* }
* @psalm-type TwigExtraConfig = array{
* cache?: bool|array{
* enabled?: bool, // Default: false
@ -2372,13 +2373,6 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
* invalidate_on_env_change?: bool, // Default: true
* },
* }
* @psalm-type JbtronicsTranslationEditorConfig = array{
* translations_path?: scalar|null, // Default: "%translator.default_path%"
* format?: scalar|null, // Default: "xlf"
* xliff_version?: scalar|null, // Default: "2.0"
* use_intl_icu_format?: bool, // Default: false
* writer_options?: list<scalar|null>,
* }
* @psalm-type ApiPlatformConfig = array{
* title?: scalar|null, // The title of the API. // Default: ""
* description?: scalar|null, // The description of the API. // Default: ""
@ -2634,11 +2628,17 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
* ...<mixed>
* },
* }
* @psalm-type DamaDoctrineTestConfig = array{
* enable_static_connection?: mixed, // Default: true
* enable_static_meta_data_cache?: bool, // Default: true
* enable_static_query_cache?: bool, // Default: true
* connection_keys?: list<mixed>,
* @psalm-type MakerConfig = array{
* root_namespace?: scalar|null, // Default: "App"
* generate_final_classes?: bool, // Default: true
* generate_final_entities?: bool, // Default: false
* }
* @psalm-type JbtronicsTranslationEditorConfig = array{
* translations_path?: scalar|null, // Default: "%translator.default_path%"
* format?: scalar|null, // Default: "xlf"
* xliff_version?: scalar|null, // Default: "2.0"
* use_intl_icu_format?: bool, // Default: false
* writer_options?: list<scalar|null>,
* }
* @psalm-type ConfigType = array{
* imports?: ImportsConfig,

View file

@ -60,19 +60,14 @@ readonly class RegisterSynonymsAsTranslationParametersListener
//Generate a placeholder for each element type
foreach (ElementTypes::cases() as $elementType) {
// Get the capitalized labels
$capitalizedSingular = $this->typeNameGenerator->typeLabel($elementType);
$capitalizedPlural = $this->typeNameGenerator->typeLabelPlural($elementType);
// Curly braces for lowercase versions
$placeholders['{' . $elementType->value . '}'] = mb_strtolower($capitalizedSingular);
$placeholders['{{' . $elementType->value . '}}'] = mb_strtolower($capitalizedPlural);
//Versions with capitalized first letter
$capitalized = ucfirst($elementType->value); //We have only ASCII element type values, so this is sufficient
$placeholders['[' . $capitalized . ']'] = $this->typeNameGenerator->typeLabel($elementType);
$placeholders['[[' . $capitalized . ']]'] = $this->typeNameGenerator->typeLabelPlural($elementType);
// Square brackets for capitalized versions (with capital first letter in placeholder)
// Use mb_strtoupper for the first character to handle multibyte strings consistently
$capitalizedKey = mb_strtoupper(mb_substr($elementType->value, 0, 1)) . mb_substr($elementType->value, 1);
$placeholders['[' . $capitalizedKey . ']'] = $capitalizedSingular;
$placeholders['[[' . $capitalizedKey . ']]'] = $capitalizedPlural;
//And we have lowercase versions for both
$placeholders['[' . $elementType->value . ']'] = mb_strtolower($this->typeNameGenerator->typeLabel($elementType));
$placeholders['[[' . $elementType->value . ']]'] = mb_strtolower($this->typeNameGenerator->typeLabelPlural($elementType));
}
return $placeholders;

View file

@ -41,8 +41,8 @@ class RegisterSynonymsAsTranslationParametersTest extends KernelTestCase
$this->assertIsArray($placeholders);
// Curly braces for lowercase versions
$this->assertSame('part', $placeholders['{part}']);
$this->assertSame('parts', $placeholders['{{part}}']);
$this->assertSame('part', $placeholders['[part]']);
$this->assertSame('parts', $placeholders['[[part]]']);
// Square brackets for capitalized versions (with capital first letter in placeholder)
$this->assertSame('Part', $placeholders['[Part]']);
$this->assertSame('Parts', $placeholders['[[Part]]']);