-
Notifications
You must be signed in to change notification settings - Fork 93
Add Symfony 4 support #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ff02e83
24882e4
a16f916
6fb3429
1c4e527
75dc718
72a3306
7391edc
e114a06
4844b40
5887a83
23762ba
cfa14a1
4f23256
2931222
a54d3d6
d54ee4f
2d74ebc
06fc223
9594986
f40e62e
f14ee83
271672f
4469cfe
97671a8
d922523
5b0458e
66bd35e
b0dddbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PHP Translation package. | ||
* | ||
* (c) PHP Translation team <tobias.nyholm@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Translation\Bundle\DependencyInjection\CompilerPass; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you write a class comment that explains the purpose of this CompilerPass? |
||
/** | ||
* To provide a BC layer for Symfony 2.7 to 3.3 this compiler pass | ||
* registers an alias of whether TranslationReader or TranslationLoader | ||
* to be able to inject it in other services. | ||
*/ | ||
class LoaderOrReaderPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if ($container->has('translation.reader')) { | ||
$container->setAlias('translation.loader_or_reader', 'translation.reader'); | ||
|
||
return; | ||
} | ||
|
||
if ($container->has('translation.loader')) { | ||
$container->setAlias('translation.loader_or_reader', 'translation.loader'); | ||
|
||
return; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
services: | ||
php_translation.catalogue_fetcher: | ||
public: true | ||
class: Translation\Bundle\Catalogue\CatalogueFetcher | ||
arguments: ["@translation.loader"] | ||
arguments: ["@translation.loader_or_reader"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, thanks to @dkozickis for this idea and his help |
||
|
||
php_translation.catalogue_writer: | ||
public: true | ||
class: Translation\Bundle\Catalogue\CatalogueWriter | ||
arguments: ["@translation.writer", "%php_translation.default_locale%"] | ||
|
||
|
@@ -13,26 +15,30 @@ services: | |
arguments: ["@php_translation.catalogue_fetcher", "@php_translation.catalogue_writer", ~] | ||
|
||
php_translation.catalogue_manager: | ||
public: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do the services need to be public? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we call it from the container in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can inject it into controller instead, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we should But that is out of scope for this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, it won't work in 2.7, will it? |
||
class: Translation\Bundle\Catalogue\CatalogueManager | ||
|
||
php_translation.extractor: | ||
class: Translation\Extractor\Extractor | ||
|
||
php_translation.configuration_manager: | ||
public: true | ||
class: Translation\Bundle\Service\ConfigurationManager | ||
|
||
php_translation.importer: | ||
public: true | ||
class: Translation\Bundle\Service\Importer | ||
arguments: ["@php_translation.extractor"] | ||
|
||
php_translation.cache_clearer: | ||
public: true | ||
class: Translation\Bundle\Service\CacheClearer | ||
arguments: ["%kernel.cache_dir%", "@translator", "@filesystem"] | ||
|
||
php_translation.local_file_storage.abstract: | ||
class: Translation\SymfonyStorage\FileStorage | ||
abstract: true | ||
arguments: ["@translation.writer", "@translation.loader", ~, []] | ||
arguments: ["@translation.writer", "@translation.loader_or_reader", ~, []] | ||
|
||
php_translation.storage.xlf_loader: | ||
class: Translation\SymfonyStorage\Loader\XliffLoader | ||
|
@@ -45,5 +51,6 @@ services: | |
- { name: translation.dumper, alias: xlf, legacy-alias: xliff } | ||
|
||
php_translation.catalogue_counter: | ||
public: true | ||
class: Translation\Bundle\Catalogue\CatalogueCounter | ||
arguments: [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
services: | ||
test.php_translation.edit_in_place.activator: | ||
public: true | ||
alias: 'php_translation.edit_in_place.activator' | ||
|
||
test.php_translation.extractor.php: | ||
public: true | ||
alias: 'php_translation.extractor.php' | ||
|
||
test.php_translation.extractor.twig: | ||
public: true | ||
alias: 'php_translation.extractor.twig' | ||
|
||
test.php_translation.extractor: | ||
public: true | ||
alias: 'php_translation.extractor' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PHP Translation package. | ||
* | ||
* (c) PHP Translation team <tobias.nyholm@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\Component\Translation\MessageCatalogue; | ||
use Translation\Bundle\Catalogue\CatalogueFetcher; | ||
use Translation\Bundle\Model\Configuration; | ||
use Translation\Bundle\Tests\Functional\BaseTestCase; | ||
|
||
class CatalogueFetcherTest extends BaseTestCase | ||
{ | ||
/** | ||
* @var CatalogueFetcher | ||
*/ | ||
private $catalogueFetcher; | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
file_put_contents( | ||
__DIR__.'/../app/Resources/translations/messages.sv.xlf', | ||
<<<'XML' | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="fr-FR" trgLang="en-US"> | ||
<file id="messages.en_US"> | ||
<unit id="LCa0a2j"> | ||
<segment> | ||
<source>key0</source> | ||
<target>trans0</target> | ||
</segment> | ||
</unit> | ||
<unit id="LCa0a2b"> | ||
<segment> | ||
<source>key1</source> | ||
<target>trans1</target> | ||
</segment> | ||
</unit> | ||
</file> | ||
</xliff> | ||
|
||
XML | ||
); | ||
} | ||
|
||
public function testFetchCatalogue() | ||
{ | ||
$this->bootKernel(); | ||
|
||
$this->catalogueFetcher = $this->getContainer()->get('php_translation.catalogue_fetcher'); | ||
|
||
$data = self::getDefaultData(); | ||
$data['external_translations_dirs'] = [__DIR__.'/../app/Resources/translations/']; | ||
|
||
$conf = new Configuration($data); | ||
|
||
/** @var MessageCatalogue[] $catalogues */ | ||
$catalogues = $this->catalogueFetcher->getCatalogues($conf, ['sv']); | ||
|
||
$this->assertEquals('sv', $catalogues[0]->getLocale()); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getDefaultData() | ||
{ | ||
return [ | ||
'name' => 'getName', | ||
'locales' => ['getLocales'], | ||
'project_root' => 'getProjectRoot', | ||
'output_dir' => 'getOutputDir', | ||
'dirs' => ['getDirs'], | ||
'excluded_dirs' => ['getExcludedDirs'], | ||
'excluded_names' => ['getExcludedNames'], | ||
'external_translations_dirs' => ['getExternalTranslationsDirs'], | ||
'output_format' => 'getOutputFormat', | ||
'blacklist_domains' => ['getBlacklistDomains'], | ||
'whitelist_domains' => ['getWhitelistDomains'], | ||
'xliff_version' => ['getXliffVersion'], | ||
]; | ||
} | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->kernel->addConfigFile(__DIR__.'/../app/config/normal_config.yml'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface does not exits anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? Because I see it in master: https://github.com/php-translation/symfony-storage/blob/master/src/TranslationLoader.php and it is not even deprecated.