Added translations for info provider settings fields

This commit is contained in:
Jan Böhmer 2024-05-10 00:55:14 +02:00
parent 08ae313dfe
commit 4876068cce
10 changed files with 1706 additions and 1514 deletions

View file

@ -26,15 +26,16 @@ namespace App\Settings\InfoProviderSystem;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
use Symfony\Component\Translation\TranslatableMessage as TM;
#[Settings]
#[Settings(label: new TM("settings.ips.element14"))]
class Element14Settings
{
use SettingsTrait;
#[SettingsParameter(envVar: "PROVIDER_ELEMENT14_KEY")]
#[SettingsParameter(label: new TM("settings.ips.element14.apiKey"), description: new TM("settings.ips.element14.apiKey.help"), formOptions: ["help_html" => true], envVar: "PROVIDER_ELEMENT14_KEY")]
public ?string $apiKey = null;
#[SettingsParameter(envVar: "PROVIDER_ELEMENT14_STORE_ID")]
#[SettingsParameter(label: new TM("settings.ips.element14.storeId"), description: new TM("settings.ips.element14.storeId.help"), formOptions: ["help_html" => true], envVar: "PROVIDER_ELEMENT14_STORE_ID")]
public string $storeId = "de.farnell.com";
}

View file

@ -32,9 +32,6 @@ class InfoProviderSettings
{
use SettingsTrait;
#[EmbeddedSettings]
public ?LCSCSettings $lcsc = null;
#[EmbeddedSettings]
public ?MouserSettings $mouser = null;
@ -43,4 +40,7 @@ class InfoProviderSettings
#[EmbeddedSettings]
public ?Element14Settings $element14 = null;
#[EmbeddedSettings]
public ?LCSCSettings $lcsc = null;
}

View file

@ -28,16 +28,17 @@ use Jbtronics\SettingsBundle\Settings\SettingsParameter;
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Translation\TranslatableMessage as TM;
#[Settings]
#[Settings(label: new TM("settings.ips.lcsc"), description: new TM("settings.ips.lcsc.help"))]
class LCSCSettings
{
use SettingsTrait;
#[SettingsParameter(label: "Enable LCSC provider", envVar: "bool:PROVIDER_LCSC_ENABLED")]
#[SettingsParameter(label: new TM("settings.ips.lcsc.enabled"), envVar: "bool:PROVIDER_LCSC_ENABLED")]
public bool $enabled = false;
#[SettingsParameter(label: "LCSC Currency", description: "The currency to retrieve prices from LCSC", formType: CurrencyType::class, envVar: "string:PROVIDER_LCSC_CURRENCY")]
#[SettingsParameter(label: new TM("settings.ips.lcsc.currency"), formType: CurrencyType::class, envVar: "string:PROVIDER_LCSC_CURRENCY")]
#[Assert\Currency()]
public string $currency = 'EUR';
}

View file

@ -23,10 +23,25 @@ declare(strict_types=1);
namespace App\Settings\InfoProviderSystem;
enum MouserSearchOptions: string
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
enum MouserSearchOptions: string implements TranslatableInterface
{
case NONE = "None";
case ROHS = "Rohs";
case IN_STOCK = "InStock";
case ROHS_AND_INSTOCK = "RohsAndInStock";
public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
$key = match($this) {
self::NONE => "settings.ips.mouser.searchOptions.none",
self::ROHS => "settings.ips.mouser.searchOptions.rohs",
self::IN_STOCK => "settings.ips.mouser.searchOptions.inStock",
self::ROHS_AND_INSTOCK => "settings.ips.mouser.searchOptions.rohsAndInStock",
};
return $translator->trans($key, locale: $locale);
}
}

View file

