Skip to content

Commit

Permalink
Bugfix with xliff format
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Dec 23, 2015
1 parent f55e386 commit 9ffd5b2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ _happyr_translation:
``` yaml

happyr_translation:
file_extension: 'xliff' # could be 'json', 'mo', 'php', 'po', 'yaml' and many more
file_extension: 'xlf' # could be 'json', 'mo', 'php', 'po', 'yaml' and many more
locales: []
dimensions: []
translation_service: 'loco'
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getConfigTreeBuilder()
->scalarNode('target_dir')->defaultValue('%kernel.root_dir%/Resources/translations')->end()
->booleanNode('auto_add_assets')->defaultFalse()->end()
->booleanNode('allow_edit')->defaultTrue()->end()
->enumNode('file_extension')->values(array('csv', 'ini', 'json', 'mo', 'php', 'po', 'qt', 'yaml', 'xliff'))->defaultValue('xliff')->end()
->enumNode('file_extension')->values(array('csv', 'ini', 'json', 'mo', 'php', 'po', 'qt', 'yaml', 'xlf'))->defaultValue('xlf')->end()
->arrayNode('locales')
->requiresAtLeastOneElement()
->prototype('scalar')->end()
Expand Down
10 changes: 6 additions & 4 deletions src/DependencyInjection/HappyrTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ private function copyValuesFromParentToProject($key, array &$config)
*/
protected function configureLoaderAndDumper(ContainerBuilder $container, $fileExtension)
{
$loader = $container->getDefinition('happyr.translation.loader');
$loader->setClass(sprintf('Symfony\Component\Translation\Loader\%sFileLoader', ucfirst($fileExtension)));
if ($fileExtension === 'xlf') {
$fileExtension = 'xliff';
}

$loader = $container->register('happyr.translation.loader', sprintf('Symfony\Component\Translation\Loader\%sFileLoader', ucfirst($fileExtension)));
$loader->addTag('translation.loader', ['alias' => $fileExtension]);

$dumper = $container->getDefinition('happyr.translation.dumper');
$dumper->setClass(sprintf('Symfony\Component\Translation\Dumper\%sFileDumper', ucfirst($fileExtension)));
$dumper = $container->register('happyr.translation.dumper', sprintf('Symfony\Component\Translation\Dumper\%sFileDumper', ucfirst($fileExtension)));
$dumper->addTag('translation.dumper', ['alias' => $fileExtension]);
}
}
9 changes: 0 additions & 9 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
parameters:

services:
happyr.translation.loader:
class: Symfony\Component\Translation\Loader\XliffFileLoader
tags:
- { name: 'translation.loader', alias: 'xliff' }

happyr.translation.dumper:
class: Symfony\Component\Translation\Dumper\XliffFileDumper
tags:
- { name: 'translation.dumper', alias: 'xliff' }

# Custom data_collector to use our own template
happyr.translation.data_collector:
Expand Down
12 changes: 6 additions & 6 deletions src/Service/Loco.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,13 @@ public function updateTranslation(Message $message)
* If there is something wrong with the translation, please flag it.
*
* @param Message $message
* @param int $type 0: Fuzzy, 1: Error, 2: Review, 3: Pending
* @param int $type 0: Fuzzy, 1: Incorrect, 2: Provisional, 3: Unapproved, 4: Incomplete
*
* @return bool
*/
public function flagTranslation(Message $message, $type = 0)
{
$project = $this->getProject($message);
//$flags = ['fuzzy', 'error', 'review', 'pending'];
$flags = ['fuzzy', 'incorrect', 'provisional', 'unapproved', 'incomplete'];

try {
Expand Down Expand Up @@ -337,9 +336,9 @@ private function flatten(array &$messages, array $subnode = null, $path = null)
* @param string $domain
* @param bool $useDomainAsFilter
*/
protected function getUrls(array &$data, array &$config, $domain, $useDomainAsFilter)
protected function getUrls(array &$data, array $config, $domain, $useDomainAsFilter)
{
$query = $this->getExportQueryParams();
$query = $this->getExportQueryParams($config['api_key']);

if ($useDomainAsFilter) {
$query['filter'] = $domain;
Expand All @@ -359,17 +358,18 @@ protected function getUrls(array &$data, array &$config, $domain, $useDomainAsFi
*
* @return array
*/
private function getExportQueryParams()
private function getExportQueryParams($key)
{
$data = array(
'index' => 'id',
'status' => 'translated',
'key' => $key,
);
switch ($this->filesystemService->getFileExtension()) {
case 'php':
$data['format'] = 'zend'; // 'Zend' will give us a flat array
break;
case 'xliff':
case 'xlf':
default:
$data['format'] = 'symfony';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Translation/FilesystemUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function writeToFile($fileName, $data)
mkdir($this->targetDir, 0777, true);
}

file_put_contents(sprintf('%s/%s', $this->targetDir, $fileName, $data));
file_put_contents(sprintf('%s/%s', $this->targetDir, $fileName), $data);
}

/**
Expand Down

0 comments on commit 9ffd5b2

Please sign in to comment.