Implemented the ability to set user-defined synonyms/labels for internal element types

* Implementiere bevorzugte Sprachauswahl und Datenquellen-Synonyme

Die Spracheinstellungen/System-Settings wurden um die Möglichkeit ergänzt, bevorzugte Sprachen für die Dropdown-Menüs festzulegen. Zudem wurde ein Datenquellen-Synonymsystem implementiert, um benutzerfreundlichere Bezeichnungen anzuzeigen und zu personalisieren.

* Anpassung aus Analyse

* Entferne alten JSON-basierten Datenquellen-Synonym-Handler

Die Verwaltung der Datenquellen-Synonyme wurde überarbeitet, um ein flexibleres und strukturiertes Konzept zu ermöglichen. Der bestehende JSON-basierte Ansatz wurde durch eine neue Service-basierte Architektur ersetzt, die eine bessere Handhabung und Erweiterbarkeit erlaubt.

* Ermögliche Rückgabe aller möglichen Sprachoptionen in Verbindung mit den vom Nutzer freigeschalteten.

* Removed unnecessary service definition

The tag is applied via autoconfiguration

* Use default translations for the NotBlank constraint

* Started refactoring ElementTypeNameGenerator

* Made ElementTypeNameGenerator class readonly

* Modified form to work properly with new datastructure

* Made the form more beautiful and space saving

* Made synonym form even more space saving

* Allow to define overrides for any element label there is

* Use defined synonyms in ElementTypeNameGenerator

* Use ElementTypeNameGenerator where possible

* Register synonyms for element types as global translation parameters

* Revert changes done to permission layout

* Use new synonym system for admin page titles

* Removed now unnecessary services

* Reworked settings name and translation

* Renamed all files to Synonyms

* Removed unnecessary translations

* Removed unnecessary translations

* Fixed duplicate check

* Renamed synoynms translations

* Use our synonyms for permission translations

* Fixed phpstan issue

* Added tests

---------

Co-authored-by: Marcel Diegelmann <marcel.diegelmann@gmail.com>
Co-authored-by: Jan Böhmer <mail@jan-boehmer.de>
This commit is contained in:
web-devinition.de 2025-11-12 21:35:02 +01:00 committed by GitHub
parent 5e3bd26e27
commit 54f318ecac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 1504 additions and 335 deletions

View file

@ -0,0 +1,68 @@
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
static targets = ['items'];
static values = {
prototype: String,
prototypeName: { type: String, default: '__name__' },
index: { type: Number, default: 0 },
};
connect() {
if (!this.hasIndexValue || Number.isNaN(this.indexValue)) {
this.indexValue = this.itemsTarget?.children.length || 0;
}
}
add(event) {
event.preventDefault();
const encodedProto = this.prototypeValue || '';
const placeholder = this.prototypeNameValue || '__name__';
if (!encodedProto || !this.itemsTarget) return;
const protoHtml = this._decodeHtmlAttribute(encodedProto);
const idx = this.indexValue;
const html = protoHtml.replace(new RegExp(placeholder, 'g'), String(idx));
const wrapper = document.createElement('div');
wrapper.innerHTML = html;
const newItem = wrapper.firstElementChild;
if (newItem) {
this.itemsTarget.appendChild(newItem);
this.indexValue = idx + 1;
}
}
remove(event) {
event.preventDefault();
const row = event.currentTarget.closest('.tc-item');
if (row) row.remove();
}
_decodeHtmlAttribute(str) {
const tmp = document.createElement('textarea');
tmp.innerHTML = str;
return tmp.value || tmp.textContent || '';
}
}

View file

@ -1,7 +1,7 @@
framework: framework:
default_locale: 'en' default_locale: 'en'
# Just enable the locales we need for performance reasons. # Just enable the locales we need for performance reasons.
enabled_locale: '%partdb.locale_menu%' enabled_locale: ['en', 'de', 'it', 'fr', 'ru', 'ja', 'cs', 'da', 'zh', 'pl']
translator: translator:
default_path: '%kernel.project_dir%/translations' default_path: '%kernel.project_dir%/translations'
fallbacks: fallbacks:

View file

@ -1,6 +1,6 @@
twig: twig:
default_path: '%kernel.project_dir%/templates' default_path: '%kernel.project_dir%/templates'
form_themes: ['bootstrap_5_horizontal_layout.html.twig', 'form/extended_bootstrap_layout.html.twig', 'form/permission_layout.html.twig', 'form/filter_types_layout.html.twig'] form_themes: ['bootstrap_5_horizontal_layout.html.twig', 'form/extended_bootstrap_layout.html.twig', 'form/permission_layout.html.twig', 'form/filter_types_layout.html.twig', 'form/synonyms_collection.html.twig']
paths: paths:
'%kernel.project_dir%/assets/css': css '%kernel.project_dir%/assets/css': css

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: "perm.parts" 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: "perm.storelocations" 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: "perm.part.footprints" label: "{{footprint}}"
categories: categories:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "perm.part.categories" label: "{{category}}"
suppliers: suppliers:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "perm.part.supplier" label: "{{supplier}}"
manufacturers: manufacturers:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "perm.part.manufacturers" label: "{{manufacturer}}"
projects: projects:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "perm.projects" label: "{{project}}"
attachment_types: attachment_types:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "perm.part.attachment_types" label: "{{attachment_type}}"
currencies: currencies:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "perm.currencies" label: "{{currency}}"
measurement_units: measurement_units:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "perm.measurement_units" label: "{{measurement_unit}}"
part_custom_states: part_custom_states:
<<: *PART_CONTAINING <<: *PART_CONTAINING
label: "perm.part_custom_states" label: "{{part_custom_state}}"
tools: tools:
label: "perm.part.tools" label: "perm.part.tools"

View file

@ -64,7 +64,7 @@ class SettingsController extends AbstractController
$this->settingsManager->save($settings); $this->settingsManager->save($settings);
//It might be possible, that the tree settings have changed, so clear the cache //It might be possible, that the tree settings have changed, so clear the cache
$cache->invalidateTags(['tree_treeview', 'sidebar_tree_update']); $cache->invalidateTags(['tree_tools', 'tree_treeview', 'sidebar_tree_update', 'synonyms']);
$this->addFlash('success', t('settings.flash.saved')); $this->addFlash('success', t('settings.flash.saved'));
} }

View file

