Skip to content

Commit

Permalink
add support for options (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Jan 4, 2017
1 parent 08e93b6 commit ec9c2b4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ final class FileStorage implements Storage, TransferableStorage
*/
private $dir;

/**
* @var array with option to the dumper
*/
private $options;

/**
* @var MessageCatalogue[] Fetched catalogies
*/
Expand All @@ -50,8 +55,9 @@ final class FileStorage implements Storage, TransferableStorage
* @param TranslationWriter $writer
* @param SymfonyTranslationLoader|TranslationLoader $loader
* @param array $dir
* @param array $options
*/
public function __construct(TranslationWriter $writer, $loader, array $dir)
public function __construct(TranslationWriter $writer, $loader, array $dir, array $options = [])
{
if (!$loader instanceof SymfonyTranslationLoader && !$loader instanceof TranslationLoader) {
throw new \LogicException('Second parameter of FileStorage must be a Symfony translation loader or implement Translation\SymfonyStorage\TranslationLoader');
Expand All @@ -64,6 +70,7 @@ public function __construct(TranslationWriter $writer, $loader, array $dir)
$this->writer = $writer;
$this->loader = $loader;
$this->dir = $dir;
$this->options = $options;
}

/**
Expand Down Expand Up @@ -141,10 +148,12 @@ public function import(MessageCatalogueInterface $catalogue)
private function writeCatalogue(MessageCatalogue $catalogue, $locale, $domain)
{
$resources = $catalogue->getResources();
$options = $this->options;
foreach ($resources as $resource) {
$path = (string) $resource;
if (preg_match('|/'.$domain.'\.'.$locale.'\.([a-z]+)$|', $path, $matches)) {
$this->writer->writeTranslations($catalogue, $matches[1], ['path' => str_replace($matches[0], '', $path)]);
$options['path'] = str_replace($matches[0], '', $path);
$this->writer->writeTranslations($catalogue, $matches[1], $options);
}
}
}
Expand Down

0 comments on commit ec9c2b4

Please sign in to comment.