settings = $settings; $this->map = array_map('strval', $map); $this->localeMap = $localeMap; } /** * {@inheritdoc} */ public function count(): int { return count($this->retrieveLocaleMap() ?? $this->map); } /** * {@inheritdoc} */ public function generate(string $value): ?string { $map = $this->retrieveLocaleMap() ?? $this->map; $index = array_search($value, $map, true); return $index !== false ? (string)$index : null; } /** * {@inheritdoc} */ public function resolve(string $value): ?string { $map = $this->retrieveLocaleMap() ?? $this->map; return isset($map[$value]) ? (string)$map[$value] : null; } /** * Fetches the map of with the matching locale. */ protected function retrieveLocaleMap(): ?array { $locale = (string)$this->siteLanguage->getLocale(); foreach ($this->localeMap as $item) { $pattern = '#^' . str_replace('_', '-', $item['locale']) . '#i'; if (preg_match($pattern, $locale)) { return array_map('strval', $item['map']); } } return null; } }