@ -0,0 +1,93 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\EventListener;
use App\Services\ElementTypeNameGenerator;
use App\Services\ElementTypes;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\Translation\Translator;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
#[AsEventListener]
readonly class RegisterSynonymsAsTranslationParametersListener
{
private Translator $translator;
public function __construct(
#[Autowire(service: 'translator.default')] TranslatorInterface $translator,
private TagAwareCacheInterface $cache,
private ElementTypeNameGenerator $typeNameGenerator)
{
if (!$translator instanceof Translator) {
throw new \RuntimeException('Translator must be an instance of Symfony\Component\Translation\Translator or this listener cannot be used.');
}
$this->translator = $translator;
}
public function getSynonymPlaceholders(): array
{
return $this->cache->get('partdb_synonym_placeholders', function (ItemInterface $item) {
$item->tag('synonyms');
$placeholders = [];
//Generate a placeholder for each element type
foreach (ElementTypes::cases() as $elementType) {
//We have a placeholder for singular
$placeholders['{' . $elementType->value . '}'] = $this->typeNameGenerator->typeLabel($elementType);
//We have a placeholder for plural
$placeholders['{{' . $elementType->value . '}}'] = $this->typeNameGenerator->typeLabelPlural($elementType);
//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;
});
}
public function __invoke(RequestEvent $event): void
{
//If we already added the parameters, skip adding them again
if (isset($this->translator->getGlobalParameters()['@@partdb_synonyms_registered@@'])) {
return;
}
//Register all placeholders for synonyms
$placeholders = $this->getSynonymPlaceholders();
foreach ($placeholders as $key => $value) {
$this->translator->addGlobalParameter($key, $value);
}
//Register the marker parameter to avoid double registration
$this->translator->addGlobalParameter('@@partdb_synonyms_registered@@', 'registered');
}
}

View file

@ -21,12 +21,11 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Form\Type; namespace App\Form\Settings;
use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\LanguageType; use Symfony\Component\Form\Extension\Core\Type\LanguageType;
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
use Symfony\Component\Intl\Languages; use Symfony\Component\Intl\Languages;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;

View file

@ -0,0 +1,142 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Form\Settings;
use App\Services\ElementTypes;
use App\Settings\SystemSettings\LocalizationSettings;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Intl\Locales;
use Symfony\Component\Validator\Constraints as Assert;
/**
* A single translation row: data source + language + translations (singular/plural).
*/
class TypeSynonymRowType extends AbstractType
{
private const PREFERRED_TYPES = [
ElementTypes::CATEGORY,
ElementTypes::STORAGE_LOCATION,
ElementTypes::FOOTPRINT,
ElementTypes::MANUFACTURER,
ElementTypes::SUPPLIER,
ElementTypes::PROJECT,
];
public function __construct(
private readonly LocalizationSettings $localizationSettings,
#[Autowire(param: 'partdb.locale_menu')] private readonly array $preferredLanguagesParam,
) {
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('dataSource', EnumType::class, [
'class' => ElementTypes::class,
'label' => false,
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
'row_attr' => ['class' => 'mb-0'],
'attr' => ['class' => 'form-select-sm'],
'preferred_choices' => self::PREFERRED_TYPES
])
->add('locale', LocaleType::class, [
'label' => false,
'required' => true,
// Restrict to languages configured in the language menu: disable ChoiceLoader and provide explicit choices
'choice_loader' => null,
'choices' => $this->buildLocaleChoices(true),
'preferred_choices' => $this->getPreferredLocales(),
'constraints' => [
new Assert\NotBlank(),
],
'row_attr' => ['class' => 'mb-0'],
'attr' => ['class' => 'form-select-sm']
])
->add('translation_singular', TextType::class, [
'label' => false,
'required' => true,
'empty_data' => '',
'constraints' => [
new Assert\NotBlank(),
],
'row_attr' => ['class' => 'mb-0'],
'attr' => ['class' => 'form-select-sm']
])
->add('translation_plural', TextType::class, [
'label' => false,
'required' => true,
'empty_data' => '',
'constraints' => [
new Assert\NotBlank(),
],
'row_attr' => ['class' => 'mb-0'],
'attr' => ['class' => 'form-select-sm']
]);
}
/**
* Returns only locales configured in the language menu (settings) or falls back to the parameter.
* Format: ['German (DE)' => 'de', ...]
*/
private function buildLocaleChoices(bool $returnPossible = false): array
{
$locales = $this->getPreferredLocales();
if ($returnPossible) {
$locales = $this->getPossibleLocales();
}
$choices = [];
foreach ($locales as $code) {
$label = Locales::getName($code);
$choices[$label . ' (' . strtoupper($code) . ')'] = $code;
}
return $choices;
}
/**
* Source of allowed locales:
* 1) LocalizationSettings->languageMenuEntries (if set)
* 2) Fallback: parameter partdb.locale_menu
*/
private function getPreferredLocales(): array
{
$fromSettings = $this->localizationSettings->languageMenuEntries ?? [];
return !empty($fromSettings) ? array_values($fromSettings) : array_values($this->preferredLanguagesParam);
}
private function getPossibleLocales(): array
{
return array_values($this->preferredLanguagesParam);
}
}

View file

@ -0,0 +1,223 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Form\Settings;
use App\Services\ElementTypes;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Intl\Locales;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Flat collection of translation rows.
* View data: list [{dataSource, locale, translation_singular, translation_plural}, ...]
* Model data: same structure (list). Optionally expands a nested map to a list.
*/
class TypeSynonymsCollectionType extends AbstractType
{
public function __construct(private readonly TranslatorInterface $translator)
{
}
private function flattenStructure(array $modelValue): array
{
//If the model is already flattened, return as is
if (array_is_list($modelValue)) {
return $modelValue;
}
$out = [];
foreach ($modelValue as $dataSource => $locales) {
if (!is_array($locales)) {
continue;
}
foreach ($locales as $locale => $translations) {
if (!is_array($translations)) {
continue;
}
$out[] = [
//Convert string to enum value
'dataSource' => ElementTypes::from($dataSource),
'locale' => $locale,
'translation_singular' => $translations['singular'] ?? '',
'translation_plural' => $translations['plural'] ?? '',
];
}
}
return $out;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void {
//Flatten the structure
$data = $event->getData();
$event->setData($this->flattenStructure($data));
});
$builder->addModelTransformer(new CallbackTransformer(
// Model -> View
$this->flattenStructure(...),
// View -> Model (keep list; let existing behavior unchanged)
function (array $viewValue) {
//Turn our flat list back into the structured array
$out = [];
foreach ($viewValue as $row) {
if (!is_array($row)) {
continue;
}
$dataSource = $row['dataSource'] ?? null;
$locale = $row['locale'] ?? null;
$translation_singular = $row['translation_singular'] ?? null;
$translation_plural = $row['translation_plural'] ?? null;
if ($dataSource === null ||
!is_string($locale) || $locale === ''
) {
continue;
}
$out[$dataSource->value][$locale] = [
'singular' => is_string($translation_singular) ? $translation_singular : '',
'plural' => is_string($translation_plural) ? $translation_plural : '',
];
}
return $out;
}
));
// Validation and normalization (duplicates + sorting) during SUBMIT
$builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event): void {
$form = $event->getForm();
$rows = $event->getData();
if (!is_array($rows)) {
return;
}
// Duplicate check: (dataSource, locale) must be unique
$seen = [];
$hasDuplicate = false;
foreach ($rows as $idx => $row) {
if (!is_array($row)) {
continue;
}
$ds = $row['dataSource'] ?? null;
$loc = $row['locale'] ?? null;
if ($ds !== null && is_string($loc) && $loc !== '') {
$key = $ds->value . '|' . $loc;
if (isset($seen[$key])) {
$hasDuplicate = true;
if ($form->has((string)$idx)) {
$child = $form->get((string)$idx);
if ($child->has('dataSource')) {
$child->get('dataSource')->addError(
new FormError($this->translator->trans(
'settings.synonyms.type_synonyms.collection_type.duplicate',
[], 'validators'
))
);
}
if ($child->has('locale')) {
$child->get('locale')->addError(
new FormError($this->translator->trans(
'settings.synonyms.type_synonyms.collection_type.duplicate',
[], 'validators'
))
);
}
}
} else {
$seen[$key] = true;
}
}
}
if ($hasDuplicate) {
return;
}
// Overall sort: first by dataSource key, then by localized language name
$sortable = $rows;
usort($sortable, static function ($a, $b) {
$aDs = $a['dataSource']->value ?? '';
$bDs = $b['dataSource']->value ?? '';
$cmpDs = strcasecmp($aDs, $bDs);
if ($cmpDs !== 0) {
return $cmpDs;
}
$aLoc = (string)($a['locale'] ?? '');
$bLoc = (string)($b['locale'] ?? '');
$aName = Locales::getName($aLoc);
$bName = Locales::getName($bLoc);
return strcasecmp($aName, $bName);
});
$event->setData($sortable);
});
}
public function configureOptions(OptionsResolver $resolver): void
{
// Defaults for the collection and entry type
$resolver->setDefaults([
'entry_type' => TypeSynonymRowType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'required' => false,
'prototype' => true,
'empty_data' => [],
'entry_options' => ['label' => false],
]);
}
public function getParent(): ?string
{
return CollectionType::class;
}
public function getBlockPrefix(): string
{
return 'type_synonyms_collection';
}
}

View file

