Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ private function configsNode(ArrayNodeDefinition $root)
->arrayNode('whitelist_domains')
->prototype('scalar')->end()
->end()
->arrayNode('local_storage')
->info('Where translations are stored locally.')
->prototype('enum')->values($this->getStorages())->defaultValue('filesystem')->end()
->end()
->arrayNode('remote_storage')
->info('Any remote storage for the translation, could be a third party translation service.')
->prototype('enum')->values($this->getStorages())->defaultValue('blackhole')->end()
->end()
->scalarNode('output_dir')->isRequired()->cannotBeEmpty()->end()
->scalarNode('project_root')->info("The root dir of your project. By default this will be kernel_root's parent. ")->end()
->end()
Expand All @@ -156,11 +164,35 @@ private function addTranslationServiceNode(ArrayNodeDefinition $root)
{
$root
->children()
->enumNode('storage')
->info('Where translations are stored.')
->values(['blackhole', 'filesystem', 'loco'])
->defaultValue('filesystem')
->arrayNode('platforms')
->children()
->arrayNode('loco')
->addDefaultsIfNotSet()
->children()
->arrayNode('projects')
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('api_key')->info('The API key for this project.')->isRequired()->end()
->end()
->end()
->end()
->end()
->end()
->end();
}

/**
*
* @return array
*/
private function getStorages()
{
return [
'blackhole',
'filesystem',
'loco'
];
}

}
39 changes: 39 additions & 0 deletions DependencyInjection/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

namespace Translation\Bundle\DependencyInjection;

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Translation\Bundle\Service\StorageService;
use Translation\PlatformAdapter\Adapter\Loco;

/**
* This is the class that loads and manages your bundle configuration.
Expand Down Expand Up @@ -55,6 +57,8 @@ public function load(array $configs, ContainerBuilder $container)
$this->enableFallbackAutoTranslator($container, $config);
}

$this->handlePlatformAdapters($loader, $container, $config['platforms']);

$first = null;
foreach ($config['configs'] as $name => &$c) {
if ($first === null || $name === 'default') {
Expand Down Expand Up @@ -87,6 +91,41 @@ private function enableWebUi(ContainerBuilder $container, $config)
{
}

/**
* @param LoaderInterface $loader
* @param ContainerBuilder $container
* @param array $config
*/
private function handlePlatformAdapters(LoaderInterface $loader, ContainerBuilder $container, array $config)
{
foreach ($config as $name => $config) {
switch ($name) {
case 'loco':
$this->verifyClassExists(Loco::class);
// TODO load
break;
default:
throw new \LogicException(sprintf('Platform named "%s" was not found.', $name));
}
}
}

/**
* @param string $class
* @param string|null $message
*
* @throws \LogicException if class does not exist.
*/
private function verifyClassExists($class, $message = null)
{
if (null === $message) {
$message = sprintf('Could not find class "%s" that is needed for your current Translation configration.', $class);
}
if (!class_exists($class)) {
throw new \LogicException($message);
}
}

private function enableSymfonyProfiler(ContainerBuilder $container, $config)
{
$container->setParameter('php_translation.toolbar.allow_edit', $config['symfony_profiler']['allow_edit']);
Expand Down