Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ private function getProjectNode()
->requiresAtLeastOneElement()
->prototype('scalar')->end()
->end()
->arrayNode('tags')
->prototype('scalar')->end()
->end()
->end()
->end();

Expand Down
17 changes: 16 additions & 1 deletion src/Service/Loco.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,16 @@ protected function getUrls(array &$data, array $config, $domain, $useDomainAsFil
$fileName = sprintf('%s.%s.%s', $domain, $locale, $this->filesystemService->getFileExtension());

$data[$url] = $fileName;

if (!empty($config['tags'])) {
$query_tags = $this->getExportQueryParams($config['api_key'], $config['tags']);

// Build url
$url = sprintf('%sexport/locale/%s.%s?%s', self::BASE_URL, $locale, $this->filesystemService->getFileExtension(), http_build_query($query_tags));
$fileName = sprintf('%s.%s.%s', $domain.'-'.(implode($config['tags'], '-')), $locale, $this->filesystemService->getFileExtension());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of the tags?
It looks like you building another URL here. The result would be that you download all translations AND translation filtered with tags.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my project, i need two files per locale : one for back-end translations, where i take all translations, and one for front-end translations, where i select translations using tags (in order to have minify the file size).


$data[$url] = $fileName;
}
}
}

Expand All @@ -437,13 +447,18 @@ protected function getUrls(array &$data, array $config, $domain, $useDomainAsFil
*
* @return array
*/
private function getExportQueryParams($key)
private function getExportQueryParams($key, $tags=null)
{
$data = array(
'index' => 'id',
'status' => 'translated',
'key' => $key,
);

if ($tags !== null) {
$data['filter'] = implode($tags, ',');
}

switch ($this->filesystemService->getFileExtension()) {
case 'php':
$data['format'] = 'zend'; // 'Zend' will give us a flat array
Expand Down