Skip to content

Commit

Permalink
Remove dependency on templating component
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrech committed Sep 5, 2017
1 parent 6d5d57d commit 0244e30
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 42 deletions.
14 changes: 7 additions & 7 deletions Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use Bazinga\Bundle\JsTranslationBundle\Finder\TranslationFinder;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Twig_Environment;

/**
* @author William DURAND <william.durand1@gmail.com>
Expand All @@ -23,9 +23,9 @@ class Controller
private $translator;

/**
* @var EngineInterface
* @var Twig_Environment
*/
private $engine;
private $twig;

/**
* @var TranslationFinder
Expand Down Expand Up @@ -63,7 +63,7 @@ class Controller

/**
* @param TranslatorInterface $translator The translator.
* @param EngineInterface $engine The engine.
* @param Twig_Environment $twig The twig environment.
* @param TranslationFinder $translationFinder The translation finder.
* @param string $cacheDir
* @param boolean $debug
Expand All @@ -73,7 +73,7 @@ class Controller
*/
public function __construct(
TranslatorInterface $translator,
EngineInterface $engine,
Twig_Environment $twig,
TranslationFinder $translationFinder,
$cacheDir,
$debug = false,
Expand All @@ -82,7 +82,7 @@ public function __construct(
$httpCacheTime = 86400
) {
$this->translator = $translator;
$this->engine = $engine;
$this->twig = $twig;
$this->translationFinder = $translationFinder;
$this->cacheDir = $cacheDir;
$this->debug = $debug;
Expand Down Expand Up @@ -150,7 +150,7 @@ public function getTranslationsAction(Request $request, $domain, $_format)
}
}

$content = $this->engine->render('BazingaJsTranslationBundle::getTranslations.' . $_format . '.twig', array(
$content = $this->twig->render('@BazingaJsTranslation/getTranslations.' . $_format . '.twig', array(
'fallback' => $this->localeFallback,
'defaultDomain' => $this->defaultDomain,
'translations' => $translations,
Expand Down
20 changes: 10 additions & 10 deletions Dumper/TranslationDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Bazinga\Bundle\JsTranslationBundle\Finder\TranslationFinder;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\Filesystem\Filesystem;
use Twig_Environment;

/**
* @author Adrien Russo <adrien.russo.qc@gmail.com>
Expand All @@ -16,9 +16,9 @@ class TranslationDumper
const DEFAULT_TRANSLATION_PATTERN = '/translations/{domain}.{_format}';

/**
* @var EngineInterface
* @var \Twig_Environment
*/
private $engine;
private $twig;

/**
* @var TranslationFinder
Expand Down Expand Up @@ -56,22 +56,22 @@ class TranslationDumper
private $defaultDomain;

/**
* @param EngineInterface $engine The engine.
* @param Twig_Environment $twig The twig environment.
* @param TranslationFinder $finder The translation finder.
* @param FileSystem $filesystem The file system.
* @param string $localeFallback
* @param string $defaultDomain
*/
public function __construct(
EngineInterface $engine,
Twig_Environment $twig,
TranslationFinder $finder,
Filesystem $filesystem,
$localeFallback = '',
$defaultDomain = '',
array $activeLocales = array(),
array $activeDomains = array()
) {
$this->engine = $engine;
$this->twig = $twig;
$this->finder = $finder;
$this->filesystem = $filesystem;
$this->localeFallback = $localeFallback;
Expand Down Expand Up @@ -166,7 +166,7 @@ private function dumpConfig($pattern, array $formats, $target)

file_put_contents(
$file,
$this->engine->render('BazingaJsTranslationBundle::config.' . $format . '.twig', array(
$this->twig->render('@BazingaJsTranslation/config.' . $format . '.twig', array(
'fallback' => $this->localeFallback,
'defaultDomain' => $this->defaultDomain,
))
Expand All @@ -179,7 +179,7 @@ private function dumpTranslationsPerDomain($pattern, array $formats, $target)
foreach ($this->getTranslations() as $locale => $domains) {
foreach ($domains as $domain => $translations) {
foreach ($formats as $format) {
$content = $this->engine->render('BazingaJsTranslationBundle::getTranslations.' . $format . '.twig', array(
$content = $this->twig->render('@BazingaJsTranslation/getTranslations.' . $format . '.twig', array(
'translations' => array($locale => array(
$domain => $translations,
)),
Expand Down Expand Up @@ -210,8 +210,8 @@ private function dumpTranslationsPerLocale($pattern, array $formats, $target)
{
foreach ($this->getTranslations() as $locale => $domains) {
foreach ($formats as $format) {
$content = $this->engine->render(
'BazingaJsTranslationBundle::getTranslations.' . $format . '.twig',
$content = $this->twig->render(
'@BazingaJsTranslation/getTranslations.' . $format . '.twig',
array(
'translations' => array($locale => $domains),
'include_config' => false,
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/controllers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<services>
<service id="bazinga.jstranslation.controller" class="%bazinga.jstranslation.controller.class%">
<argument type="service" id="translator" />
<argument type="service" id="templating" />
<argument type="service" id="twig" />
<argument type="service" id="bazinga.jstranslation.translation_finder" />
<argument>%kernel.cache_dir%/bazinga-js-translation</argument>
<argument>%kernel.debug%</argument>
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<argument type="collection"></argument> <!-- all resource files paths from the framework bundle -->
</service>
<service id="bazinga.jstranslation.translation_dumper" class="%bazinga.jstranslation.translation_dumper.class%">
<argument type="service" id="templating" />
<argument type="service" id="twig" />
<argument type="service" id="bazinga.jstranslation.translation_finder" />
<argument type="service" id="filesystem" />
<argument></argument> <!-- fallback (locale) -->
Expand Down
21 changes: 21 additions & 0 deletions Tests/Fixtures/app/config/base_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
framework:
secret: test
router: { resource: "%kernel.root_dir%/config/routing.yml" }
test: ~
translator: { enabled: true }
validation: { enabled: false }

# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"

# Traduction dans JS
bazinga_js_translation:
active_locales:
- fr
- en
active_domains:
- messages
- numerics
- foo
2 changes: 1 addition & 1 deletion Tests/Fixtures/app/config/default.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
imports:
- { resource: older_versions_config.yml }
- { resource: base_config.yml }

framework:
translator:
Expand Down
26 changes: 6 additions & 20 deletions Tests/Fixtures/app/config/older_versions_config.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
imports:
- { resource: base_config.yml }

framework:
secret: test
router: { resource: "%kernel.root_dir%/config/routing.yml" }
# Needed for Symfony 2.7 as the Exception controller from TwigBundle uses
# the Templating classes instead of the new Twig template notation.
# Probably related to https://github.com/symfony/symfony/pull/15970
templating: { engines: [ 'twig' ] }
test: ~
translator: { enabled: true }
validation: { enabled: false }

# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"

# Traduction dans JS
bazinga_js_translation:
active_locales:
- fr
- en
active_domains:
- messages
- numerics
- foo
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"symfony/finder": "~2.7|~3.1",
"symfony/console": "~2.7|~3.1",
"symfony/intl": "~2.7|~3.1",
"symfony/templating": "~2.7|~3.1",
"symfony/translation": "~2.7|~3.1"
"symfony/translation": "~2.7|~3.1",
"symfony/twig-bundle": "~2.7|~3.1"
},
"require-dev": {
"symfony/asset": "~2.7|~3.1",
Expand Down

0 comments on commit 0244e30

Please sign in to comment.