diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 87b2407..cae5e91 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2,5 +2,5 @@ parameters: ignoreErrors: - message: "#^Parameter \\#1 \\$catalogue of method Symfony\\\\Component\\\\Translation\\\\Writer\\\\TranslationWriterInterface\\:\\:write\\(\\) expects Symfony\\\\Component\\\\Translation\\\\MessageCatalogue, Symfony\\\\Component\\\\Translation\\\\MessageCatalogueInterface given\\.$#" - count: 2 + count: 3 path: src/FileStorage.php diff --git a/src/FileStorage.php b/src/FileStorage.php index fe75726..aab9bb3 100644 --- a/src/FileStorage.php +++ b/src/FileStorage.php @@ -140,9 +140,17 @@ private function writeCatalogue(MessageCatalogueInterface $catalogue, string $lo $resources = $catalogue->getResources(); $options = $this->options; $written = false; + // $intlDomainSuffix = '(\\' . MessageCatalogueInterface::INTL_DOMAIN_SUFFIX . ')'; # not available in older Symfony versions + $intlDomainSuffix = '(\\'.'+intl-icu'.')'; + $searchPatternWithIntl = '|/'.$domain.$intlDomainSuffix.'\.'.$locale.'\.([a-z]+)$|'; + $searchPatternWithoutIntl = str_replace($intlDomainSuffix, '', $searchPatternWithIntl); foreach ($resources as $resource) { $path = (string) $resource; - if (preg_match('|/'.$domain.'\.'.$locale.'\.([a-z]+)$|', $path, $matches)) { + if (preg_match($searchPatternWithIntl, $path, $matches)) { + $options['path'] = str_replace($matches[0], '', $path); + $this->writer->write($catalogue, $matches[2], $options); + $written = true; + } elseif (preg_match($searchPatternWithoutIntl, $path, $matches)) { $options['path'] = str_replace($matches[0], '', $path); $this->writer->write($catalogue, $matches[1], $options); $written = true;