From e970476b6949e2111095ca1b6e609f10dccde667 Mon Sep 17 00:00:00 2001 From: Guite Date: Fri, 17 Jan 2020 13:42:20 +0100 Subject: [PATCH 1/4] look for translation files with intl domain suffix, too --- src/FileStorage.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/FileStorage.php b/src/FileStorage.php index fe75726..543ace0 100644 --- a/src/FileStorage.php +++ b/src/FileStorage.php @@ -140,9 +140,16 @@ private function writeCatalogue(MessageCatalogueInterface $catalogue, string $lo $resources = $catalogue->getResources(); $options = $this->options; $written = false; + $intlDomainSuffix = '(\\' . MessageCatalogueInterface::INTL_DOMAIN_SUFFIX . ')'; + $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; From 654530961437f7776b8a840fb465fca824907fd7 Mon Sep 17 00:00:00 2001 From: Guite Date: Fri, 17 Jan 2020 14:06:28 +0100 Subject: [PATCH 2/4] compat for older Sf versions --- src/FileStorage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/FileStorage.php b/src/FileStorage.php index 543ace0..be30605 100644 --- a/src/FileStorage.php +++ b/src/FileStorage.php @@ -140,7 +140,8 @@ private function writeCatalogue(MessageCatalogueInterface $catalogue, string $lo $resources = $catalogue->getResources(); $options = $this->options; $written = false; - $intlDomainSuffix = '(\\' . MessageCatalogueInterface::INTL_DOMAIN_SUFFIX . ')'; + // $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) { From ca91642affad46b6391f2df3dc3e493dd37591ff Mon Sep 17 00:00:00 2001 From: Guite Date: Sun, 19 Jan 2020 13:23:24 +0100 Subject: [PATCH 3/4] fixed php-cs-fixer issues --- src/FileStorage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FileStorage.php b/src/FileStorage.php index be30605..aab9bb3 100644 --- a/src/FileStorage.php +++ b/src/FileStorage.php @@ -141,8 +141,8 @@ private function writeCatalogue(MessageCatalogueInterface $catalogue, string $lo $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]+)$|'; + $intlDomainSuffix = '(\\'.'+intl-icu'.')'; + $searchPatternWithIntl = '|/'.$domain.$intlDomainSuffix.'\.'.$locale.'\.([a-z]+)$|'; $searchPatternWithoutIntl = str_replace($intlDomainSuffix, '', $searchPatternWithIntl); foreach ($resources as $resource) { $path = (string) $resource; From 585469ccf626b1ef82fe1f90d985b5ef6030a793 Mon Sep 17 00:00:00 2001 From: Guite Date: Sun, 19 Jan 2020 13:26:39 +0100 Subject: [PATCH 4/4] adjusted phpstan baseline --- phpstan-baseline.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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