Removed now unnecessary services

This commit is contained in:
Jan Böhmer 2025-11-11 23:08:40 +01:00
parent f61ecc9738
commit a0a12b8692
2 changed files with 0 additions and 138 deletions

View file

@ -1,71 +0,0 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2023 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\Misc;
use App\Settings\SystemSettings\DataSourceSynonymsSettings;
use Symfony\Contracts\Translation\TranslatorInterface;
readonly class DataSourceSynonymResolver
{
public function __construct(
private TranslatorInterface $translator,
private DataSourceSynonymsSettings $synonymsSettings,
) {
}
public function displayNamePlural(string $dataSource, string $defaultKey, ?string $locale = null): string
{
$locale ??= $this->translator->getLocale();
$syn = $this->synonyms($dataSource, $locale);
if ($syn['plural'] !== '') {
return $syn['plural'];
}
return $this->translator->trans($defaultKey, locale: $locale);
}
public function displayNameSingular(string $dataSource, string $defaultKey, ?string $locale = null): string
{
$locale ??= $this->translator->getLocale();
$syn = $this->synonyms($dataSource, $locale);
if ($syn['singular'] !== '') {
return $syn['singular'];
}
return $this->translator->trans($defaultKey, locale: $locale);
}
private function synonyms(string $dataSource, string $locale): array
{
$all = [];
$row = $all[$dataSource][$locale] ?? ['singular' => '', 'plural' => ''];
return [
'singular' => (string)($row['singular'] ?? ''),
'plural' => (string)($row['plural'] ?? ''),
];
}
}

View file

@ -1,67 +0,0 @@
<?php
namespace App\Twig;
use App\Services\Misc\DataSourceSynonymResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class DataSourceNameExtension extends AbstractExtension
{
public function __construct(
private readonly TranslatorInterface $translator,
private readonly DataSourceSynonymResolver $resolver,
) {
}
public function getFunctions(): array
{
return [
new TwigFunction('get_data_source_name_singular', [$this, 'getDataSourceNameSingular']),
new TwigFunction('get_data_source_name_plural', [$this, 'getDataSourceNamePlural']),
new TwigFunction('data_source_name_with_hint', [$this, 'getDataSourceNameWithHint']),
];
}
/**
* Returns the singular synonym for the given data source in current locale,
* or the translated fallback key if no synonym provided.
*/
public function getDataSourceNameSingular(string $dataSourceName, string $defaultKeySingular): string
{
return $this->resolver->displayNameSingular($dataSourceName, $defaultKeySingular, $this->translator->getLocale());
}
/**
* Returns the plural synonym for the given data source in current locale,
* or the translated fallback key if no synonym provided.
*/
public function getDataSourceNamePlural(string $dataSourceName, string $defaultKeyPlural): string
{
return $this->resolver->displayNamePlural($dataSourceName, $defaultKeyPlural, $this->translator->getLocale());
}
/**
* Like data_source_name, only with a note if a synonym was set (uses translation key 'datasource.synonym').
*/
public function getDataSourceNameWithHint(string $dataSourceName, string $defaultKey, string $type = 'singular'): string
{
$type = $type === 'singular' ? 'singular' : 'plural';
$resolved = $type === 'singular'
? $this->resolver->displayNameSingular($dataSourceName, $defaultKey, $this->translator->getLocale())
: $this->resolver->displayNamePlural($dataSourceName, $defaultKey, $this->translator->getLocale());
$fallback = $this->translator->trans($defaultKey);
if ($resolved !== $fallback) {
return $this->translator->trans('datasource.synonym', [
'%name%' => $fallback,
'%synonym%' => $resolved,
]);
}
return $fallback;
}
}