Skip to content

Commit

Permalink
[TranslatorBundle] fixed sf4 translations issue (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
deZinc authored and acrobat committed Feb 14, 2019
1 parent f49346d commit 1c92b9c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Expand Up @@ -25,8 +25,8 @@ public function getConfigTreeBuilder()
$rootNode = $treeBuilder->root('kuma_translator');
}

$availableStorageEngines = array('orm');
$defaultFileFormats = array('yml', 'xliff');
$availableStorageEngines = ['orm'];
$defaultFileFormats = ['yml', 'yaml', 'xliff'];

$rootNode
->children()
Expand Down
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Kernel;

/**
* This is the class that loads and manages your bundle configuration
Expand Down Expand Up @@ -90,7 +91,13 @@ public function registerTranslatorConfiguration($config, $container)

$dirs[] = dirname($r->getFilename()).'/Resources/translations';
}
$overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations';

if (Kernel::VERSION_ID < 4000) {
$overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations';
} else {
$overridePath = $container->getParameter('kernel.project_dir').'/translations';
}

foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
$reflection = new \ReflectionClass($class);
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/translations')) {
Expand All @@ -100,7 +107,14 @@ public function registerTranslatorConfiguration($config, $container)
$dirs[] = $dir;
}
}
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {

if (Kernel::VERSION_ID < 4000) {
$dir = $container->getParameter('kernel.root_dir').'/Resources/translations';
} else {
$dir = $container->getParameter('kernel.project_dir').'/translations';
}

if (is_dir($dir)) {
$dirs[] = $dir;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/TranslatorBundle/README.md
Expand Up @@ -53,7 +53,7 @@ kunstmaan_translator:
bundles: []
cache_dir: %kernel.cache_dir%/translations
managed_locales: []
file_formats: ['yml', 'xliff']
file_formats: ['yml', 'yaml', 'xliff']
debug: defaults to the kernel.debug parameter (boolean)
```

Expand Down
Expand Up @@ -49,6 +49,7 @@ private function getContainer()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.root_dir', 'src/Kunstmaan/TranslatorBundle');
$container->setParameter('kernel.project_dir', 'src/Kunstmaan/TranslatorBundle');
$container->setParameter('kernel.bundles', array(new \Kunstmaan\TranslatorBundle\KunstmaanTranslatorBundle()));
$container->setParameter('kernel.debug', true);
$container->setParameter('kunstmaan_admin.default_locale', 'en');
Expand Down

0 comments on commit 1c92b9c

Please sign in to comment.