Skip to content

Commit b7f6274

Browse files
committed
Tranlate comments to English to prepare for Pull-Request
1 parent 1cd1640 commit b7f6274

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

src/Services/InfoProviderSystem/Providers/BuerklinProvider.php

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private function getToken(): string
7777
}
7878
}
7979

80-
// Bürklin OAuth2 password grant (ROPC)
80+
// Buerklin OAuth2 password grant (ROPC)
8181
$resp = $this->client->request('POST', 'https://www.buerklin.com/authorizationserver/oauth/token/', [
8282
'headers' => [
8383
'Accept' => 'application/json',
@@ -96,7 +96,7 @@ private function getToken(): string
9696

9797
if (!isset($data['access_token'])) {
9898
throw new \RuntimeException(
99-
'Invalid token response from Bürklin: HTTP ' . $resp->getStatusCode() . ' body=' . $resp->getContent(false)
99+
'Invalid token response from Buerklin: HTTP ' . $resp->getStatusCode() . ' body=' . $resp->getContent(false)
100100
);
101101
}
102102

@@ -114,6 +114,7 @@ private function getToken(): string
114114

115115
return $token;
116116
}
117+
117118
private function getDefaultQueryParams(): array
118119
{
119120
return [
@@ -188,10 +189,10 @@ public function getProviderKey(): string
188189
return 'buerklin';
189190
}
190191

191-
// This provider is always active
192+
// This provider is considered active if settings are present
192193
public function isActive(): bool
193194
{
194-
//The client ID has to be set and a token has to be available (user clicked connect)
195+
// The client credentials and user credentials must be set
195196
return $this->settings->clientId !== ''
196197
&& $this->settings->secret !== ''
197198
&& $this->settings->username !== ''
@@ -227,13 +228,13 @@ private function sanitizeField(?string $field): ?string
227228
}
228229

229230
/**
230-
* Takes a deserialized json object of the product and returns a PartDetailDTO
231+
* Takes a deserialized JSON object of the product and returns a PartDetailDTO
231232
* @param array $product
232233
* @return PartDetailDTO
233234
*/
234235
private function getPartDetail(array $product): PartDetailDTO
235236
{
236-
// If this is a search-result object, it may not contain prices/features/images -> reload full detail.
237+
// If this is a search-result object, it may not contain prices/features/images -> reload full details.
237238
if ((!isset($product['price']) && !isset($product['volumePrices'])) && isset($product['code'])) {
238239
try {
239240
$product = $this->getProduct((string) $product['code']);
@@ -242,25 +243,25 @@ private function getPartDetail(array $product): PartDetailDTO
242243
}
243244
}
244245

245-
// Extract Images from API response
246+
// Extract images from API response
246247
$productImages = $this->getProductImages($product['images'] ?? null);
247248

248-
// Set Preview image
249+
// Set preview image
249250
$preview = $productImages[0]->url ?? null;
250251

251-
// Extract features (parameters) from classifications[0].features of Bürklin JSON response
252+
// Extract features (parameters) from classifications[0].features of Buerklin JSON response
252253
$features = $product['classifications'][0]['features'] ?? [];
253254

254-
// Feature Parameters (from classifications->features)
255-
$featureParams = $this->attributesToParameters($features, ''); //leave group empty for normal parameters
255+
// Feature parameters (from classifications->features)
256+
$featureParams = $this->attributesToParameters($features, ''); // leave group empty for normal parameters
256257

257-
// Compliance-Parameter (from Top-Level fields like RoHS/SVHC/…)
258+
// Compliance parameters (from top-level fields like RoHS/SVHC/…)
258259
$complianceParams = $this->complianceToParameters($product, 'Compliance');
259260

260261
// Merge all parameters
261262
$allParams = array_merge($featureParams, $complianceParams);
262263

263-
// Assign Footprint: "Design" (en) / "Bauform" (de) / "Enclosure" (en) / "Gehäuse" (de)
264+
// Assign footprint: "Design" (en) / "Bauform" (de) / "Enclosure" (en) / "Gehäuse" (de)
264265
$footprint = null;
265266
if (is_array($features)) {
266267
foreach ($features as $feature) {
@@ -337,10 +338,10 @@ private function pricesToVendorInfo(string $sku, string $url, array $prices): ar
337338
$priceDTOs = array_map(function ($price) {
338339
$val = $price['value'] ?? null;
339340
$valStr = is_numeric($val)
340-
? number_format((float) $val, 6, '.', '') // 6 Nachkommastellen, trailing zeros ok
341+
? number_format((float) $val, 6, '.', '') // 6 decimal places, trailing zeros are fine
341342
: (string) $val;
342343

343-
// Optional: weich kürzen (z.B. 75.550000 -> 75.55)
344+
// Optional: softly trim unnecessary trailing zeros (e.g. 75.550000 -> 75.55)
344345
$valStr = rtrim(rtrim($valStr, '0'), '.');
345346

346347
return new PriceDTO(
@@ -376,7 +377,7 @@ private function getProductShortURL(string $product_code): string
376377
* Returns a deduplicated list of product images as FileDTOs.
377378
*
378379
* - takes only real image arrays (with 'url' field)
379-
* - makes relative URLs absolut
380+
* - makes relative URLs absolute
380381
* - deduplicates using URL
381382
* - prefers 'zoom' format, then 'product' format, then all others
382383
*
@@ -456,13 +457,13 @@ private function attributesToParameters(array $features, ?string $group = null):
456457
// Multiple values: join with comma
457458
$value = implode(', ', array_values(array_unique($vals)));
458459

459-
// Unit/Symbol from Buerklin feature
460+
// Unit/symbol from Buerklin feature
460461
$unit = $f['featureUnit']['symbol'] ?? null;
461462
if (!is_string($unit) || trim($unit) === '') {
462463
$unit = null;
463464
}
464465

465-
// ParameterDTO parses value field (handles value+unit)
466+
// ParameterDTO parses value field (handles value + unit)
466467
$out[] = ParameterDTO::parseValueField(
467468
name: $name,
468469
value: $value,
@@ -472,7 +473,7 @@ private function attributesToParameters(array $features, ?string $group = null):
472473
);
473474
}
474475

475-
// deduplicate by name
476+
// Deduplicate by name
476477
$byName = [];
477478
foreach ($out as $p) {
478479
$byName[$p->name] ??= $p;
@@ -527,11 +528,12 @@ public function getCapabilities(): array
527528
return [
528529
ProviderCapabilities::BASIC,
529530
ProviderCapabilities::PICTURE,
530-
//ProviderCapabilities::DATASHEET, //currently not implemented
531+
//ProviderCapabilities::DATASHEET, // currently not implemented
531532
ProviderCapabilities::PRICE,
532533
ProviderCapabilities::FOOTPRINT,
533534
];
534535
}
536+
535537
private function complianceToParameters(array $product, ?string $group = 'Compliance'): array
536538
{
537539
$params = [];
@@ -543,7 +545,7 @@ private function complianceToParameters(array $product, ?string $group = 'Compli
543545
if (is_bool($value)) {
544546
$value = $value ? 'Yes' : 'No';
545547
} elseif (is_array($value) || is_object($value)) {
546-
// avoid dumping huge structures
548+
// Avoid dumping large or complex structures
547549
return;
548550
} else {
549551
$value = trim((string) $value);
@@ -563,28 +565,28 @@ private function complianceToParameters(array $product, ?string $group = 'Compli
563565
$add('RoHS conform', $product['labelRoHS'] ?? null); // "yes"/"no"
564566

565567
$rawRoHsDate = $product['dateRoHS'] ?? null;
566-
// Try to parse and reformat date to Y-m-d (don't use language-dependent formats)
568+
// Try to parse and reformat date to Y-m-d (do not use language-dependent formats)
567569
if (is_string($rawRoHsDate) && $rawRoHsDate !== '') {
568570
try {
569571
$dt = new \DateTimeImmutable($rawRoHsDate);
570572
$formatted = $dt->format('Y-m-d');
571573
} catch (\Exception $e) {
572574
$formatted = $rawRoHsDate;
573575
}
574-
// Use always the same parameter name (don't use language-dependent names)
576+
// Always use the same parameter name (do not use language-dependent names)
575577
$add('RoHS date', $formatted);
576578
}
577579
$add('SVHC free', $product['SVHC'] ?? null); // bool
578580
$add('Hazardous good', $product['hazardousGood'] ?? null); // bool
579581
$add('Hazardous materials', $product['hazardousMaterials'] ?? null); // bool
580582

581583
$add('Country of origin', $product['countryOfOrigin'] ?? null);
582-
// Customs tariffs code/Zolltarifnummer always as string otherwise "85411000" is stored as "8.5411e+7"
584+
// Customs tariff code must always be stored as string, otherwise "85411000" may be stored as "8.5411e+7"
583585
if (isset($product['articleCustomsCode'])) {
584-
// Rohwert als String
586+
// Raw value as string
585587
$codeRaw = (string) $product['articleCustomsCode'];
586588

587-
// Optional: nur Ziffern behalten (falls mal Leerzeichen o.ä. drin sind)
589+
// Optionally keep only digits (in case of spaces or other characters)
588590
$code = preg_replace('/\D/', '', $codeRaw) ?? $codeRaw;
589591
$code = trim($code);
590592

@@ -604,6 +606,7 @@ private function complianceToParameters(array $product, ?string $group = 'Compli
604606

605607
return $params;
606608
}
609+
607610
/**
608611
* @param string[] $keywords
609612
* @return array<string, SearchResultDTO[]>
@@ -618,10 +621,10 @@ public function searchByKeywordsBatch(array $keywords): array
618621
continue;
619622
}
620623

621-
// Bestehende Einzelsuche wiederverwenden → liefert PartDetailDTO[]
624+
// Reuse existing single search -> returns PartDetailDTO[]
622625
$partDetails = $this->searchByKeyword($keyword);
623626

624-
// In SearchResultDTO[] konvertieren
627+
// Convert to SearchResultDTO[]
625628
$results[$keyword] = array_map(
626629
fn(PartDetailDTO $detail) => $this->convertPartDetailToSearchResult($detail),
627630
$partDetails
@@ -630,6 +633,7 @@ public function searchByKeywordsBatch(array $keywords): array
630633

631634
return $results;
632635
}
636+
633637
private function searchProducts(string $query): array
634638
{
635639
$response = $this->makeAPICall('/products/search/', [
@@ -641,8 +645,9 @@ private function searchProducts(string $query): array
641645

642646
return $response['products'] ?? [];
643647
}
648+
644649
/**
645-
* Konvertiert ein PartDetailDTO in ein SearchResultDTO für Bulk-Suche.
650+
* Converts a PartDetailDTO into a SearchResultDTO for bulk search.
646651
*/
647652
private function convertPartDetailToSearchResult(PartDetailDTO $detail): SearchResultDTO
648653
{

0 commit comments

Comments
 (0)