@ -30,7 +30,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
/** /**
* A locale select field that uses the preferred languages from the configuration. * A locale select field that uses the preferred languages from the configuration.
*/ */
class LocaleSelectType extends AbstractType class LocaleSelectType extends AbstractType
{ {

View file

@ -24,68 +24,31 @@ namespace App\Services;
use App\Entity\Attachments\Attachment; use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentContainingDBElement; use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractDBElement;
use App\Entity\Contracts\NamedElementInterface; use App\Entity\Contracts\NamedElementInterface;
use App\Entity\InfoProviderSystem\BulkInfoProviderImportJob;
use App\Entity\InfoProviderSystem\BulkInfoProviderImportJobPart;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\Parameters\AbstractParameter; use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\Parts\PartAssociation;
use App\Entity\Parts\PartCustomState;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Entity\Parts\StorageLocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\PriceInformations\Orderdetail; use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail; use App\Entity\PriceInformations\Pricedetail;
use App\Entity\ProjectSystem\Project; use App\Entity\ProjectSystem\Project;
use App\Entity\ProjectSystem\ProjectBOMEntry; use App\Entity\ProjectSystem\ProjectBOMEntry;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Exceptions\EntityNotSupportedException; use App\Exceptions\EntityNotSupportedException;
use App\Settings\SynonymSettings;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
/** /**
* @see \App\Tests\Services\ElementTypeNameGeneratorTest * @see \App\Tests\Services\ElementTypeNameGeneratorTest
*/ */
class ElementTypeNameGenerator final readonly class ElementTypeNameGenerator
{ {
protected array $mapping;
public function __construct(protected TranslatorInterface $translator, private readonly EntityURLGenerator $entityURLGenerator) public function __construct(
private TranslatorInterface $translator,
private EntityURLGenerator $entityURLGenerator,
private SynonymSettings $synonymsSettings,
)
{ {
//Child classes has to become before parent classes
$this->mapping = [
Attachment::class => $this->translator->trans('attachment.label'),
Category::class => $this->translator->trans('category.label'),
AttachmentType::class => $this->translator->trans('attachment_type.label'),
Project::class => $this->translator->trans('project.label'),
ProjectBOMEntry::class => $this->translator->trans('project_bom_entry.label'),
Footprint::class => $this->translator->trans('footprint.label'),
Manufacturer::class => $this->translator->trans('manufacturer.label'),
MeasurementUnit::class => $this->translator->trans('measurement_unit.label'),
Part::class => $this->translator->trans('part.label'),
PartLot::class => $this->translator->trans('part_lot.label'),
StorageLocation::class => $this->translator->trans('storelocation.label'),
Supplier::class => $this->translator->trans('supplier.label'),
Currency::class => $this->translator->trans('currency.label'),
Orderdetail::class => $this->translator->trans('orderdetail.label'),
Pricedetail::class => $this->translator->trans('pricedetail.label'),
Group::class => $this->translator->trans('group.label'),
User::class => $this->translator->trans('user.label'),
AbstractParameter::class => $this->translator->trans('parameter.label'),
LabelProfile::class => $this->translator->trans('label_profile.label'),
PartAssociation::class => $this->translator->trans('part_association.label'),
BulkInfoProviderImportJob::class => $this->translator->trans('bulk_info_provider_import_job.label'),
BulkInfoProviderImportJobPart::class => $this->translator->trans('bulk_info_provider_import_job_part.label'),
PartCustomState::class => $this->translator->trans('part_custom_state.label'),
];
} }
/** /**
@ -99,27 +62,69 @@ class ElementTypeNameGenerator
* @return string the localized label for the entity type * @return string the localized label for the entity type
* *
* @throws EntityNotSupportedException when the passed entity is not supported * @throws EntityNotSupportedException when the passed entity is not supported
* @deprecated Use label() instead
*/ */
public function getLocalizedTypeLabel(object|string $entity): string public function getLocalizedTypeLabel(object|string $entity): string
{ {
$class = is_string($entity) ? $entity : $entity::class; return $this->typeLabel($entity);
//Check if we have a direct array entry for our entity class, then we can use it
if (isset($this->mapping[$class])) {
return $this->mapping[$class];
} }
//Otherwise iterate over array and check for inheritance (needed when the proxy element from doctrine are passed) private function resolveSynonymLabel(ElementTypes $type, ?string $locale, bool $plural): ?string
foreach ($this->mapping as $class_to_check => $translation) { {
if (is_a($entity, $class_to_check, true)) { $locale ??= $this->translator->getLocale();
return $translation;
if ($this->synonymsSettings->isSynonymDefinedForType($type)) {
if ($plural) {
$syn = $this->synonymsSettings->getPluralSynonymForType($type, $locale);
} else {
$syn = $this->synonymsSettings->getSingularSynonymForType($type, $locale);
}
if ($syn === null) {
//Try to fall back to english
if ($plural) {
$syn = $this->synonymsSettings->getPluralSynonymForType($type, 'en');
} else {
$syn = $this->synonymsSettings->getSingularSynonymForType($type, 'en');
} }
} }
//When nothing was found throw an exception return $syn;
throw new EntityNotSupportedException(sprintf('No localized label for the element with type %s was found!', is_object($entity) ? $entity::class : (string) $entity));
} }
return null;
}
/**
* Gets a localized label for the type of the entity. If user defined synonyms are defined,
* these are used instead of the default labels.
* @param object|string $entity
* @param string|null $locale
* @return string
*/
public function typeLabel(object|string $entity, ?string $locale = null): string
{
$type = ElementTypes::fromValue($entity);
return $this->resolveSynonymLabel($type, $locale, false)
?? $this->translator->trans($type->getDefaultLabelKey(), locale: $locale);
}
/**
* Similar to label(), but returns the plural version of the label.
* @param object|string $entity
* @param string|null $locale
* @return string
*/
public function typeLabelPlural(object|string $entity, ?string $locale = null): string
{
$type = ElementTypes::fromValue($entity);
return $this->resolveSynonymLabel($type, $locale, true)
?? $this->translator->trans($type->getDefaultPluralLabelKey(), locale: $locale);
}
/** /**
* Returns a string like in the format ElementType: ElementName. * Returns a string like in the format ElementType: ElementName.
* For example this could be something like: "Part: BC547". * For example this could be something like: "Part: BC547".
@ -134,7 +139,7 @@ class ElementTypeNameGenerator
*/ */
public function getTypeNameCombination(NamedElementInterface $entity, bool $use_html = false): string public function getTypeNameCombination(NamedElementInterface $entity, bool $use_html = false): string
{ {
$type = $this->getLocalizedTypeLabel($entity); $type = $this->typeLabel($entity);
if ($use_html) { if ($use_html) {
return '<i>' . $type . ':</i> ' . htmlspecialchars($entity->getName()); return '<i>' . $type . ':</i> ' . htmlspecialchars($entity->getName());
} }
@ -144,7 +149,7 @@ class ElementTypeNameGenerator
/** /**
* Returns a HTML formatted label for the given enitity in the format "Type: Name" (on elements with a name) and * Returns a HTML formatted label for the given entity in the format "Type: Name" (on elements with a name) and
* "Type: ID" (on elements without a name). If possible the value is given as a link to the element. * "Type: ID" (on elements without a name). If possible the value is given as a link to the element.
* @param AbstractDBElement $entity The entity for which the label should be generated * @param AbstractDBElement $entity The entity for which the label should be generated
* @param bool $include_associated If set to true, the associated entity (like the part belonging to a part lot) is included in the label to give further information * @param bool $include_associated If set to true, the associated entity (like the part belonging to a part lot) is included in the label to give further information
@ -165,7 +170,7 @@ class ElementTypeNameGenerator
} else { //Target does not have a name } else { //Target does not have a name
$tmp = sprintf( $tmp = sprintf(
'<i>%s</i>: %s', '<i>%s</i>: %s',
$this->getLocalizedTypeLabel($entity), $this->typeLabel($entity),
$entity->getID() $entity->getID()
); );
} }
@ -209,7 +214,7 @@ class ElementTypeNameGenerator
{ {
return sprintf( return sprintf(
'<i>%s</i>: %s [%s]', '<i>%s</i>: %s [%s]',
$this->getLocalizedTypeLabel($class), $this->typeLabel($class),
$id, $id,
$this->translator->trans('log.target_deleted') $this->translator->trans('log.target_deleted')
); );

View file

@ -0,0 +1,229 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Services;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\InfoProviderSystem\BulkInfoProviderImportJob;
use App\Entity\InfoProviderSystem\BulkInfoProviderImportJobPart;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartAssociation;
use App\Entity\Parts\PartCustomState;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\StorageLocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
use App\Entity\ProjectSystem\Project;
use App\Entity\ProjectSystem\ProjectBOMEntry;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Exceptions\EntityNotSupportedException;
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
enum ElementTypes: string implements TranslatableInterface
{
case ATTACHMENT = "attachment";
case CATEGORY = "category";
case ATTACHMENT_TYPE = "attachment_type";
case PROJECT = "project";
case PROJECT_BOM_ENTRY = "project_bom_entry";
case FOOTPRINT = "footprint";
case MANUFACTURER = "manufacturer";
case MEASUREMENT_UNIT = "measurement_unit";
case PART = "part";
case PART_LOT = "part_lot";
case STORAGE_LOCATION = "storage_location";
case SUPPLIER = "supplier";
case CURRENCY = "currency";
case ORDERDETAIL = "orderdetail";
case PRICEDETAIL = "pricedetail";
case GROUP = "group";
case USER = "user";
case PARAMETER = "parameter";
case LABEL_PROFILE = "label_profile";
case PART_ASSOCIATION = "part_association";
case BULK_INFO_PROVIDER_IMPORT_JOB = "bulk_info_provider_import_job";
case BULK_INFO_PROVIDER_IMPORT_JOB_PART = "bulk_info_provider_import_job_part";
case PART_CUSTOM_STATE = "part_custom_state";
//Child classes has to become before parent classes
private const CLASS_MAPPING = [
Attachment::class => self::ATTACHMENT,
Category::class => self::CATEGORY,
AttachmentType::class => self::ATTACHMENT_TYPE,
Project::class => self::PROJECT,
ProjectBOMEntry::class => self::PROJECT_BOM_ENTRY,
Footprint::class => self::FOOTPRINT,
Manufacturer::class => self::MANUFACTURER,
MeasurementUnit::class => self::MEASUREMENT_UNIT,
Part::class => self::PART,
PartLot::class => self::PART_LOT,
StorageLocation::class => self::STORAGE_LOCATION,
Supplier::class => self::SUPPLIER,
Currency::class => self::CURRENCY,
Orderdetail::class => self::ORDERDETAIL,
Pricedetail::class => self::PRICEDETAIL,
Group::class => self::GROUP,
User::class => self::USER,
AbstractParameter::class => self::PARAMETER,
LabelProfile::class => self::LABEL_PROFILE,
PartAssociation::class => self::PART_ASSOCIATION,
BulkInfoProviderImportJob::class => self::BULK_INFO_PROVIDER_IMPORT_JOB,
BulkInfoProviderImportJobPart::class => self::BULK_INFO_PROVIDER_IMPORT_JOB_PART,
PartCustomState::class => self::PART_CUSTOM_STATE,
];
/**
* Gets the default translation key for the label of the element type (singular form).
*/
public function getDefaultLabelKey(): string
{
return match ($this) {
self::ATTACHMENT => 'attachment.label',
self::CATEGORY => 'category.label',
self::ATTACHMENT_TYPE => 'attachment_type.label',
self::PROJECT => 'project.label',
self::PROJECT_BOM_ENTRY => 'project_bom_entry.label',
self::FOOTPRINT => 'footprint.label',
self::MANUFACTURER => 'manufacturer.label',
self::MEASUREMENT_UNIT => 'measurement_unit.label',
self::PART => 'part.label',
self::PART_LOT => 'part_lot.label',
self::STORAGE_LOCATION => 'storelocation.label',
self::SUPPLIER => 'supplier.label',
self::CURRENCY => 'currency.label',
self::ORDERDETAIL => 'orderdetail.label',
self::PRICEDETAIL => 'pricedetail.label',
self::GROUP => 'group.label',
self::USER => 'user.label',
self::PARAMETER => 'parameter.label',
self::LABEL_PROFILE => 'label_profile.label',
self::PART_ASSOCIATION => 'part_association.label',
self::BULK_INFO_PROVIDER_IMPORT_JOB => 'bulk_info_provider_import_job.label',
self::BULK_INFO_PROVIDER_IMPORT_JOB_PART => 'bulk_info_provider_import_job_part.label',
self::PART_CUSTOM_STATE => 'part_custom_state.label',
};
}
public function getDefaultPluralLabelKey(): string
{
return match ($this) {
self::ATTACHMENT => 'attachment.labelp',
self::CATEGORY => 'category.labelp',
self::ATTACHMENT_TYPE => 'attachment_type.labelp',
self::PROJECT => 'project.labelp',
self::PROJECT_BOM_ENTRY => 'project_bom_entry.labelp',
self::FOOTPRINT => 'footprint.labelp',
self::MANUFACTURER => 'manufacturer.labelp',
self::MEASUREMENT_UNIT => 'measurement_unit.labelp',
self::PART => 'part.labelp',
self::PART_LOT => 'part_lot.labelp',
self::STORAGE_LOCATION => 'storelocation.labelp',
self::SUPPLIER => 'supplier.labelp',
self::CURRENCY => 'currency.labelp',
self::ORDERDETAIL => 'orderdetail.labelp',
self::PRICEDETAIL => 'pricedetail.labelp',
self::GROUP => 'group.labelp',
self::USER => 'user.labelp',
self::PARAMETER => 'parameter.labelp',
self::LABEL_PROFILE => 'label_profile.labelp',
self::PART_ASSOCIATION => 'part_association.labelp',
self::BULK_INFO_PROVIDER_IMPORT_JOB => 'bulk_info_provider_import_job.labelp',
self::BULK_INFO_PROVIDER_IMPORT_JOB_PART => 'bulk_info_provider_import_job_part.labelp',
self::PART_CUSTOM_STATE => 'part_custom_state.labelp',
};
}
/**
* Used to get a user-friendly representation of the object that can be translated.
* For this the singular default label key is used.
* @param TranslatorInterface $translator
* @param string|null $locale
* @return string
*/
public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
return $translator->trans($this->getDefaultLabelKey(), locale: $locale);
}
/**
* Determines the ElementType from a value, which can either be an enum value, an ElementTypes instance, a class name or an object instance.
* @param string|object $value
* @return self
*/
public static function fromValue(string|object $value): self
{
if ($value instanceof self) {
return $value;
}
if (is_object($value)) {
return self::fromClass($value);
}
//Otherwise try to parse it as enum value first
$enumValue = self::tryFrom($value);
//Otherwise try to get it from class name
return $enumValue ?? self::fromClass($value);
}
/**
* Determines the ElementType from a class name or object instance.
* @param string|object $class
* @throws EntityNotSupportedException if the class is not supported
* @return self
*/
public static function fromClass(string|object $class): self
{
if (is_object($class)) {
$className = get_class($class);
} else {
$className = $class;
}
if (array_key_exists($className, self::CLASS_MAPPING)) {
return self::CLASS_MAPPING[$className];
}
//Otherwise we need to check for inheritance
foreach (self::CLASS_MAPPING as $entityClass => $elementType) {
if (is_a($className, $entityClass, true)) {
return $elementType;
}
}
throw new EntityNotSupportedException(sprintf('No localized label for the element with type %s was found!', $className));
}
}

View file

@ -38,6 +38,7 @@ use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use App\Helpers\Trees\TreeViewNode; use App\Helpers\Trees\TreeViewNode;
use App\Services\Cache\UserCacheKeyGenerator; use App\Services\Cache\UserCacheKeyGenerator;
use App\Services\ElementTypeNameGenerator;
use Symfony\Bundle\SecurityBundle\Security; use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Cache\ItemInterface; use Symfony\Contracts\Cache\ItemInterface;
@ -50,8 +51,14 @@ use Symfony\Contracts\Translation\TranslatorInterface;
*/ */
class ToolsTreeBuilder class ToolsTreeBuilder
{ {
public function __construct(protected TranslatorInterface $translator, protected UrlGeneratorInterface $urlGenerator, protected TagAwareCacheInterface $cache, protected UserCacheKeyGenerator $keyGenerator, protected Security $security) public function __construct(
{ protected TranslatorInterface $translator,
protected UrlGeneratorInterface $urlGenerator,
protected TagAwareCacheInterface $cache,
protected UserCacheKeyGenerator $keyGenerator,
protected Security $security,
private readonly ElementTypeNameGenerator $elementTypeNameGenerator,
) {
} }
/** /**
@ -160,67 +167,67 @@ class ToolsTreeBuilder
if ($this->security->isGranted('read', new AttachmentType())) { if ($this->security->isGranted('read', new AttachmentType())) {
$nodes[] = (new TreeViewNode( $nodes[] = (new TreeViewNode(
$this->translator->trans('tree.tools.edit.attachment_types'), $this->elementTypeNameGenerator->typeLabelPlural(AttachmentType::class),
$this->urlGenerator->generate('attachment_type_new') $this->urlGenerator->generate('attachment_type_new')
))->setIcon('fa-fw fa-treeview fa-solid fa-file-alt'); ))->setIcon('fa-fw fa-treeview fa-solid fa-file-alt');
} }
if ($this->security->isGranted('read', new Category())) { if ($this->security->isGranted('read', new Category())) {
$nodes[] = (new TreeViewNode( $nodes[] = (new TreeViewNode(
$this->translator->trans('tree.tools.edit.categories'), $this->elementTypeNameGenerator->typeLabelPlural(Category::class),
$this->urlGenerator->generate('category_new') $this->urlGenerator->generate('category_new')
))->setIcon('fa-fw fa-treeview fa-solid fa-tags'); ))->setIcon('fa-fw fa-treeview fa-solid fa-tags');
} }
if ($this->security->isGranted('read', new Project())) { if ($this->security->isGranted('read', new Project())) {
$nodes[] = (new TreeViewNode( $nodes[] = (new TreeViewNode(
$this->translator->trans('tree.tools.edit.projects'), $this->elementTypeNameGenerator->typeLabelPlural(Project::class),
$this->urlGenerator->generate('project_new') $this->urlGenerator->generate('project_new')
))->setIcon('fa-fw fa-treeview fa-solid fa-archive'); ))->setIcon('fa-fw fa-treeview fa-solid fa-archive');
} }
if ($this->security->isGranted('read', new Supplier())) { if ($this->security->isGranted('read', new Supplier())) {
$nodes[] = (new TreeViewNode( $nodes[] = (new TreeViewNode(
$this->translator->trans('tree.tools.edit.suppliers'), $this->elementTypeNameGenerator->typeLabelPlural(Supplier::class),
$this->urlGenerator->generate('supplier_new') $this->urlGenerator->generate('supplier_new')
))->setIcon('fa-fw fa-treeview fa-solid fa-truck'); ))->setIcon('fa-fw fa-treeview fa-solid fa-truck');
} }
if ($this->security->isGranted('read', new Manufacturer())) { if ($this->security->isGranted('read', new Manufacturer())) {
$nodes[] = (new TreeViewNode( $nodes[] = (new TreeViewNode(
$this->translator->trans('tree.tools.edit.manufacturer'), $this->elementTypeNameGenerator->typeLabelPlural(Manufacturer::class),
$this->urlGenerator->generate('manufacturer_new') $this->urlGenerator->generate('manufacturer_new')
))->setIcon('fa-fw fa-treeview fa-solid fa-industry'); ))->setIcon('fa-fw fa-treeview fa-solid fa-industry');
} }
if ($this->security->isGranted('read', new StorageLocation())) { if ($this->security->isGranted('read', new StorageLocation())) {
$nodes[] = (new TreeViewNode( $nodes[] = (new TreeViewNode(
$this->translator->trans('tree.tools.edit.storelocation'), $this->elementTypeNameGenerator->typeLabelPlural(StorageLocation::class),
$this->urlGenerator->generate('store_location_new') $this->urlGenerator->generate('store_location_new')
))->setIcon('fa-fw fa-treeview fa-solid fa-cube'); ))->setIcon('fa-fw fa-treeview fa-solid fa-cube');
} }
if ($this->security->isGranted('read', new Footprint())) { if ($this->security->isGranted('read', new Footprint())) {
$nodes[] = (new TreeViewNode( $nodes[] = (new TreeViewNode(
$this->translator->trans('tree.tools.edit.footprint'), $this->elementTypeNameGenerator->typeLabelPlural(Footprint::class),
$this->urlGenerator->generate('footprint_new') $this->urlGenerator->generate('footprint_new')
))->setIcon('fa-fw fa-treeview fa-solid fa-microchip'); ))->setIcon('fa-fw fa-treeview fa-solid fa-microchip');
} }
if ($this->security->isGranted('read', new Currency())) { if ($this->security->isGranted('read', new Currency())) {
$nodes[] = (new TreeViewNode( $nodes[] = (new TreeViewNode(
$this->translator->trans('tree.tools.edit.currency'), $this->elementTypeNameGenerator->typeLabelPlural(Currency::class),
$this->urlGenerator->generate('currency_new') $this->urlGenerator->generate('currency_new')
))->setIcon('fa-fw fa-treeview fa-solid fa-coins'); ))->setIcon('fa-fw fa-treeview fa-solid fa-coins');
} }
if ($this->security->isGranted('read', new MeasurementUnit())) { if ($this->security->isGranted('read', new MeasurementUnit())) {
$nodes[] = (new TreeViewNode( $nodes[] = (new TreeViewNode(
$this->translator->trans('tree.tools.edit.measurement_unit'), $this->elementTypeNameGenerator->typeLabelPlural(MeasurementUnit::class),
$this->urlGenerator->generate('measurement_unit_new') $this->urlGenerator->generate('measurement_unit_new')
))->setIcon('fa-fw fa-treeview fa-solid fa-balance-scale'); ))->setIcon('fa-fw fa-treeview fa-solid fa-balance-scale');
} }
if ($this->security->isGranted('read', new LabelProfile())) { if ($this->security->isGranted('read', new LabelProfile())) {
$nodes[] = (new TreeViewNode( $nodes[] = (new TreeViewNode(
$this->translator->trans('tree.tools.edit.label_profile'), $this->elementTypeNameGenerator->typeLabelPlural(LabelProfile::class),
$this->urlGenerator->generate('label_profile_new') $this->urlGenerator->generate('label_profile_new')
))->setIcon('fa-fw fa-treeview fa-solid fa-qrcode'); ))->setIcon('fa-fw fa-treeview fa-solid fa-qrcode');
} }
if ($this->security->isGranted('read', new PartCustomState())) { if ($this->security->isGranted('read', new PartCustomState())) {
$nodes[] = (new TreeViewNode( $nodes[] = (new TreeViewNode(
$this->translator->trans('tree.tools.edit.part_custom_state'), $this->elementTypeNameGenerator->typeLabelPlural(PartCustomState::class),
$this->urlGenerator->generate('part_custom_state_new') $this->urlGenerator->generate('part_custom_state_new')
))->setIcon('fa-fw fa-treeview fa-solid fa-tools'); ))->setIcon('fa-fw fa-treeview fa-solid fa-tools');
} }

View file

@ -34,9 +34,9 @@ use App\Entity\ProjectSystem\Project;
use App\Helpers\Trees\TreeViewNode; use App\Helpers\Trees\TreeViewNode;
use App\Helpers\Trees\TreeViewNodeIterator; use App\Helpers\Trees\TreeViewNodeIterator;
use App\Repository\NamedDBElementRepository; use App\Repository\NamedDBElementRepository;
use App\Repository\StructuralDBElementRepository;
use App\Services\Cache\ElementCacheTagGenerator; use App\Services\Cache\ElementCacheTagGenerator;
use App\Services\Cache\UserCacheKeyGenerator; use App\Services\Cache\UserCacheKeyGenerator;
use App\Services\ElementTypeNameGenerator;
use App\Services\EntityURLGenerator; use App\Services\EntityURLGenerator;
use App\Settings\BehaviorSettings\SidebarSettings; use App\Settings\BehaviorSettings\SidebarSettings;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -67,6 +67,7 @@ class TreeViewGenerator
protected TranslatorInterface $translator, protected TranslatorInterface $translator,
private readonly UrlGeneratorInterface $router, private readonly UrlGeneratorInterface $router,
private readonly SidebarSettings $sidebarSettings, private readonly SidebarSettings $sidebarSettings,
private readonly ElementTypeNameGenerator $elementTypeNameGenerator
) { ) {
$this->rootNodeEnabled = $this->sidebarSettings->rootNodeEnabled; $this->rootNodeEnabled = $this->sidebarSettings->rootNodeEnabled;
$this->rootNodeExpandedByDefault = $this->sidebarSettings->rootNodeExpanded; $this->rootNodeExpandedByDefault = $this->sidebarSettings->rootNodeExpanded;
@ -212,15 +213,7 @@ class TreeViewGenerator
protected function entityClassToRootNodeString(string $class): string protected function entityClassToRootNodeString(string $class): string
{ {
return match ($class) { return $this->elementTypeNameGenerator->typeLabelPlural($class);
Category::class => $this->translator->trans('category.labelp'),
StorageLocation::class => $this->translator->trans('storelocation.labelp'),
Footprint::class => $this->translator->trans('footprint.labelp'),
Manufacturer::class => $this->translator->trans('manufacturer.labelp'),
Supplier::class => $this->translator->trans('supplier.labelp'),
Project::class => $this->translator->trans('project.labelp'),
default => $this->translator->trans('tree.root_node.text'),
};
} }
protected function entityClassToRootNodeIcon(string $class): ?string protected function entityClassToRootNodeIcon(string $class): ?string

View file

@ -47,6 +47,12 @@ class AppSettings
#[EmbeddedSettings()] #[EmbeddedSettings()]
public ?InfoProviderSettings $infoProviders = null; public ?InfoProviderSettings $infoProviders = null;
#[EmbeddedSettings]
public ?SynonymSettings $synonyms = null;
#[EmbeddedSettings()] #[EmbeddedSettings()]
public ?MiscSettings $miscSettings = null; public ?MiscSettings $miscSettings = null;
} }

View file

@ -0,0 +1,116 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Settings;
use App\Form\Settings\TypeSynonymsCollectionType;
use App\Services\ElementTypes;
use Jbtronics\SettingsBundle\ParameterTypes\ArrayType;
use Jbtronics\SettingsBundle\ParameterTypes\SerializeType;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
use Symfony\Component\Translation\TranslatableMessage as TM;
use Symfony\Component\Validator\Constraints as Assert;
#[Settings(label: new TM("settings.synonyms"), description: "settings.synonyms.help")]
#[SettingsIcon("fa-language")]
class SynonymSettings
{
use SettingsTrait;
#[SettingsParameter(
ArrayType::class,
label: new TM("settings.synonyms.type_synonyms"),
description: new TM("settings.synonyms.type_synonyms.help"),
options: ['type' => SerializeType::class],
formType: TypeSynonymsCollectionType::class,
formOptions: [
'required' => false,
],
)]
#[Assert\Type('array')]
#[Assert\All([new Assert\Type('array')])]
/**
* @var array<string, array<string, array{singular: string, plural: string}>> $typeSynonyms
* An array of the form: [
* 'category' => [
* 'en' => ['singular' => 'Category', 'plural' => 'Categories'],
* 'de' => ['singular' => 'Kategorie', 'plural' => 'Kategorien'],
* ],
* 'manufacturer' => [
* 'en' => ['singular' => 'Manufacturer', 'plural' =>'Manufacturers'],
* ],
* ]
*/
public array $typeSynonyms = [];
/**
* Checks if there is any synonym defined for the given type (no matter which language).
* @param ElementTypes $type
* @return bool
*/
public function isSynonymDefinedForType(ElementTypes $type): bool
{
return isset($this->typeSynonyms[$type->value]) && count($this->typeSynonyms[$type->value]) > 0;
}
/**
* Returns the singular synonym for the given type and locale, or null if none is defined.
* @param ElementTypes $type
* @param string $locale
* @return string|null
*/
public function getSingularSynonymForType(ElementTypes $type, string $locale): ?string
{
return $this->typeSynonyms[$type->value][$locale]['singular'] ?? null;
}
/**
* Returns the plural synonym for the given type and locale, or null if none is defined.
* @param ElementTypes $type
* @param string|null $locale
* @return string|null
*/
public function getPluralSynonymForType(ElementTypes $type, ?string $locale): ?string
{
return $this->typeSynonyms[$type->value][$locale]['plural']
?? $this->typeSynonyms[$type->value][$locale]['singular']
?? null;
}
/**
* Sets a synonym for the given type and locale.
* @param ElementTypes $type
* @param string $locale
* @param string $singular
* @param string $plural
* @return void
*/
public function setSynonymForType(ElementTypes $type, string $locale, string $singular, string $plural): void
{
$this->typeSynonyms[$type->value][$locale] = [
'singular' => $singular,
'plural' => $plural,
];
}
}

View file

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace App\Settings\SystemSettings; namespace App\Settings\SystemSettings;
use App\Form\Type\LanguageMenuEntriesType; use App\Form\Settings\LanguageMenuEntriesType;
use App\Form\Type\LocaleSelectType; use App\Form\Type\LocaleSelectType;
use App\Settings\SettingsIcon; use App\Settings\SettingsIcon;
use Jbtronics\SettingsBundle\Metadata\EnvVarMode; use Jbtronics\SettingsBundle\Metadata\EnvVarMode;

View file

@ -33,6 +33,8 @@ class SystemSettings
#[EmbeddedSettings()] #[EmbeddedSettings()]
public ?LocalizationSettings $localization = null; public ?LocalizationSettings $localization = null;
#[EmbeddedSettings()] #[EmbeddedSettings()]
public ?CustomizationSettings $customization = null; public ?CustomizationSettings $customization = null;

View file

@ -76,6 +76,8 @@ final class EntityExtension extends AbstractExtension
/* Gets a human readable label for the type of the given entity */ /* Gets a human readable label for the type of the given entity */
new TwigFunction('entity_type_label', fn(object|string $entity): string => $this->nameGenerator->getLocalizedTypeLabel($entity)), new TwigFunction('entity_type_label', fn(object|string $entity): string => $this->nameGenerator->getLocalizedTypeLabel($entity)),
new TwigFunction('type_label', fn(object|string $entity): string => $this->nameGenerator->typeLabel($entity)),
new TwigFunction('type_label_p', fn(object|string $entity): string => $this->nameGenerator->typeLabelPlural($entity)),
]; ];
} }

View file

@ -1,7 +1,7 @@
{% extends "admin/base_admin.html.twig" %} {% extends "admin/base_admin.html.twig" %}
{% block card_title %} {% block card_title %}
<i class="fas fa-tags fa-fw"></i> {% trans %}category.labelp{% endtrans %} <i class="fas fa-tags fa-fw"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}
{% block additional_pills %} {% block additional_pills %}

