Skip to content

Commit caa23d0

Browse files
authored
Merge pull request #49 from Guite/master
look for translation files with intl domain suffix, too
2 parents 7ace69c + 585469c commit caa23d0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

phpstan-baseline.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ parameters:
22
ignoreErrors:
33
-
44
message: "#^Parameter \\#1 \\$catalogue of method Symfony\\\\Component\\\\Translation\\\\Writer\\\\TranslationWriterInterface\\:\\:write\\(\\) expects Symfony\\\\Component\\\\Translation\\\\MessageCatalogue, Symfony\\\\Component\\\\Translation\\\\MessageCatalogueInterface given\\.$#"
5-
count: 2
5+
count: 3
66
path: src/FileStorage.php

src/FileStorage.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,17 @@ private function writeCatalogue(MessageCatalogueInterface $catalogue, string $lo
140140
$resources = $catalogue->getResources();
141141
$options = $this->options;
142142
$written = false;
143+
// $intlDomainSuffix = '(\\' . MessageCatalogueInterface::INTL_DOMAIN_SUFFIX . ')'; # not available in older Symfony versions
144+
$intlDomainSuffix = '(\\'.'+intl-icu'.')';
145+
$searchPatternWithIntl = '|/'.$domain.$intlDomainSuffix.'\.'.$locale.'\.([a-z]+)$|';
146+
$searchPatternWithoutIntl = str_replace($intlDomainSuffix, '', $searchPatternWithIntl);
143147
foreach ($resources as $resource) {
144148
$path = (string) $resource;
145-
if (preg_match('|/'.$domain.'\.'.$locale.'\.([a-z]+)$|', $path, $matches)) {
149+
if (preg_match($searchPatternWithIntl, $path, $matches)) {
150+
$options['path'] = str_replace($matches[0], '', $path);
151+
$this->writer->write($catalogue, $matches[2], $options);
152+
$written = true;
153+
} elseif (preg_match($searchPatternWithoutIntl, $path, $matches)) {
146154
$options['path'] = str_replace($matches[0], '', $path);
147155
$this->writer->write($catalogue, $matches[1], $options);
148156
$written = true;

0 commit comments

Comments
 (0)