Skip to content

Commit

Permalink
Added XliffCoventer (#3)
Browse files Browse the repository at this point in the history
* Added XliffCoventer

* Code style

* Fixes

* Made classes final and added composer alias

* Added changlog
  • Loading branch information
Nyholm authored Jan 3, 2017
1 parent 1e4ad04 commit 0fbc711
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 625 deletions.
21 changes: 21 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Change Log

The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.

## 0.2.0

### Changed

- Made`TranslationLoader` final

### Removed

- `FileDumper` in favor for `FlysystemXliffDumper`
- `XliffFileLoader` in favor for `FlysystemXliffLoader`
- `XliffFileDumper`

## 0.1.0

Init release


8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"require": {
"php": "^5.5 || ^7.0",
"php-translation/common": "^0.2",
"php-translation/symfony-storage": "^0.1",
"php-translation/symfony-storage": "^0.2",
"symfony/translation": "^2.7 || ^3.0",
"league/flysystem": "^1.0"
},
Expand All @@ -32,5 +32,11 @@
"scripts": {
"test": "vendor/bin/phpunit",
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "0.2-dev"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Translation\Writer\TranslationWriter;
use Translation\PlatformAdapter\Flysystem\Dumper\XliffFileDumper;
use Translation\PlatformAdapter\Flysystem\Dumper\FlysystemXliffDumper;
use Translation\PlatformAdapter\Flysystem\Flysystem;
use Translation\PlatformAdapter\Flysystem\Loader\XliffFileLoader;
use Translation\PlatformAdapter\Flysystem\Loader\FlysystemXliffLoader;
use Translation\PlatformAdapter\Flysystem\TranslationLoader;
use Translation\SymfonyStorage\FileStorage;

Expand All @@ -38,12 +38,12 @@ public function load(array $configs, ContainerBuilder $container)
$baseServiceId = 'php_translation.adapter.flysystem.'.$name;
$flysytemServiceId = $data['flysystem_service'];

$dumperDef = $container->register($baseServiceId.'.dumper', XliffFileDumper::class);
$dumperDef = $container->register($baseServiceId.'.dumper', FlysystemXliffDumper::class);
$dumperDef->setPublic(false)->addMethodCall('setFilesystem', [new Reference($flysytemServiceId)]);
$writerDef = $container->register($baseServiceId.'.writer', TranslationWriter::class);
$writerDef->setPublic(false)->addMethodCall('addDumper', ['xlf', $dumperDef]);

$xlfLoaderDef = $container->register($baseServiceId.'.xlf_loader', XliffFileLoader::class);
$xlfLoaderDef = $container->register($baseServiceId.'.xlf_loader', FlysystemXliffLoader::class);
$xlfLoaderDef->setPublic(false)->addArgument(new Reference($flysytemServiceId));
$loaderDef = $container->register($baseServiceId.'.loader', TranslationLoader::class);
$loaderDef
Expand Down
22 changes: 2 additions & 20 deletions src/Dumper/FileDumper.php → src/Dumper/FlysystemXliffDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Translation\PlatformAdapter\Flysystem\Dumper;

use Symfony\Component\Translation\Dumper\DumperInterface;
use Symfony\Component\Translation\Dumper\XliffFileDumper;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Exception\InvalidArgumentException;
use League\Flysystem\Filesystem;
Expand All @@ -27,7 +27,7 @@
* @author Michel Salib <[email protected]>
* @author Tobias Nyholm <[email protected]>
*/
abstract class FileDumper implements DumperInterface
final class FlysystemXliffDumper extends XliffFileDumper
{
/**
* @var Filesystem
Expand Down Expand Up @@ -109,24 +109,6 @@ public function dump(MessageCatalogue $messages, $options = [])
}
}

/**
* Transforms a domain of a message catalogue to its string representation.
*
* @param MessageCatalogue $messages
* @param string $domain
* @param array $options
*
* @return string representation
*/
abstract public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = []);

/**
* Gets the file extension of the dumper.
*
* @return string file extension
*/
abstract protected function getExtension();

/**
* Gets the relative file path using the template.
*
Expand Down
184 changes: 0 additions & 184 deletions src/Dumper/XliffFileDumper.php

This file was deleted.

58 changes: 58 additions & 0 deletions src/Loader/FlysystemXliffLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* This file is part of the PHP Translation package.
*
* (c) PHP Translation team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Translation\PlatformAdapter\Flysystem\Loader;

use League\Flysystem\Filesystem;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Config\Resource\FileResource;
use Translation\SymfonyStorage\Loader\XliffLoader;

/**
* XliffFileLoader loads translations from XLIFF files.
*
* @author Tobias Nyholm <[email protected]>
*/
final class FlysystemXliffLoader extends XliffLoader
{
/**
* @var Filesystem
*/
private $filesystem;

/**
* @param Filesystem filesystem
*/
public function __construct(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}

/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!$this->filesystem->has($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}

$catalogue = new MessageCatalogue($locale);
$this->extractFromContent($this->filesystem->read($resource), $catalogue, $domain);

if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
$catalogue->addResource(new FileResource($resource));
}

return $catalogue;
}
}
Loading

0 comments on commit 0fbc711

Please sign in to comment.