View file

@ -3,7 +3,7 @@
{% import "vars.macro.twig" as vars %} {% import "vars.macro.twig" as vars %}
{% block card_title %} {% block card_title %}
<i class="fa-solid fa-coins"></i> {% trans %}currency.caption{% endtrans %} <i class="fa-solid fa-coins"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}
{% block additional_controls %} {% block additional_controls %}

View file

@ -1,7 +1,7 @@
{% extends "admin/base_admin.html.twig" %} {% extends "admin/base_admin.html.twig" %}
{% block card_title %} {% block card_title %}
<i class="fas fa-microchip fa-fw"></i> {% trans %}footprint.labelp{% endtrans %} <i class="fas fa-microchip fa-fw"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}
{% block master_picture_block %} {% block master_picture_block %}

View file

@ -1,7 +1,7 @@
{% extends "admin/base_admin.html.twig" %} {% extends "admin/base_admin.html.twig" %}
{% block card_title %} {% block card_title %}
<i class="fas fa-users fa-fw"></i> {% trans %}group.edit.caption{% endtrans %} <i class="fas fa-users fa-fw"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}

View file

@ -1,7 +1,7 @@
{% extends "admin/base_admin.html.twig" %} {% extends "admin/base_admin.html.twig" %}
{% block card_title %} {% block card_title %}
<i class="fas fa-qrcode fa-fw"></i> {% trans %}label_profile.caption{% endtrans %} <i class="fas fa-qrcode fa-fw"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}
{% block additional_pills %} {% block additional_pills %}

