storeViewRegistry = $storeViewRegistry; $this->storeManager = $storeManager; } public function map(string $language, ?string $market = null): ?string { $language = strtolower(trim($language)); if ($market !== null && $this->isRealStoreCodeInScope($market) && $this->languageFromStoreCode($market) === $language ) { return $market; } return $this->getDefaultStoreCodeForLanguage($language); } public function languageFromStoreCode(string $storeCode): ?string { return $this->storeViewRegistry->getLanguageByStoreCode($storeCode); } public function marketFromStoreCode(string $storeCode): ?string { return $this->isRealStoreCodeInScope($storeCode) ? $storeCode : null; } public function isRealStoreCodeInScope(string $storeCode): bool { return $this->storeViewRegistry->isStoreCodeInWebsite($storeCode, $this->getWebsiteId()); } public function isLanguageAllowed(string $language): bool { return $this->storeViewRegistry->isLanguageInWebsite($language, $this->getWebsiteId()); } public function getDefaultStoreCodeForLanguage(string $language): ?string { return $this->storeViewRegistry->getStoreCodeForLanguageInWebsite($language, $this->getWebsiteId()); } public function getDefaultLanguage(): ?string { try { $defaultStore = $this->storeManager->getWebsite()->getDefaultStore(); return $defaultStore ? $this->languageFromStoreCode((string)$defaultStore->getCode()) : null; } catch (\Throwable $exception) { return null; } } public function isDefaultLanguage(string $language): bool { return strtolower(trim($language)) === $this->getDefaultLanguage(); } private function getWebsiteId(): int { return (int)$this->storeManager->getWebsite()->getId(); } }