@ -26,24 +26,26 @@ namespace App\Settings\InfoProviderSystem;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Translation\TranslatableMessage as TM;
#[Settings]
#[Settings(label: new TM("settings.ips.mouser"))]
class MouserSettings
{
#[SettingsParameter(envVar: "PROVIDER_MOUSER_KEY")]
#[SettingsParameter(label: new TM("settings.ips.mouser.apiKey"), description: new TM("settings.ips.mouser.apiKey.help"), formOptions: ["help_html" => true], envVar: "PROVIDER_MOUSER_KEY")]
public ?string $apiKey = null;
/** @var int The number of results to get from Mouser while searching (please note that this value is max 50) */
#[SettingsParameter(envVar: "int:PROVIDER_MOUSER_SEARCH_LIMIT")]
#[SettingsParameter(label: new TM("settings.ips.mouser.searchLimit"), description: new TM("settings.ips.mouser.searchLimit.help"), envVar: "int:PROVIDER_MOUSER_SEARCH_LIMIT")]
#[Assert\Range(min: 1, max: 50)]
public int $searchLimit = 50;
/** @var MouserSearchOptions Filter search results by RoHS compliance and stock availability */
#[SettingsParameter(envVar: "PROVIDER_MOUSER_SEARCH_OPTION", envVarMapper: [self::class, "mapSearchOptionEnvVar"])]
#[SettingsParameter(label: new TM("settings.ips.mouser.searchOptions"), description: new TM("settings.ips.mouser.searchOptions.help"), envVar: "PROVIDER_MOUSER_SEARCH_OPTION", envVarMapper: [self::class, "mapSearchOptionEnvVar"])]
public MouserSearchOptions $searchOption = MouserSearchOptions::NONE;
/** @var bool It is recommended to leave this set to 'true'. The option is not really documented by Mouser:
* Used when searching for keywords in the language specified when you signed up for Search API. */
//TODO: Put this into some expert mode only
#[SettingsParameter(envVar: "bool:PROVIDER_MOUSER_SEARCH_WITH_SIGNUP_LANGUAGE")]
public bool $searchWithSignUpLanguage = true;

View file

@ -30,32 +30,34 @@ use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Translation\TranslatableMessage as TM;
#[Settings(label: "TME settings", description: "Settings for the TME API")]
#[Settings(label: new TM("settings.ips.tme"))]
class TMESettings
{
use SettingsTrait;
private const SUPPORTED_CURRENCIES = ["EUR", "USD", "PLN", "GBP"];
#[SettingsParameter(envVar: "PROVIDER_TME_KEY")]
#[SettingsParameter(label: new TM("settings.ips.tme.token"),
description: new TM("settings.ips.tme.token.help"), formOptions: ["help_html" => true], envVar: "PROVIDER_TME_KEY")]
public ?string $apiToken = null;
#[SettingsParameter(envVar: "PROVIDER_TME_SECRET")]
#[SettingsParameter(label: new TM("settings.ips.tme.secret"), envVar: "PROVIDER_TME_SECRET")]
public ?string $apiSecret = null;
#[SettingsParameter(formType: CurrencyType::class, formOptions: ["preferred_choices" => self::SUPPORTED_CURRENCIES], envVar: "PROVIDER_TME_CURRENCY")]
#[SettingsParameter(label: new TM("settings.ips.tme.currency"), formType: CurrencyType::class, formOptions: ["preferred_choices" => self::SUPPORTED_CURRENCIES], envVar: "PROVIDER_TME_CURRENCY")]
#[Assert\Choice(choices: self::SUPPORTED_CURRENCIES)]
public string $currency = "EUR";
#[SettingsParameter(formType: LanguageType::class, formOptions: ["preferred_choices" => ["en", "de", "fr", "pl"]], envVar: "PROVIDER_TME_LANGUAGE")]
#[SettingsParameter(label: new TM("settings.ips.tme.language"), formType: LanguageType::class, formOptions: ["preferred_choices" => ["en", "de", "fr", "pl"]], envVar: "PROVIDER_TME_LANGUAGE")]
#[Assert\Language]
public string $language = "en";
#[SettingsParameter(envVar: "PROVIDER_TME_COUNTRY", formType: CountryType::class, formOptions: ["preferred_choices" => ["DE", "PL", "GB", "FR"]])]
#[SettingsParameter(label: new TM("settings.ips.tme.country"), envVar: "PROVIDER_TME_COUNTRY", formType: CountryType::class, formOptions: ["preferred_choices" => ["DE", "PL", "GB", "FR"]])]
#[Assert\Country]
public string $country = "DE";
#[SettingsParameter(envVar: "bool:PROVIDER_TME_GET_GROSS_PRICES")]
#[SettingsParameter(label: new TM("settings.ips.tme.grossPrices"), envVar: "bool:PROVIDER_TME_GET_GROSS_PRICES")]
public bool $grossPrices = true;
}