Skip to content

Commit

Permalink
Added translations for info provider settings fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtronics committed May 9, 2024
1 parent 08ae313 commit 4876068
Show file tree
Hide file tree
Showing 10 changed files with 1,706 additions and 1,514 deletions.
49 changes: 26 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/Settings/InfoProviderSystem/Element14Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
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";
}
6 changes: 3 additions & 3 deletions src/Settings/InfoProviderSystem/InfoProviderSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class InfoProviderSettings
{
use SettingsTrait;

#[EmbeddedSettings]
public ?LCSCSettings $lcsc = null;

#[EmbeddedSettings]
public ?MouserSettings $mouser = null;

Expand All @@ -43,4 +40,7 @@ class InfoProviderSettings

#[EmbeddedSettings]
public ?Element14Settings $element14 = null;

#[EmbeddedSettings]
public ?LCSCSettings $lcsc = null;
}
7 changes: 4 additions & 3 deletions src/Settings/InfoProviderSystem/LCSCSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@
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';
}
17 changes: 16 additions & 1 deletion src/Settings/InfoProviderSystem/MouserSearchOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,25 @@

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);
}
}
10 changes: 6 additions & 4 deletions src/Settings/InfoProviderSystem/MouserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,26 @@
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;

Expand Down
16 changes: 9 additions & 7 deletions src/Settings/InfoProviderSystem/TMESettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,34 @@
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;
}
Loading

0 comments on commit 4876068

Please sign in to comment.