diff --git a/config/parameters.yaml b/config/parameters.yaml index 118e367c..3931729d 100644 --- a/config/parameters.yaml +++ b/config/parameters.yaml @@ -16,20 +16,6 @@ parameters: partdb.create_assembly_use_ipn_placeholder_in_name: '%env(bool:CREATE_ASSEMBLY_USE_IPN_PLACEHOLDER_IN_NAME)%' # Use an %%ipn%% placeholder in the name of an assembly. Placeholder is replaced with the ipn input while saving. - partdb.data_sources.synonyms: # Define your own synonyms for the given data sources - # Possible datasources: category, storagelocation, footprint, manufacturer, supplier, project, assembly - # Possible locales like the ones in 'partdb.locale_menu': en, de, it, fr, ru, ja, cs, da, zh, pl - #category: - #de: 'Bauteil Kategorien' - #en: 'Part categories' - #project: - #de: 'Geräte' - #en: 'Devices' - #assembly: - #de: 'Zusammengestellte Baugruppe' - #en: 'Combined assembly' - - ###################################################################################################################### # Users and Privacy ###################################################################################################################### diff --git a/config/services.yaml b/config/services.yaml index e354ca84..b1af60b0 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -191,25 +191,6 @@ services: $fontDirectory: '%kernel.project_dir%/var/dompdf/fonts/' $tmpDirectory: '%kernel.project_dir%/var/dompdf/tmp/' - #################################################################################################################### - # Trees - #################################################################################################################### - App\Services\Trees\TreeViewGenerator: - arguments: - $dataSourceSynonyms: '%partdb.data_sources.synonyms%' - App\Services\Trees\ToolsTreeBuilder: - arguments: - $dataSourceSynonyms: '%partdb.data_sources.synonyms%' - - #################################################################################################################### - # Twig Extensions - #################################################################################################################### - - App\Twig\DataSourceNameExtension: - arguments: - $dataSourceSynonyms: '%partdb.data_sources.synonyms%' - tags: [ 'twig.extension' ] - #################################################################################################################### # Part info provider system #################################################################################################################### diff --git a/src/Services/Trees/ToolsTreeBuilder.php b/src/Services/Trees/ToolsTreeBuilder.php index 78b99696..f16431b3 100644 --- a/src/Services/Trees/ToolsTreeBuilder.php +++ b/src/Services/Trees/ToolsTreeBuilder.php @@ -50,15 +50,8 @@ use Symfony\Contracts\Translation\TranslatorInterface; */ class ToolsTreeBuilder { - public function __construct( - protected TranslatorInterface $translator, - protected UrlGeneratorInterface $urlGenerator, - protected TagAwareCacheInterface $cache, - protected UserCacheKeyGenerator $keyGenerator, - protected Security $security, - protected ?array $dataSourceSynonyms = [], - ) { - $this->dataSourceSynonyms = $dataSourceSynonyms ?? []; + public function __construct(protected TranslatorInterface $translator, protected UrlGeneratorInterface $urlGenerator, protected TagAwareCacheInterface $cache, protected UserCacheKeyGenerator $keyGenerator, protected Security $security) + { } /** @@ -173,43 +166,43 @@ class ToolsTreeBuilder } if ($this->security->isGranted('read', new Category())) { $nodes[] = (new TreeViewNode( - $this->getTranslatedDataSourceOrSynonym('category', 'tree.tools.edit.categories', $this->translator->getLocale()), + $this->translator->trans('tree.tools.edit.categories'), $this->urlGenerator->generate('category_new') ))->setIcon('fa-fw fa-treeview fa-solid fa-tags'); } if ($this->security->isGranted('read', new Project())) { $nodes[] = (new TreeViewNode( - $this->getTranslatedDataSourceOrSynonym('project', 'tree.tools.edit.projects', $this->translator->getLocale()), + $this->translator->trans('tree.tools.edit.projects'), $this->urlGenerator->generate('project_new') ))->setIcon('fa-fw fa-treeview fa-solid fa-archive'); } if ($this->security->isGranted('read', new Assembly())) { $nodes[] = (new TreeViewNode( - $this->getTranslatedDataSourceOrSynonym('assembly', 'tree.tools.edit.assemblies', $this->translator->getLocale()), + $this->translator->trans('tree.tools.edit.assemblies'), $this->urlGenerator->generate('assembly_new') ))->setIcon('fa-fw fa-treeview fa-solid fa-list'); } if ($this->security->isGranted('read', new Supplier())) { $nodes[] = (new TreeViewNode( - $this->getTranslatedDataSourceOrSynonym('supplier', 'tree.tools.edit.suppliers', $this->translator->getLocale()), + $this->translator->trans('tree.tools.edit.suppliers'), $this->urlGenerator->generate('supplier_new') ))->setIcon('fa-fw fa-treeview fa-solid fa-truck'); } if ($this->security->isGranted('read', new Manufacturer())) { $nodes[] = (new TreeViewNode( - $this->getTranslatedDataSourceOrSynonym('manufacturer', 'tree.tools.edit.manufacturer', $this->translator->getLocale()), + $this->translator->trans('tree.tools.edit.manufacturer'), $this->urlGenerator->generate('manufacturer_new') ))->setIcon('fa-fw fa-treeview fa-solid fa-industry'); } if ($this->security->isGranted('read', new StorageLocation())) { $nodes[] = (new TreeViewNode( - $this->getTranslatedDataSourceOrSynonym('storagelocation', 'tree.tools.edit.storelocation', $this->translator->getLocale()), + $this->translator->trans('tree.tools.edit.storelocation'), $this->urlGenerator->generate('store_location_new') ))->setIcon('fa-fw fa-treeview fa-solid fa-cube'); } if ($this->security->isGranted('read', new Footprint())) { $nodes[] = (new TreeViewNode( - $this->getTranslatedDataSourceOrSynonym('footprint', 'tree.tools.edit.footprint', $this->translator->getLocale()), + $this->translator->trans('tree.tools.edit.footprint'), $this->urlGenerator->generate('footprint_new') ))->setIcon('fa-fw fa-treeview fa-solid fa-microchip'); } @@ -317,22 +310,4 @@ class ToolsTreeBuilder return $nodes; } - - protected function getTranslatedDataSourceOrSynonym(string $dataSource, string $translationKey, string $locale): string - { - $currentTranslation = $this->translator->trans($translationKey); - - // Call alternatives from DataSourcesynonyms (if available) - if (!empty($this->dataSourceSynonyms[$dataSource][$locale])) { - $alternativeTranslation = $this->dataSourceSynonyms[$dataSource][$locale]; - - // Use alternative translation when it deviates from the standard translation - if ($alternativeTranslation !== $currentTranslation) { - return $alternativeTranslation; - } - } - - // Otherwise return the standard translation - return $currentTranslation; - } } diff --git a/src/Services/Trees/TreeViewGenerator.php b/src/Services/Trees/TreeViewGenerator.php index d5358bfa..3a097902 100644 --- a/src/Services/Trees/TreeViewGenerator.php +++ b/src/Services/Trees/TreeViewGenerator.php @@ -68,11 +68,9 @@ class TreeViewGenerator protected TranslatorInterface $translator, private readonly UrlGeneratorInterface $router, private readonly SidebarSettings $sidebarSettings, - protected ?array $dataSourceSynonyms = [], ) { $this->rootNodeEnabled = $this->sidebarSettings->rootNodeEnabled; $this->rootNodeExpandedByDefault = $this->sidebarSettings->rootNodeExpanded; - $this->dataSourceSynonyms = $dataSourceSynonyms ?? []; } /** @@ -228,16 +226,14 @@ class TreeViewGenerator protected function entityClassToRootNodeString(string $class): string { - $locale = $this->translator->getLocale(); - return match ($class) { - Category::class => $this->getTranslatedOrSynonym('category', $locale), - StorageLocation::class => $this->getTranslatedOrSynonym('storelocation', $locale), - Footprint::class => $this->getTranslatedOrSynonym('footprint', $locale), - Manufacturer::class => $this->getTranslatedOrSynonym('manufacturer', $locale), - Supplier::class => $this->getTranslatedOrSynonym('supplier', $locale), - Project::class => $this->getTranslatedOrSynonym('project', $locale), - Assembly::class => $this->getTranslatedOrSynonym('assembly', $locale), + 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'), + Assembly::class => $this->translator->trans('assembly.labelp'), default => $this->translator->trans('tree.root_node.text'), }; } @@ -294,22 +290,4 @@ class TreeViewGenerator return $repo->getGenericNodeTree($parent); //@phpstan-ignore-line }); } - - protected function getTranslatedOrSynonym(string $key, string $locale): string - { - $currentTranslation = $this->translator->trans($key . '.labelp'); - - // Call alternatives from DataSourcesynonyms (if available) - if (!empty($this->dataSourceSynonyms[$key][$locale])) { - $alternativeTranslation = $this->dataSourceSynonyms[$key][$locale]; - - // Use alternative translation when it deviates from the standard translation - if ($alternativeTranslation !== $currentTranslation) { - return $alternativeTranslation; - } - } - - // Otherwise return the standard translation - return $currentTranslation; - } } diff --git a/src/Twig/DataSourceNameExtension.php b/src/Twig/DataSourceNameExtension.php deleted file mode 100644 index 1c02243f..00000000 --- a/src/Twig/DataSourceNameExtension.php +++ /dev/null @@ -1,42 +0,0 @@ -translator = $translator; - $this->dataSourceSynonyms = $dataSourceSynonyms ?? []; - } - - public function getFunctions(): array - { - return [ - new TwigFunction('get_data_source_name', [$this, 'getDataSourceName']), - ]; - } - - /** - * Based on the locale and data source names, gives the right synonym value back or the default translator value. - */ - public function getDataSourceName(string $dataSourceName, string $defaultKey): string - { - $locale = $this->translator->getLocale(); - - // Use alternative dataSource synonym (if available) - if (isset($this->dataSourceSynonyms[$dataSourceName][$locale])) { - return $this->dataSourceSynonyms[$dataSourceName][$locale]; - } - - // Otherwise return the standard translation - return $this->translator->trans($defaultKey); - } -} \ No newline at end of file diff --git a/templates/admin/assembly_admin.html.twig b/templates/admin/assembly_admin.html.twig index 2e68a3da..b6bf6d09 100644 --- a/templates/admin/assembly_admin.html.twig +++ b/templates/admin/assembly_admin.html.twig @@ -3,9 +3,7 @@ {# @var entity App\Entity\AssemblySystem\Assembly #} {% block card_title %} - {% set dataSourceName = get_data_source_name('assembly', 'assembly.caption') %} - {% set translatedSource = 'assembly.caption'|trans %} - {% if dataSourceName != translatedSource %}{{ 'datasource.synonym'|trans({'%name%': translatedSource, '%synonym%': dataSourceName}) }}{% else %}{{ translatedSource }}{% endif %} + {% trans %}assembly.caption{% endtrans %} {% endblock %} {% block edit_title %} diff --git a/templates/admin/category_admin.html.twig b/templates/admin/category_admin.html.twig index f1fe7663..5811640b 100644 --- a/templates/admin/category_admin.html.twig +++ b/templates/admin/category_admin.html.twig @@ -1,9 +1,7 @@ {% extends "admin/base_admin.html.twig" %} {% block card_title %} - {% set dataSourceName = get_data_source_name('category', 'category.labelp') %} - {% set translatedSource = 'category.labelp'|trans %} - {% if dataSourceName != translatedSource %}{{ 'datasource.synonym'|trans({'%name%': translatedSource, '%synonym%': dataSourceName}) }}{% else %}{{ translatedSource }}{% endif %} + {% trans %}category.labelp{% endtrans %} {% endblock %} {% block additional_pills %} diff --git a/templates/admin/footprint_admin.html.twig b/templates/admin/footprint_admin.html.twig index a6acbe84..a2c3e4af 100644 --- a/templates/admin/footprint_admin.html.twig +++ b/templates/admin/footprint_admin.html.twig @@ -1,9 +1,7 @@ {% extends "admin/base_admin.html.twig" %} {% block card_title %} - {% set dataSourceName = get_data_source_name('footprint', 'footprint.labelp') %} - {% set translatedSource = 'footprint.labelp'|trans %} - {% if dataSourceName != translatedSource %}{{ 'datasource.synonym'|trans({'%name%': translatedSource, '%synonym%': dataSourceName}) }}{% else %}{{ translatedSource }}{% endif %} + {% trans %}footprint.labelp{% endtrans %} {% endblock %} {% block master_picture_block %} diff --git a/templates/admin/manufacturer_admin.html.twig b/templates/admin/manufacturer_admin.html.twig index 3ce9a124..5db892c0 100644 --- a/templates/admin/manufacturer_admin.html.twig +++ b/templates/admin/manufacturer_admin.html.twig @@ -1,9 +1,7 @@ {% extends "admin/base_company_admin.html.twig" %} {% block card_title %} - {% set dataSourceName = get_data_source_name('manufacturer', 'manufacturer.caption') %} - {% set translatedSource = 'manufacturer.caption'|trans %} - {% if dataSourceName != translatedSource %}{{ 'datasource.synonym'|trans({'%name%': translatedSource, '%synonym%': dataSourceName}) }}{% else %}{{ translatedSource }}{% endif %} + {% trans %}manufacturer.caption{% endtrans %} {% endblock %} {% block edit_title %} diff --git a/templates/admin/project_admin.html.twig b/templates/admin/project_admin.html.twig index 401be7cf..dcf8c64c 100644 --- a/templates/admin/project_admin.html.twig +++ b/templates/admin/project_admin.html.twig @@ -3,9 +3,7 @@ {# @var entity App\Entity\ProjectSystem\Project #} {% block card_title %} - {% set dataSourceName = get_data_source_name('project', 'project.caption') %} - {% set translatedSource = 'project.caption'|trans %} - {% if dataSourceName != translatedSource %}{{ 'datasource.synonym'|trans({'%name%': translatedSource, '%synonym%': dataSourceName}) }}{% else %}{{ translatedSource }}{% endif %} + {% trans %}project.caption{% endtrans %} {% endblock %} {% block edit_title %} diff --git a/templates/admin/storelocation_admin.html.twig b/templates/admin/storelocation_admin.html.twig index 1e60eeea..c93339dc 100644 --- a/templates/admin/storelocation_admin.html.twig +++ b/templates/admin/storelocation_admin.html.twig @@ -2,9 +2,7 @@ {% import "label_system/dropdown_macro.html.twig" as dropdown %} {% block card_title %} - {% set dataSourceName = get_data_source_name('storagelocation', 'storelocation.labelp') %} - {% set translatedSource = 'storelocation.labelp'|trans %} - {% if dataSourceName != translatedSource %}{{ 'datasource.synonym'|trans({'%name%': translatedSource, '%synonym%': dataSourceName}) }}{% else %}{{ translatedSource }}{% endif %} + {% trans %}storelocation.labelp{% endtrans %} {% endblock %} {% block additional_controls %} diff --git a/templates/admin/supplier_admin.html.twig b/templates/admin/supplier_admin.html.twig index b5cf7b23..ce38a5ca 100644 --- a/templates/admin/supplier_admin.html.twig +++ b/templates/admin/supplier_admin.html.twig @@ -1,9 +1,7 @@ {% extends "admin/base_company_admin.html.twig" %} {% block card_title %} - {% set dataSourceName = get_data_source_name('supplier', 'supplier.caption') %} - {% set translatedSource = 'supplier.caption'|trans %} - {% if dataSourceName != translatedSource %}{{ 'datasource.synonym'|trans({'%name%': translatedSource, '%synonym%': dataSourceName}) }}{% else %}{{ translatedSource }}{% endif %} + {% trans %}supplier.caption{% endtrans %} {% endblock %} {% block additional_panes %} diff --git a/templates/components/tree_macros.html.twig b/templates/components/tree_macros.html.twig index 210a0063..2e55147a 100644 --- a/templates/components/tree_macros.html.twig +++ b/templates/components/tree_macros.html.twig @@ -1,16 +1,14 @@ {% macro sidebar_dropdown() %} - {% set currentLocale = app.request.locale %} - {# Format is [mode, route, label, show_condition] #} {% set data_sources = [ - ['categories', path('tree_category_root'), 'category.labelp', is_granted('@categories.read') and is_granted('@parts.read'), 'category'], - ['locations', path('tree_location_root'), 'storelocation.labelp', is_granted('@storelocations.read') and is_granted('@parts.read'), 'storagelocation'], - ['footprints', path('tree_footprint_root'), 'footprint.labelp', is_granted('@footprints.read') and is_granted('@parts.read'), 'footprint'], - ['manufacturers', path('tree_manufacturer_root'), 'manufacturer.labelp', 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'), 'supplier'], - ['projects', path('tree_device_root'), 'project.labelp', is_granted('@projects.read'), 'project'], - ['assembly', path('tree_assembly_root'), 'assembly.labelp', is_granted('@assemblies.read'), 'assembly'], - ['tools', path('tree_tools'), 'tools.label', true, 'tool'], + ['categories', path('tree_category_root'), 'category.labelp', 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')], + ['footprints', path('tree_footprint_root'), 'footprint.labelp', 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')], + ['suppliers', path('tree_supplier_root'), 'supplier.labelp', is_granted('@suppliers.read') and is_granted('@parts.read')], + ['projects', path('tree_device_root'), 'project.labelp', is_granted('@projects.read')], + ['assembly', path('tree_assembly_root'), 'assembly.labelp', is_granted('@assemblies.read')], + ['tools', path('tree_tools'), 'tools.label', true], ] %} @@ -21,9 +19,9 @@ {% for source in data_sources %} {% if source[3] %} {# show_condition #} -
  • + >{{ source[2] | trans }} {% endif %} {% endfor %} {% endmacro %} @@ -64,4 +62,4 @@
    -{% endmacro %} +{% endmacro %} \ No newline at end of file diff --git a/templates/form/permission_layout.html.twig b/templates/form/permission_layout.html.twig index dcceae33..45525d02 100644 --- a/templates/form/permission_layout.html.twig +++ b/templates/form/permission_layout.html.twig @@ -6,36 +6,12 @@
    {% else %} - def{{ form.vars.label | trans }} + {{ form.vars.label | trans }} {% endif %} @@ -134,4 +110,4 @@ {% endfor %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/translations/messages.cs.xlf b/translations/messages.cs.xlf index ad2d4bb7..2f1b63a1 100644 --- a/translations/messages.cs.xlf +++ b/translations/messages.cs.xlf @@ -14877,11 +14877,5 @@ Vezměte prosím na vědomí, že se nemůžete vydávat za uživatele se zakáz Popis - - - datasource.synonym - %name% (Váš synonymum: %synonym%) - - diff --git a/translations/messages.da.xlf b/translations/messages.da.xlf index c07d229d..90614740 100644 --- a/translations/messages.da.xlf +++ b/translations/messages.da.xlf @@ -13522,11 +13522,5 @@ Bemærk venligst, at du ikke kan kopiere fra deaktiveret bruger. Hvis du prøver Beskrivelse - - - datasource.synonym - %name% (Dit synonym: %synonym%) - - diff --git a/translations/messages.de.xlf b/translations/messages.de.xlf index 7f4f5d33..55045836 100644 --- a/translations/messages.de.xlf +++ b/translations/messages.de.xlf @@ -15551,11 +15551,5 @@ Bitte beachten Sie, dass Sie sich nicht als deaktivierter Benutzer ausgeben kön Beschreibung - - - datasource.synonym - %name% (Ihr Synonym: %synonym%) - - diff --git a/translations/messages.el.xlf b/translations/messages.el.xlf index b9be2574..e6cf3986 100644 --- a/translations/messages.el.xlf +++ b/translations/messages.el.xlf @@ -2530,11 +2530,5 @@ Περιγραφή - - - datasource.synonym - %name% (Το συνώνυμό σας: %synonym%) - - diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index 7a78c01a..6c83146c 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -15552,11 +15552,5 @@ Please note, that you can not impersonate a disabled user. If you try you will g Description - - - datasource.synonym - %name% (Your synonym: %synonym%) - - diff --git a/translations/messages.es.xlf b/translations/messages.es.xlf index 8539d631..8101f36e 100644 --- a/translations/messages.es.xlf +++ b/translations/messages.es.xlf @@ -13694,11 +13694,5 @@ Por favor ten en cuenta que no puedes personificar a un usuario deshabilitado. S Descripción - - - datasource.synonym - %name% (Tu sinónimo: %synonym%) - - diff --git a/translations/messages.fr.xlf b/translations/messages.fr.xlf index ae9e9aff..4da61a17 100644 --- a/translations/messages.fr.xlf +++ b/translations/messages.fr.xlf @@ -10104,11 +10104,5 @@ exemple de ville Description - - - datasource.synonym - %name% (Votre synonyme : %synonym%) - - diff --git a/translations/messages.it.xlf b/translations/messages.it.xlf index e7b012ed..19e76ee0 100644 --- a/translations/messages.it.xlf +++ b/translations/messages.it.xlf @@ -13696,11 +13696,5 @@ Notare che non è possibile impersonare un utente disattivato. Quando si prova a Descrizione - - - datasource.synonym - %name% (Il tuo sinonimo: %synonym%) - - diff --git a/translations/messages.ja.xlf b/translations/messages.ja.xlf index 4d92f055..e2e50d77 100644 --- a/translations/messages.ja.xlf +++ b/translations/messages.ja.xlf @@ -9817,11 +9817,5 @@ Exampletown 説明 - - - datasource.synonym - %name% (あなたの同義語: %synonym%) - - diff --git a/translations/messages.nl.xlf b/translations/messages.nl.xlf index 63a42c6c..a892fc58 100644 --- a/translations/messages.nl.xlf +++ b/translations/messages.nl.xlf @@ -1755,11 +1755,5 @@ Beschrijving - - - datasource.synonym - %name% (Uw synoniem: %synonym%) - - diff --git a/translations/messages.pl.xlf b/translations/messages.pl.xlf index 2c77cfea..9f415c56 100644 --- a/translations/messages.pl.xlf +++ b/translations/messages.pl.xlf @@ -13549,11 +13549,5 @@ Należy pamiętać, że nie możesz udawać nieaktywnych użytkowników. Jeśli Opis - - - datasource.synonym - %name% (Twój synonim: %synonym%) - - diff --git a/translations/messages.ru.xlf b/translations/messages.ru.xlf index 4345c6c9..3391bf50 100644 --- a/translations/messages.ru.xlf +++ b/translations/messages.ru.xlf @@ -13649,11 +13649,5 @@ Описание - - - datasource.synonym - %name% (Ваш синоним: %synonym%) - - diff --git a/translations/messages.zh.xlf b/translations/messages.zh.xlf index 34da9e78..bfbf1db4 100644 --- a/translations/messages.zh.xlf +++ b/translations/messages.zh.xlf @@ -13534,11 +13534,5 @@ Element 3 描述 - - - datasource.synonym - %name% (您的同义词: %synonym%) - -