View file

@ -1,7 +1,7 @@
{% extends "admin/base_company_admin.html.twig" %} {% extends "admin/base_company_admin.html.twig" %}
{% block card_title %} {% block card_title %}
<i class="fas fa-industry fa-fw"></i> {% trans %}manufacturer.caption{% endtrans %} <i class="fas fa-industry fa-fw"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}
{% block edit_title %} {% block edit_title %}

View file

@ -1,7 +1,7 @@
{% extends "admin/base_admin.html.twig" %} {% extends "admin/base_admin.html.twig" %}
{% block card_title %} {% block card_title %}
<i class="fas fa-balance-scale fa-fw"></i> {% trans %}measurement_unit.caption{% endtrans %} <i class="fas fa-balance-scale fa-fw"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}
{% block edit_title %} {% block edit_title %}

View file

@ -1,7 +1,7 @@
{% extends "admin/base_admin.html.twig" %} {% extends "admin/base_admin.html.twig" %}
{% block card_title %} {% block card_title %}
<i class="fas fa-balance-scale fa-tools"></i> {% trans %}part_custom_state.caption{% endtrans %} <i class="fas fa-balance-scale fa-tools"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}
{% block edit_title %} {% block edit_title %}

View file

@ -3,7 +3,7 @@
{# @var entity App\Entity\ProjectSystem\Project #} {# @var entity App\Entity\ProjectSystem\Project #}
{% block card_title %} {% block card_title %}
<i class="fas fa-archive fa-fw"></i> {% trans %}project.caption{% endtrans %} <i class="fas fa-archive fa-fw"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}
{% block edit_title %} {% block edit_title %}

View file

@ -2,7 +2,7 @@
{% import "label_system/dropdown_macro.html.twig" as dropdown %} {% import "label_system/dropdown_macro.html.twig" as dropdown %}
{% block card_title %} {% block card_title %}
<i class="fas fa-cube fa-fw"></i> {% trans %}storelocation.labelp{% endtrans %} <i class="fas fa-cube fa-fw"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}
{% block additional_controls %} {% block additional_controls %}

View file

@ -1,7 +1,7 @@
{% extends "admin/base_company_admin.html.twig" %} {% extends "admin/base_company_admin.html.twig" %}
{% block card_title %} {% block card_title %}
<i class="fas fa-truck fa-fw"></i> {% trans %}supplier.caption{% endtrans %} <i class="fas fa-truck fa-fw"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}
{% block additional_panes %} {% block additional_panes %}

View file

