Skip to content

Commit

Permalink
Fixes for project copywriting (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Ducoudray authored and cdaguerre committed Sep 19, 2016
1 parent 8d83f8d commit 4360b4d
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function getConfigTreeBuilder()
->prototype('scalar')->end()
->end()
->end()
->scalarNode('copywriting_word_count')->isRequired()->end()
->end()
;

Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/WorldiaTextmasterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('worldia.textmaster.templates.job.reject', $config['templates']['job']['reject']);

$container->setParameter('worldia.textmaster.mapping.properties', $config['mapping_properties']);
$container->setParameter('worldia.textmaster.copywriting_word_count', $config['copywriting_word_count']);
}
}
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<argument type="service" id="worldia.textmaster.api.manager" />
<argument type="service" id="worldia.textmaster.api.translator" />
<argument type="service" id="router" />
<argument>%worldia.textmaster.copywriting_word_count%</argument>
</service>

<service id="worldia.textmaster.generator.translation" class="%worldia.textmaster.generator.translation.class%">
Expand Down
1 change: 1 addition & 0 deletions Tests/Fixtures/Project/app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ worldia_textmaster:
base_uri: textmaster_api_base_uri
mapping_properties:
Worldia\Bundle\ProductTestBundle\Entity\Product: ['title', 'description']
copywriting_word_count: 200
1 change: 1 addition & 0 deletions Tests/Units/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function assertValidConfiguration()
'mapping_properties' => [
'Worldia\Bundle\ProductTestBundle\Entity\Product' => ['title', 'description'],
],
'copywriting_word_count' => 200,
],
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function getMinimalConfiguration()
'api_key' => 'My API key',
'api_secret' => 'My API secret',
],
'copywriting_word_count' => 200,
];
}

Expand All @@ -46,6 +47,8 @@ public function assertParameters()
$this->assertContainerBuilderHasParameter('worldia.textmaster.templates.project.index', 'WorldiaTextmasterBundle:Project:list.html.twig');
$this->assertContainerBuilderHasParameter('worldia.textmaster.templates.job.show', 'WorldiaTextmasterBundle:Job:show.html.twig');
$this->assertContainerBuilderHasParameter('worldia.textmaster.templates.job.index', 'WorldiaTextmasterBundle:Job:list.html.twig');

$this->assertContainerBuilderHasParameter('worldia.textmaster.copywriting_word_count', 200);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Tests/Units/Translation/TranslationManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public function shouldCreateProject()
$projectMock->expects($this->once())
->method('setCallback')
->willReturn($projectMock);
$projectMock->expects($this->once())
->method('setWorkTemplate')
->willReturn($projectMock);
$projectMock->expects($this->once())
->method('save')
->willReturn($projectMock);
Expand All @@ -63,7 +66,7 @@ public function shouldCreateProject()
->method('create')
->willReturn($documentMock);

$translationManager = new TranslationManager($textmasterManagerMock, $translatorMock, $routerMock);
$translationManager = new TranslationManager($textmasterManagerMock, $translatorMock, $routerMock, 150);
$project = $translationManager->create([$translatableMock], 'Project 1', 'en', 'fr', 'CO21', 'Lorem ipsum...', ['language_level' => 'premium']);

$this->assertTrue(in_array('Textmaster\Model\ProjectInterface', class_implements($project)));
Expand Down
5 changes: 3 additions & 2 deletions Translation/TranslationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function generate(
$briefing,
$languageTo = null,
array $options = [],
$activity = ProjectInterface::ACTIVITY_TRANSLATION
$activity = ProjectInterface::ACTIVITY_TRANSLATION,
$workTemplate = null
) {
if (null === $locale = $languageTo) {
$locale = $languageFrom;
Expand All @@ -59,7 +60,7 @@ public function generate(
return;
}

$project = $this->translationManager->create($translatables, $name, $languageFrom, $category, $briefing, $languageTo, $options, $activity);
$project = $this->translationManager->create($translatables, $name, $languageFrom, $category, $briefing, $languageTo, $options, $activity, $workTemplate);

return $project->launch();
}
Expand Down
6 changes: 4 additions & 2 deletions Translation/TranslationGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ interface TranslationGeneratorInterface
* @param string $briefing textmaster project briefing
* @param string $languageTo destination language identifier (ex: fr, en, de...)
* @param array $options textmaster project options
* @param array $activity textmaster project activity
* @param string $activity textmaster project activity
* @param string $workTemplate textmaster project work template
*
* @return ProjectInterface|null
*/
Expand All @@ -30,6 +31,7 @@ public function generate(
$briefing,
$languageTo = null,
array $options = [],
$activity
$activity,
$workTemplate = null
);
}
29 changes: 26 additions & 3 deletions Translation/TranslationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,29 @@ class TranslationManager implements TranslationManagerInterface
*/
protected $router;

/**
* @var int
*/
protected $defaultWordCount;

/**
* TranslationManager constructor.
*
* @param Manager $textmasterManager
* @param TranslatorInterface $translator
* @param UrlGeneratorInterface $router
* @param int $defaultWordCount
*/
public function __construct(
Manager $textmasterManager,
TranslatorInterface $translator,
UrlGeneratorInterface $router
UrlGeneratorInterface $router,
$defaultWordCount
) {
$this->textmasterManager = $textmasterManager;
$this->translator = $translator;
$this->router = $router;
$this->defaultWordCount = $defaultWordCount;
}

/**
Expand All @@ -53,7 +61,8 @@ public function create(
$briefing,
$languageTo = null,
array $options = [],
$activity = ProjectInterface::ACTIVITY_TRANSLATION
$activity = ProjectInterface::ACTIVITY_TRANSLATION,
$workTemplate = null
) {
$project = $this->textmasterManager->getProject();
$project
Expand All @@ -64,6 +73,7 @@ public function create(
->setCategory($category)
->setBriefing($briefing)
->setOptions($options)
->setWorkTemplate($workTemplate)
->setCallback($this->generateProjectCallback())
;

Expand Down Expand Up @@ -93,15 +103,16 @@ protected function generateDocuments(ProjectInterface $project, array $translata
{
$callback = $this->generateDocumentCallback($project);
$activity = $project->getActivity();
$documents = [];

$documents = [];
foreach ($translatableList as $translatable) {
$params = [];
$params['project'] = $project;
$params['document'] = [
'title' => $this->generateTitle($project, $translatable),
'instructions' => $this->generateInstructions($translatable, $activity),
'callback' => $callback,
'word_count' => ProjectInterface::ACTIVITY_COPYWRITING === $activity ? $this->getWordCount($translatable) : 0,
];
$documents[] = $this->translator->create($translatable, $params, false);
}
Expand Down Expand Up @@ -140,6 +151,18 @@ protected function generateInstructions($translatable, $activity)
return '';
}

/**
* Get word count for a copywriting document.
*
* @param object $translatable
*
* @return string
*/
protected function getWordCount($translatable)
{
return $this->defaultWordCount;
}

/**
* Generate a default callback for document in review.
*
Expand Down
4 changes: 3 additions & 1 deletion Translation/TranslationManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface TranslationManagerInterface
* @param string $languageTo
* @param array $options
* @param string $activity
* @param string $workTemplate
*
* @return ProjectInterface
*/
Expand All @@ -29,7 +30,8 @@ public function create(
$briefing,
$languageTo = null,
array $options = [],
$activity = ProjectInterface::ACTIVITY_TRANSLATION
$activity = ProjectInterface::ACTIVITY_TRANSLATION,
$workTemplate = null
);

/**
Expand Down

0 comments on commit 4360b4d

Please sign in to comment.