Replace hardcoded entity type names with synonym placeholders in English and German translations (#1128)

* Initial plan

* Initial plan for replacing entity type names with placeholders

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>

* Replace entity type names with synonym placeholders in English translations

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>

* Add more synonym placeholders for storage location, project, and part patterns

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>

* Update tree navigation labels with synonym placeholders

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>

* Fix remaining entity type placeholders identified in code review

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>

* Fix placeholder syntax: use [Type]/[[Type]] instead of {type}/{{type}} and add German translations

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>

* Fix German translation to avoid awkward word concatenation with placeholder

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>

* Use capitalized placeholders in German translations (nouns are always capitalized in German)

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>

* Fixed length menu for datatable views

* Capitalize placeholders at the beginning of sentences/titles in English translations

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>

* Ensure that synonym placeholders get cached on a per locale level

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>
Co-authored-by: Jan Böhmer <mail@jan-boehmer.de>
This commit is contained in:
Copilot 2025-12-07 14:09:22 +01:00 committed by GitHub
parent a356eecd74
commit 60ff727896
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 318 additions and 192 deletions

View file

@ -50,9 +50,9 @@ readonly class RegisterSynonymsAsTranslationParametersListener
$this->translator = $translator;
}
public function getSynonymPlaceholders(): array
public function getSynonymPlaceholders(string $locale): array
{
return $this->cache->get('partdb_synonym_placeholders', function (ItemInterface $item) {
return $this->cache->get('partdb_synonym_placeholders' . '_' . $locale, function (ItemInterface $item) use ($locale) {
$item->tag('synonyms');
@ -62,12 +62,12 @@ readonly class RegisterSynonymsAsTranslationParametersListener
foreach (ElementTypes::cases() as $elementType) {
//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);
$placeholders['[' . $capitalized . ']'] = $this->typeNameGenerator->typeLabel($elementType, $locale);
$placeholders['[[' . $capitalized . ']]'] = $this->typeNameGenerator->typeLabelPlural($elementType, $locale);
//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));
$placeholders['[' . $elementType->value . ']'] = mb_strtolower($this->typeNameGenerator->typeLabel($elementType, $locale));
$placeholders['[[' . $elementType->value . ']]'] = mb_strtolower($this->typeNameGenerator->typeLabelPlural($elementType, $locale));
}
return $placeholders;
@ -82,7 +82,7 @@ readonly class RegisterSynonymsAsTranslationParametersListener
}
//Register all placeholders for synonyms
$placeholders = $this->getSynonymPlaceholders();
$placeholders = $this->getSynonymPlaceholders($event->getRequest()->getLocale());
foreach ($placeholders as $key => $value) {
$this->translator->addGlobalParameter($key, $value);
}