@ -5,7 +5,7 @@
{# @var entity \App\Entity\UserSystem\User #} {# @var entity \App\Entity\UserSystem\User #}
{% block card_title %} {% block card_title %}
<i class="fas fa-user fa-fw"></i> {% trans %}user.edit.caption{% endtrans %} <i class="fas fa-user fa-fw"></i> {{ type_label_p(entity) }}
{% endblock %} {% endblock %}
{% block comment %}{% endblock %} {% block comment %}{% endblock %}

View file

@ -1,13 +1,15 @@
{% macro sidebar_dropdown() %} {% macro sidebar_dropdown() %}
{% set currentLocale = app.request.locale %}
{# Format is [mode, route, label, show_condition] #} {# Format is [mode, route, label, show_condition] #}
{% set data_sources = [ {% set data_sources = [
['categories', path('tree_category_root'), 'category.labelp', is_granted('@categories.read') and is_granted('@parts.read')], ['categories', path('tree_category_root'), '@category@@', is_granted('@categories.read') and is_granted('@parts.read')],
['locations', path('tree_location_root'), 'storelocation.labelp', is_granted('@storelocations.read') and is_granted('@parts.read')], ['locations', path('tree_location_root'), '@storage_location@@', is_granted('@storelocations.read') and is_granted('@parts.read'), ],
['footprints', path('tree_footprint_root'), 'footprint.labelp', is_granted('@footprints.read') and is_granted('@parts.read')], ['footprints', path('tree_footprint_root'), '@footprint@@', is_granted('@footprints.read') and is_granted('@parts.read')],
['manufacturers', path('tree_manufacturer_root'), 'manufacturer.labelp', is_granted('@manufacturers.read') and is_granted('@parts.read')], ['manufacturers', path('tree_manufacturer_root'), '@manufacturer@@', is_granted('@manufacturers.read') and is_granted('@parts.read'), 'manufacturer'],
['suppliers', path('tree_supplier_root'), 'supplier.labelp', is_granted('@suppliers.read') and is_granted('@parts.read')], ['suppliers', path('tree_supplier_root'), '@supplier@@', is_granted('@suppliers.read') and is_granted('@parts.read'), 'supplier'],
['projects', path('tree_device_root'), 'project.labelp', is_granted('@projects.read')], ['projects', path('tree_device_root'), '@project@@', is_granted('@projects.read'), 'project'],
['tools', path('tree_tools'), 'tools.label', true], ['tools', path('tree_tools'), 'tools.label', true, 'tool'],
] %} ] %}
<li class="dropdown-header">{% trans %}actions{% endtrans %}</li> <li class="dropdown-header">{% trans %}actions{% endtrans %}</li>
@ -18,9 +20,20 @@
{% for source in data_sources %} {% for source in data_sources %}
{% if source[3] %} {# show_condition #} {% if source[3] %} {# show_condition #}
<li><button class="tree-btns dropdown-item" data-mode="{{ source[0] }}" data-url="{{ source[1] }}" data-text="{{ source[2] | trans }}" <li>
{% if source[2] starts with '@' %}
{% set label = type_label_p(source[2]|replace({'@': ''})) %}
{% else %}
{% set label = source[2]|trans %}
{% endif %}
<button class="tree-btns dropdown-item"
data-mode="{{ source[0] }}"
data-url="{{ source[1] }}"
data-text="{{ label }}"
{{ stimulus_action('elements/sidebar_tree', 'changeDataSource') }} {{ stimulus_action('elements/sidebar_tree', 'changeDataSource') }}
>{{ source[2] | trans }}</button></li> >{{ label }}</button>
</li>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endmacro %} {% endmacro %}

View file

@ -0,0 +1,59 @@
{% macro renderForm(child) %}
<div class="tc-item mt-1 px-2 pb-1 border-bottom">
{% form_theme child "form/vertical_bootstrap_layout.html.twig" %}
<div class="row">
<div class="col">{{ form_row(child.dataSource) }}</div>
<div class="col">{{ form_row(child.locale) }}</div>
<div class="col">{{ form_row(child.translation_singular) }}</div>
<div class="col">{{ form_row(child.translation_plural) }}</div>
<div class="col">
<button type="button" class="btn btn-outline-danger btn-sm tc-remove" {{ stimulus_action('pages/synonyms_collection', 'remove' )}}>
<i class="fa fa-trash"></i> {{ 'settings.synonyms.type_synonym.remove_entry'|trans }}
</button>
</div>
</div>
</div>
{% endmacro %}
{% block type_synonyms_collection_widget %}
{% set _attrs = attr|default({}) %}
{% set _attrs = _attrs|merge({
class: (_attrs.class|default('') ~ ' type_synonyms_collection-widget')|trim
}) %}
{% set has_proto = prototype is defined %}
{% if has_proto %}
{% set __proto %}
{{- _self.renderForm(prototype) -}}
{% endset %}
{% set _proto_html = __proto|e('html_attr') %}
{% set _proto_name = form.vars.prototype_name|default('__name__') %}
{% set _index = form|length %}
{% endif %}
<div
{{ stimulus_controller('pages/synonyms_collection', {
prototype: has_proto ? _proto_html : '',
prototypeName: has_proto ? _proto_name : '__name__',
index: has_proto ? _index : (form|length)
}) }}
{{ block('widget_container_attributes')|raw }}{% for k,v in _attrs %} {{ k }}="{{ v }}"{% endfor %}
>
<div class="row">
<div class="col text-center"><strong>{% trans%}settings.synonyms.type_synonym.type{% endtrans%}</strong></div>
<div class="col text-center"><strong>{% trans%}settings.synonyms.type_synonym.language{% endtrans%}</strong></div>
<div class="col text-center"><strong>{% trans%}settings.synonyms.type_synonym.translation_singular{% endtrans%}</strong></div>
<div class="col text-center"><strong>{% trans%}settings.synonyms.type_synonym.translation_plural{% endtrans%}</strong></div>
<div class="col text-center"></div>
</div>
<div class="tc-items" {{ stimulus_target('pages/synonyms_collection', 'items') }}>
{% for child in form %}
{{ _self.renderForm(child) }}
{% endfor %}
</div>
<button type="button" class="btn btn-outline-primary btn-sm mt-2 tc-add" {{ stimulus_action('pages/synonyms_collection', 'add')}}>
<i class="fa fa-plus"></i> {{ 'settings.synonyms.type_synonym.add_entry'|trans }}
</button>
</div>
{% endblock %}

View file

@ -0,0 +1,26 @@
{% extends 'bootstrap_5_layout.html.twig' %}
{%- block choice_widget_collapsed -%}
{# Only add the BS5 form-select class if we dont use bootstrap-selectpicker #}
{# {% if attr["data-controller"] is defined and attr["data-controller"] not in ["elements--selectpicker"] %}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-select')|trim}) -%}
{% else %}
{# If it is an selectpicker add form-control class to fill whole width
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) -%}
{% endif %}
#}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-select')|trim}) -%}
{# If no data-controller was explictly defined add data-controller=elements--select #}
{% if attr["data-controller"] is not defined %}
{%- set attr = attr|merge({"data-controller": "elements--select"}) -%}
{% if attr["data-empty-message"] is not defined %}
{%- set attr = attr|merge({"data-empty-message": ("selectpicker.nothing_selected"|trans)}) -%}
{% endif %}
{% endif %}
{{- block("choice_widget_collapsed", "bootstrap_base_layout.html.twig") -}}
{%- endblock choice_widget_collapsed -%}

View file

@ -36,7 +36,7 @@
{% for section_widget in tab_widget %} {% for section_widget in tab_widget %}
{% set settings_object = section_widget.vars.value %} {% set settings_object = section_widget.vars.value %}
{% if section_widget.vars.compound ?? false %} {% if section_widget.vars.embedded_settings_metadata is defined %} {# Check if we have nested embedded settings or not #}
<fieldset> <fieldset>
<legend class="offset-3"> <legend class="offset-3">
<i class="fa-solid {{ settings_icon(settings_object)|default('fa-sliders') }} fa-fw"></i> <i class="fa-solid {{ settings_icon(settings_object)|default('fa-sliders') }} fa-fw"></i>

View file

@ -0,0 +1,49 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Tests\EventListener;
use App\EventListener\RegisterSynonymsAsTranslationParametersListener;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class RegisterSynonymsAsTranslationParametersTest extends KernelTestCase
{
private RegisterSynonymsAsTranslationParametersListener $listener;
public function setUp(): void
{
self::bootKernel();
$this->listener = self::getContainer()->get(RegisterSynonymsAsTranslationParametersListener::class);
}
public function testGetSynonymPlaceholders(): void
{
$placeholders = $this->listener->getSynonymPlaceholders();
$this->assertIsArray($placeholders);
$this->assertSame('Part', $placeholders['{part}']);
$this->assertSame('Parts', $placeholders['{{part}}']);
//Lowercase versions:
$this->assertSame('part', $placeholders['[part]']);
$this->assertSame('parts', $placeholders['[[part]]']);
}
}

View file

@ -30,20 +30,27 @@ use App\Entity\Parts\Category;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Exceptions\EntityNotSupportedException; use App\Exceptions\EntityNotSupportedException;
use App\Services\ElementTypeNameGenerator; use App\Services\ElementTypeNameGenerator;
use App\Services\ElementTypes;
use App\Services\Formatters\AmountFormatter; use App\Services\Formatters\AmountFormatter;
use App\Settings\SynonymSettings;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ElementTypeNameGeneratorTest extends WebTestCase class ElementTypeNameGeneratorTest extends WebTestCase
{ {
/** protected ElementTypeNameGenerator $service;
* @var AmountFormatter private SynonymSettings $synonymSettings;
*/
protected $service;
protected function setUp(): void protected function setUp(): void
{ {
//Get an service instance. //Get an service instance.
$this->service = self::getContainer()->get(ElementTypeNameGenerator::class); $this->service = self::getContainer()->get(ElementTypeNameGenerator::class);
$this->synonymSettings = self::getContainer()->get(SynonymSettings::class);
}
protected function tearDown(): void
{
//Clean up synonym settings
$this->synonymSettings->typeSynonyms = [];
} }
public function testGetLocalizedTypeNameCombination(): void public function testGetLocalizedTypeNameCombination(): void
@ -84,4 +91,30 @@ class ElementTypeNameGeneratorTest extends WebTestCase
} }
}); });
} }
public function testTypeLabel(): void
{
//If no synonym is defined, the default label should be used
$this->assertSame('Part', $this->service->typeLabel(Part::class));
$this->assertSame('Part', $this->service->typeLabel(new Part()));
$this->assertSame('Part', $this->service->typeLabel(ElementTypes::PART));
$this->assertSame('Part', $this->service->typeLabel('part'));
//Define a synonym for parts in english
$this->synonymSettings->setSynonymForType(ElementTypes::PART, 'en', 'Singular', 'Plurals');
$this->assertSame('Singular', $this->service->typeLabel(Part::class));
}
public function testTypeLabelPlural(): void
{
//If no synonym is defined, the default label should be used
$this->assertSame('Parts', $this->service->typeLabelPlural(Part::class));
$this->assertSame('Parts', $this->service->typeLabelPlural(new Part()));
$this->assertSame('Parts', $this->service->typeLabelPlural(ElementTypes::PART));
$this->assertSame('Parts', $this->service->typeLabelPlural('part'));
//Define a synonym for parts in english
$this->synonymSettings->setSynonymForType(ElementTypes::PART, 'en', 'Singular', 'Plurals');
$this->assertSame('Plurals', $this->service->typeLabelPlural(Part::class));
}
} }

View file

@ -0,0 +1,79 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Tests\Services;
use App\Entity\Parameters\CategoryParameter;
use App\Entity\Parts\Category;
use App\Exceptions\EntityNotSupportedException;
use App\Services\ElementTypes;
use PHPUnit\Framework\TestCase;
class ElementTypesTest extends TestCase
{
public function testFromClass(): void
{
$this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromClass(Category::class));
$this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromClass(new Category()));
//Should also work with subclasses
$this->assertSame(ElementTypes::PARAMETER, ElementTypes::fromClass(CategoryParameter::class));
$this->assertSame(ElementTypes::PARAMETER, ElementTypes::fromClass(new CategoryParameter()));
}
public function testFromClassNotExisting(): void
{
$this->expectException(EntityNotSupportedException::class);
ElementTypes::fromClass(\LogicException::class);
}
public function testFromValue(): void
{
//By enum value
$this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromValue('category'));
$this->assertSame(ElementTypes::ATTACHMENT, ElementTypes::fromValue('attachment'));
//From enum instance
$this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromValue(ElementTypes::CATEGORY));
//From class string
$this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromValue(Category::class));
$this->assertSame(ElementTypes::PARAMETER, ElementTypes::fromValue(CategoryParameter::class));
//From class instance
$this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromValue(new Category()));
$this->assertSame(ElementTypes::PARAMETER, ElementTypes::fromValue(new CategoryParameter()));
}
public function testGetDefaultLabelKey(): void
{
$this->assertSame('category.label', ElementTypes::CATEGORY->getDefaultLabelKey());
$this->assertSame('attachment.label', ElementTypes::ATTACHMENT->getDefaultLabelKey());
}
public function testGetDefaultPluralLabelKey(): void
{
$this->assertSame('category.labelp', ElementTypes::CATEGORY->getDefaultPluralLabelKey());
$this->assertSame('attachment.labelp', ElementTypes::ATTACHMENT->getDefaultPluralLabelKey());
}
}

View file

