Replace placeholder syntax for type synonyms to be more DX friendly

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-06 21:42:40 +00:00
parent 3d3b1f276c
commit a2f3ceb142
3 changed files with 28 additions and 23 deletions

View file

@ -18,7 +18,7 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co
parts: # e.g. this maps to perms_parts in User/Group database parts: # e.g. this maps to perms_parts in User/Group database
group: "data" group: "data"
label: "{{part}}" label: "[[Part]]"
operations: # Here are all possible operations are listed => the op name is mapped to bit value operations: # Here are all possible operations are listed => the op name is mapped to bit value
read: read:
label: "perm.read" label: "perm.read"
@ -71,7 +71,7 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co
storelocations: &PART_CONTAINING storelocations: &PART_CONTAINING
label: "{{storage_location}}" label: "[[Storage_location]]"
group: "data" group: "data"
operations: operations:
read: read:
@ -103,39 +103,39 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co
footprints: footprints:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "{{footprint}}" label: "[[Footprint]]"
categories: categories:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "{{category}}" label: "[[Category]]"
suppliers: suppliers:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "{{supplier}}" label: "[[Supplier]]"
manufacturers: manufacturers:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "{{manufacturer}}" label: "[[Manufacturer]]"
projects: projects:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "{{project}}" label: "[[Project]]"
attachment_types: attachment_types:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "{{attachment_type}}" label: "[[Attachment_type]]"
currencies: currencies:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "{{currency}}" label: "[[Currency]]"
measurement_units: measurement_units:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "{{measurement_unit}}" label: "[[Measurement_unit]]"
part_custom_states: part_custom_states:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "{{part_custom_state}}" label: "[[Part_custom_state]]"
tools: tools:
label: "perm.part.tools" label: "perm.part.tools"

View file

@ -60,14 +60,18 @@ readonly class RegisterSynonymsAsTranslationParametersListener
//Generate a placeholder for each element type //Generate a placeholder for each element type
foreach (ElementTypes::cases() as $elementType) { foreach (ElementTypes::cases() as $elementType) {
//We have a placeholder for singular // Get the capitalized labels
$placeholders['{' . $elementType->value . '}'] = $this->typeNameGenerator->typeLabel($elementType); $capitalizedSingular = $this->typeNameGenerator->typeLabel($elementType);
//We have a placeholder for plural $capitalizedPlural = $this->typeNameGenerator->typeLabelPlural($elementType);
$placeholders['{{' . $elementType->value . '}}'] = $this->typeNameGenerator->typeLabelPlural($elementType);
//And we have lowercase versions for both // Curly braces for lowercase versions
$placeholders['[' . $elementType->value . ']'] = mb_strtolower($this->typeNameGenerator->typeLabel($elementType)); $placeholders['{' . $elementType->value . '}'] = mb_strtolower($capitalizedSingular);
$placeholders['[[' . $elementType->value . ']]'] = mb_strtolower($this->typeNameGenerator->typeLabelPlural($elementType)); $placeholders['{{' . $elementType->value . '}}'] = mb_strtolower($capitalizedPlural);
// Square brackets for capitalized versions (with capital first letter in placeholder)
$capitalizedKey = ucfirst($elementType->value);
$placeholders['[' . $capitalizedKey . ']'] = $capitalizedSingular;
$placeholders['[[' . $capitalizedKey . ']]'] = $capitalizedPlural;
} }
return $placeholders; return $placeholders;

View file

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