Skip to content

Commit

Permalink
Merge pull request #49 from Guite/master
Browse files Browse the repository at this point in the history
look for translation files with intl domain suffix, too
  • Loading branch information
welcoMattic committed Jan 19, 2020
2 parents 7ace69c + 585469c commit caa23d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion src/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit caa23d0

Please sign in to comment.