@ -0,0 +1,76 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Tests\Settings;
use App\Services\ElementTypes;
use App\Settings\SynonymSettings;
use App\Tests\SettingsTestHelper;
use PHPUnit\Framework\TestCase;
class SynonymSettingsTest extends TestCase
{
public function testGetSingularSynonymForType(): void
{
$settings = SettingsTestHelper::createSettingsDummy(SynonymSettings::class);
$settings->typeSynonyms['category'] = [
'en' => ['singular' => 'Category', 'plural' => 'Categories'],
'de' => ['singular' => 'Kategorie', 'plural' => 'Kategorien'],
];
$this->assertEquals('Category', $settings->getSingularSynonymForType(ElementTypes::CATEGORY, 'en'));
$this->assertEquals('Kategorie', $settings->getSingularSynonymForType(ElementTypes::CATEGORY, 'de'));
//If no synonym is defined, it should return null
$this->assertNull($settings->getSingularSynonymForType(ElementTypes::MANUFACTURER, 'en'));
}
public function testIsSynonymDefinedForType(): void
{
$settings = SettingsTestHelper::createSettingsDummy(SynonymSettings::class);
$settings->typeSynonyms['category'] = [
'en' => ['singular' => 'Category', 'plural' => 'Categories'],
'de' => ['singular' => 'Kategorie', 'plural' => 'Kategorien'],
];
$settings->typeSynonyms['supplier'] = [];
$this->assertTrue($settings->isSynonymDefinedForType(ElementTypes::CATEGORY));
$this->assertFalse($settings->isSynonymDefinedForType(ElementTypes::FOOTPRINT));
$this->assertFalse($settings->isSynonymDefinedForType(ElementTypes::SUPPLIER));
}
public function testGetPluralSynonymForType(): void
{
$settings = SettingsTestHelper::createSettingsDummy(SynonymSettings::class);
$settings->typeSynonyms['category'] = [
'en' => ['singular' => 'Category', 'plural' => 'Categories'],
'de' => ['singular' => 'Kategorie',],
];
$this->assertEquals('Categories', $settings->getPluralSynonymForType(ElementTypes::CATEGORY, 'en'));
//Fallback to singular if no plural is defined
$this->assertEquals('Kategorie', $settings->getPluralSynonymForType(ElementTypes::CATEGORY, 'de'));
//If no synonym is defined, it should return null
$this->assertNull($settings->getPluralSynonymForType(ElementTypes::MANUFACTURER, 'en'));
}
}

View file

@ -97,16 +97,6 @@
<target>New category</target> <target>New category</target>
</segment> </segment>
</unit> </unit>
<unit id="z1GMBc_" name="currency.caption">
<notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\CurrencyAdmin.html.twig:4</note>
<note priority="1">Part-DB1\templates\AdminPages\CurrencyAdmin.html.twig:4</note>
</notes>
<segment state="translated">
<source>currency.caption</source>
<target>Currency</target>
</segment>
</unit>
<unit id="KSFhj_3" name="currency.iso_code.caption"> <unit id="KSFhj_3" name="currency.iso_code.caption">
<notes> <notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\CurrencyAdmin.html.twig:12</note> <note category="file-source" priority="1">Part-DB1\templates\AdminPages\CurrencyAdmin.html.twig:12</note>
@ -418,16 +408,6 @@
<target>New footprint</target> <target>New footprint</target>
</segment> </segment>
</unit> </unit>
<unit id="tvm4F9e" name="group.edit.caption">
<notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\GroupAdmin.html.twig:4</note>
<note priority="1">Part-DB1\templates\AdminPages\GroupAdmin.html.twig:4</note>
</notes>
<segment state="translated">
<source>group.edit.caption</source>
<target>Groups</target>
</segment>
</unit>
<unit id="m27aWeR" name="user.edit.permissions"> <unit id="m27aWeR" name="user.edit.permissions">
<notes> <notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\GroupAdmin.html.twig:9</note> <note category="file-source" priority="1">Part-DB1\templates\AdminPages\GroupAdmin.html.twig:9</note>
@ -460,15 +440,6 @@
<target>New group</target> <target>New group</target>
</segment> </segment>
</unit> </unit>
<unit id="jXqdnm_" name="label_profile.caption">
<notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\LabelProfileAdmin.html.twig:4</note>
</notes>
<segment state="translated">
<source>label_profile.caption</source>
<target>Label profiles</target>
</segment>
</unit>
<unit id="GgwITAf" name="label_profile.advanced"> <unit id="GgwITAf" name="label_profile.advanced">
<notes> <notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\LabelProfileAdmin.html.twig:8</note> <note category="file-source" priority="1">Part-DB1\templates\AdminPages\LabelProfileAdmin.html.twig:8</note>
@ -507,17 +478,6 @@
<target>New label profile</target> <target>New label profile</target>
</segment> </segment>
</unit> </unit>
<unit id="r3pQ31P" name="manufacturer.caption">
<notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\ManufacturerAdmin.html.twig:4</note>
<note priority="1">Part-DB1\templates\AdminPages\ManufacturerAdmin.html.twig:4</note>
<note priority="1">templates\AdminPages\ManufacturerAdmin.html.twig:4</note>
</notes>
<segment state="translated">
<source>manufacturer.caption</source>
<target>Manufacturers</target>
</segment>
</unit>
<unit id="AVQBOWW" name="manufacturer.edit"> <unit id="AVQBOWW" name="manufacturer.edit">
<notes> <notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\ManufacturerAdmin.html.twig:8</note> <note category="file-source" priority="1">Part-DB1\templates\AdminPages\ManufacturerAdmin.html.twig:8</note>
@ -538,22 +498,6 @@
<target>New manufacturer</target> <target>New manufacturer</target>
</segment> </segment>
</unit> </unit>
<unit id="3ra2AyY" name="measurement_unit.caption">
<notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\MeasurementUnitAdmin.html.twig:4</note>
<note priority="1">Part-DB1\templates\AdminPages\MeasurementUnitAdmin.html.twig:4</note>
</notes>
<segment state="translated">
<source>measurement_unit.caption</source>
<target>Measurement Unit</target>
</segment>
</unit>
<unit id="3bcKBzY" name="part_custom_state.caption">
<segment state="translated">
<source>part_custom_state.caption</source>
<target>Custom part states</target>
</segment>
</unit>
<unit id="crdkzlg" name="storelocation.labelp"> <unit id="crdkzlg" name="storelocation.labelp">
<notes> <notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5</note> <note category="file-source" priority="1">Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5</note>
@ -620,16 +564,6 @@
<target>New supplier</target> <target>New supplier</target>
</segment> </segment>
</unit> </unit>
<unit id="vX.dhjK" name="user.edit.caption">
<notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\UserAdmin.html.twig:8</note>
<note priority="1">Part-DB1\templates\AdminPages\UserAdmin.html.twig:8</note>
</notes>
<segment state="translated">
<source>user.edit.caption</source>
<target>Users</target>
</segment>
</unit>
<unit id="Ux8wVuF" name="user.edit.configuration"> <unit id="Ux8wVuF" name="user.edit.configuration">
<notes> <notes>
<note category="file-source" priority="1">Part-DB1\templates\AdminPages\UserAdmin.html.twig:14</note> <note category="file-source" priority="1">Part-DB1\templates\AdminPages\UserAdmin.html.twig:14</note>
@ -4897,7 +4831,7 @@ If you have done this incorrectly or if a computer is no longer trusted, you can
<target>Measurement Unit</target> <target>Measurement Unit</target>
</segment> </segment>
</unit> </unit>
<unit id="G1hmQdb" name="part.table.partCustomState"> <unit id="JjTO6Nq" name="part.table.partCustomState">
<segment state="translated"> <segment state="translated">
<source>part.table.partCustomState</source> <source>part.table.partCustomState</source>
<target>Custom part state</target> <target>Custom part state</target>
@ -5767,7 +5701,7 @@ If you have done this incorrectly or if a computer is no longer trusted, you can
<target>Measuring unit</target> <target>Measuring unit</target>
</segment> </segment>
</unit> </unit>
<unit id="G1hmQdb" name="part.edit.partCustomState"> <unit id="ro8Iwr_" name="part.edit.partCustomState">
<segment state="translated"> <segment state="translated">
<source>part.edit.partCustomState</source> <source>part.edit.partCustomState</source>
<target>Custom part state</target> <target>Custom part state</target>
@ -6060,7 +5994,7 @@ If you have done this incorrectly or if a computer is no longer trusted, you can
<target>Measurement unit</target> <target>Measurement unit</target>
</segment> </segment>
</unit> </unit>
<unit id="a1mPcMw" name="part_custom_state.label"> <unit id="NpDx4rr" name="part_custom_state.label">
<segment state="translated"> <segment state="translated">
<source>part_custom_state.label</source> <source>part_custom_state.label</source>
<target>Custom part state</target> <target>Custom part state</target>
@ -6309,7 +6243,7 @@ If you have done this incorrectly or if a computer is no longer trusted, you can
<target>Measurement Unit</target> <target>Measurement Unit</target>
</segment> </segment>
</unit> </unit>
<unit id="5adacKb" name="tree.tools.edit.part_custom_state"> <unit id="oYLWbbv" name="tree.tools.edit.part_custom_state">
<segment state="translated"> <segment state="translated">
<source>tree.tools.edit.part_custom_state</source> <source>tree.tools.edit.part_custom_state</source>
<target>Custom part states</target> <target>Custom part states</target>
@ -7724,16 +7658,6 @@ Element 1 -> Element 1.2]]></target>
<target>System</target> <target>System</target>
</segment> </segment>
</unit> </unit>
<unit id="QpKjLiE" name="perm.parts">
<notes>
<note priority="1">obsolete</note>
<note category="state" priority="1">obsolete</note>
</notes>
<segment state="translated">
<source>perm.parts</source>
<target>Parts</target>
</segment>
</unit>
<unit id="lkP7BGp" name="perm.read"> <unit id="lkP7BGp" name="perm.read">
<notes> <notes>
<note priority="1">obsolete</note> <note priority="1">obsolete</note>
@ -7994,16 +7918,6 @@ Element 1 -> Element 1.2]]></target>
<target>Orders</target> <target>Orders</target>
</segment> </segment>
</unit> </unit>
<unit id="9e70TDD" name="perm.storelocations">
<notes>
<note priority="1">obsolete</note>
<note category="state" priority="1">obsolete</note>
</notes>
<segment state="translated">
<source>perm.storelocations</source>
<target>Storage locations</target>
</segment>
</unit>
<unit id="iKqTace" name="perm.move"> <unit id="iKqTace" name="perm.move">
<notes> <notes>
<note priority="1">obsolete</note> <note priority="1">obsolete</note>
@ -8024,66 +7938,6 @@ Element 1 -> Element 1.2]]></target>
<target>List parts</target> <target>List parts</target>
</segment> </segment>
</unit> </unit>
<unit id="qp4Nw88" name="perm.part.footprints">
<notes>
<note priority="1">obsolete</note>
<note category="state" priority="1">obsolete</note>
</notes>
<segment state="translated">
<source>perm.part.footprints</source>
<target>Footprints</target>
</segment>
</unit>
<unit id="ochCbWd" name="perm.part.categories">
<notes>
<note priority="1">obsolete</note>
<note category="state" priority="1">obsolete</note>
</notes>
<segment state="translated">
<source>perm.part.categories</source>
<target>Categories</target>
</segment>
</unit>
<unit id="gJeta6V" name="perm.part.supplier">
<notes>
<note priority="1">obsolete</note>
<note category="state" priority="1">obsolete</note>
</notes>
<segment state="translated">
<source>perm.part.supplier</source>
<target>Suppliers</target>
</segment>
</unit>
<unit id="AAW9ULn" name="perm.part.manufacturers">
<notes>
<note priority="1">obsolete</note>
<note category="state" priority="1">obsolete</note>
</notes>
<segment state="translated">
<source>perm.part.manufacturers</source>
<target>Manufacturers</target>
</segment>
</unit>
<unit id="xIsPPzY" name="perm.projects">
<notes>
<note priority="1">obsolete</note>
<note category="state" priority="1">obsolete</note>
</notes>
<segment state="translated">
<source>perm.projects</source>
<target>Projects</target>
</segment>
</unit>
<unit id="Fa9cXuf" name="perm.part.attachment_types">
<notes>
<note priority="1">obsolete</note>
<note category="state" priority="1">obsolete</note>
</notes>
<segment state="translated">
<source>perm.part.attachment_types</source>
<target>Attachment types</target>
</segment>
</unit>
<unit id="lIHo4Hd" name="perm.tools.import"> <unit id="lIHo4Hd" name="perm.tools.import">
<notes> <notes>
<note priority="1">obsolete</note> <note priority="1">obsolete</note>
@ -8594,12 +8448,6 @@ Element 1 -> Element 1.2]]></target>
<target>Measurement unit</target> <target>Measurement unit</target>
</segment> </segment>
</unit> </unit>
<unit id="1b5ja1c" name="perm.part_custom_states">
<segment state="translated">
<source>perm.part_custom_states</source>
<target>Custom part state</target>
</segment>
</unit>
<unit id="coNue69" name="user.settings.pw_old.label"> <unit id="coNue69" name="user.settings.pw_old.label">
<notes> <notes>
<note priority="1">obsolete</note> <note priority="1">obsolete</note>
@ -10995,7 +10843,7 @@ Element 1 -> Element 1.2]]></target>
<target>Measuring Unit</target> <target>Measuring Unit</target>
</segment> </segment>
</unit> </unit>
<unit id="2COnw1k" name="log.element_edited.changed_fields.partCustomState"> <unit id="8QD.2.r" name="log.element_edited.changed_fields.partCustomState">
<segment state="translated"> <segment state="translated">
<source>log.element_edited.changed_fields.partCustomState</source> <source>log.element_edited.changed_fields.partCustomState</source>
<target>Custom part state</target> <target>Custom part state</target>
@ -11265,13 +11113,13 @@ Element 1 -> Element 1.2]]></target>
<target>Edit Measurement Unit</target> <target>Edit Measurement Unit</target>
</segment> </segment>
</unit> </unit>
<unit id="ba52d.g" name="part_custom_state.new"> <unit id="Ae0GMtY" name="part_custom_state.new">
<segment state="translated"> <segment state="translated">
<source>part_custom_state.new</source> <source>part_custom_state.new</source>
<target>New custom part state</target> <target>New custom part state</target>
</segment> </segment>
</unit> </unit>
<unit id="c1.gb2d" name="part_custom_state.edit"> <unit id="5uZ23wR" name="part_custom_state.edit">
<segment state="translated"> <segment state="translated">
<source>part_custom_state.edit</source> <source>part_custom_state.edit</source>
<target>Edit custom part state</target> <target>Edit custom part state</target>
@ -14406,31 +14254,6 @@ Please note, that you can not impersonate a disabled user. If you try you will g
<target><![CDATA[The languages to show in the language drop-down menu. Order can be changed via drag & drop. Leave empty to show all available languages.]]></target> <target><![CDATA[The languages to show in the language drop-down menu. Order can be changed via drag & drop. Leave empty to show all available languages.]]></target>
</segment> </segment>
</unit> </unit>
<unit id="xIZ_mEX" name="project.builds.no_bom_entries">
<segment>
<source>project.builds.no_bom_entries</source>
<target>Project has no BOM entries</target>
</segment>
</unit>
<unit id="pCKgjIr" name="settings.behavior.sidebar.data_structure_nodes_table_include_children">
<segment>
<source>settings.behavior.sidebar.data_structure_nodes_table_include_children</source>
<target>Tables should include children nodes by default</target>
</segment>
</unit>
<unit id="KJQHfwV" name="settings.behavior.sidebar.data_structure_nodes_table_include_children.help">
<segment>
<source>settings.behavior.sidebar.data_structure_nodes_table_include_children.help</source>
<target>If checked, the part tables for categories, footprints, etc. should include all parts of child categories. If not checked, only parts that strictly belong to the clicked node are shown.</target>
</segment>
</unit>
<unit id="Gdlnmav" name="info_providers.search.error.oauth_reconnect">
<segment>
<source>info_providers.search.error.oauth_reconnect</source>
<target>You need to reconnect OAuth for following providers: %provider%
You can do this in the provider info list.</target>
</segment>
</unit>
<unit id="xIZ_mEX" name="project.builds.no_bom_entries"> <unit id="xIZ_mEX" name="project.builds.no_bom_entries">
<segment state="translated"> <segment state="translated">
<source>project.builds.no_bom_entries</source> <source>project.builds.no_bom_entries</source>
@ -14468,5 +14291,126 @@ You can do this in the provider info list.</target>
<target>A PCRE-compatible regular expression every IPN has to fulfill. Leave empty to allow all everything as IPN. </target> <target>A PCRE-compatible regular expression every IPN has to fulfill. Leave empty to allow all everything as IPN. </target>
</segment> </segment>
</unit> </unit>
<unit id="MoHHSNT" name="user.labelp">
<segment>
<source>user.labelp</source>
<target>Users</target>
</segment>
</unit>
<unit id="5.oI1XD" name="currency.labelp">
<segment>
<source>currency.labelp</source>
<target>Currencies</target>
</segment>
</unit>
<unit id="8F2EwVK" name="measurement_unit.labelp">
<segment>
<source>measurement_unit.labelp</source>
<target>Measurement units</target>
</segment>
</unit>
<unit id="hYrcka2" name="attachment_type.labelp">
<segment>
<source>attachment_type.labelp</source>
<target>Attachment types</target>
</segment>
</unit>
<unit id="p.Sjja3" name="label_profile.labelp">
<segment>
<source>label_profile.labelp</source>
<target>Label profiles</target>
</segment>
</unit>
<unit id="Y_ISV0y" name="part_custom_state.labelp">
<segment>
<source>part_custom_state.labelp</source>
<target>Custom part states</target>
</segment>
</unit>
<unit id="aXr7mN." name="group.labelp">
<segment>
<source>group.labelp</source>
<target>Groups</target>
</segment>
</unit>
<unit id="O10voez" name="settings.synonyms.type_synonym.type">
<segment>
<source>settings.synonyms.type_synonym.type</source>
<target>Type</target>
</segment>
</unit>
<unit id="1BDQVEp" name="settings.synonyms.type_synonym.language">
<segment>
<source>settings.synonyms.type_synonym.language</source>
<target>Language</target>
</segment>
</unit>
<unit id="2.g2ewQ" name="settings.synonyms.type_synonym.translation_singular">
<segment>
<source>settings.synonyms.type_synonym.translation_singular</source>
<target>Translation Singular</target>
</segment>
</unit>
<unit id="Up9ZhvR" name="settings.synonyms.type_synonym.translation_plural">
<segment>
<source>settings.synonyms.type_synonym.translation_plural</source>
<target>Translation Plural</target>
</segment>
</unit>
<unit id="BHoS230" name="settings.synonyms.type_synonym.add_entry">
<segment>
<source>settings.synonyms.type_synonym.add_entry</source>
<target>Add entry</target>
</segment>
</unit>
<unit id="wvtOEBn" name="settings.synonyms.type_synonym.remove_entry">
<segment>
<source>settings.synonyms.type_synonym.remove_entry</source>
<target>Remove entry</target>
</segment>
</unit>
<unit id="mLu.2F2" name="settings.synonyms">
<segment>
<source>settings.synonyms</source>
<target>Synonyms</target>
</segment>
</unit>
<unit id="SHgc9i." name="settings.synonyms.help">
<segment>
<source>settings.synonyms.help</source>
<target>The synonyms systems allow overriding how Part-DB call certain things. This can be useful, especially if Part-DB is used in a different context than electronics.
Please note that this system is currently experimental, and the synonyms defined here might not show up at all places.</target>
</segment>
</unit>
<unit id="piB78W5" name="settings.synonyms.type_synonyms">
<segment>
<source>settings.synonyms.type_synonyms</source>
<target>Type synonyms</target>
</segment>
</unit>
<unit id="J8T2HuD" name="settings.synonyms.type_synonyms.help">
<segment>
<source>settings.synonyms.type_synonyms.help</source>
<target>Type synonyms allow you to replace the labels of built-in data types. For example, you can rename "Footprint" to something else.</target>
</segment>
</unit>
<unit id="GSqBiVV" name="{{part}}">
<segment>
<source>{{part}}</source>
<target>Parts</target>
</segment>
</unit>
<unit id="wjcsjzT" name="log.element_edited.changed_fields.part_ipn_prefix">
<segment>
<source>log.element_edited.changed_fields.part_ipn_prefix</source>
<target>IPN prefix</target>
</segment>
</unit>
<unit id="R4hoCqe" name="part.labelp">
<segment>
<source>part.labelp</source>
<target>Parts</target>
</segment>
</unit>
</file> </file>
</xliff> </xliff>

View file

@ -347,13 +347,13 @@
<target>Due to technical limitations, it is not possible to select dates after the 2038-01-19 on 32-bit systems!</target> <target>Due to technical limitations, it is not possible to select dates after the 2038-01-19 on 32-bit systems!</target>
</segment> </segment>
</unit> </unit>
<unit id="89nojXY" name="validator.fileSize.invalidFormat"> <unit id="iM9yb_p" name="validator.fileSize.invalidFormat">
<segment state="translated"> <segment state="translated">
<source>validator.fileSize.invalidFormat</source> <source>validator.fileSize.invalidFormat</source>
<target>Invalid file size format. Use an integer number plus K, M, G as suffix for Kilo, Mega or Gigabytes.</target> <target>Invalid file size format. Use an integer number plus K, M, G as suffix for Kilo, Mega or Gigabytes.</target>
</segment> </segment>
</unit> </unit>
<unit id="iXcU7ce" name="validator.invalid_range"> <unit id="ZFxQ0BZ" name="validator.invalid_range">
<segment state="translated"> <segment state="translated">
<source>validator.invalid_range</source> <source>validator.invalid_range</source>
<target>The given range is not valid!</target> <target>The given range is not valid!</target>
@ -365,5 +365,11 @@
<target>Invalid code. Check that your authenticator app is set up correctly and that both the server and authentication device has the time set correctly.</target> <target>Invalid code. Check that your authenticator app is set up correctly and that both the server and authentication device has the time set correctly.</target>
</segment> </segment>
</unit> </unit>
<unit id="I330cr5" name="settings.synonyms.type_synonyms.collection_type.duplicate">
<segment>
<source>settings.synonyms.type_synonyms.collection_type.duplicate</source>
<target>There is already a translation defined for this type and language!</target>
</segment>
</unit>
</file> </file>
</xliff> </xliff>