From 39e498dca4f50f9401d8a36d11098a082ba33268 Mon Sep 17 00:00:00 2001 From: yoannlecoguic Date: Wed, 26 Oct 2016 11:24:06 +0200 Subject: [PATCH 1/4] With this patch, you can specify tags for loco, and it will get the associated translation filtered by this tags. The generated translation filename is like 'domain-tag-tag...' Add this in your happyr_translation.yml config file : project: domain: tags: [LOCALE]: - '[TAG1]' - '[TAG2]' --- src/DependencyInjection/Configuration.php | 5 +++++ src/Service/Loco.php | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 1869f6f..479a55e 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -61,6 +61,11 @@ private function getProjectNode() ->requiresAtLeastOneElement() ->prototype('scalar')->end() ->end() + ->arrayNode('tags') + ->prototype('array') + ->prototype('scalar')->end() + ->end() + ->end() ->end() ->end(); diff --git a/src/Service/Loco.php b/src/Service/Loco.php index ecd5e04..baa3f04 100644 --- a/src/Service/Loco.php +++ b/src/Service/Loco.php @@ -430,6 +430,16 @@ protected function getUrls(array &$data, array $config, $domain, $useDomainAsFil $data[$url] = $fileName; } + + foreach ($config['tags'] as $locale => $tags) { + $query = $this->getExportQueryParams($config['api_key'], $tags); + + // Build url + $url = sprintf('%sexport/locale/%s.%s?%s', self::BASE_URL, $locale, $this->filesystemService->getFileExtension(), http_build_query($query)); + $fileName = sprintf('%s.%s.%s', $domain.'-'.(implode($tags, '-')), $locale, $this->filesystemService->getFileExtension()); + + $data[$url] = $fileName; + } } /** @@ -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 From 2de6661b35f973ae90e71818c473755222209a3b Mon Sep 17 00:00:00 2001 From: yoannlecoguic Date: Wed, 26 Oct 2016 16:26:35 +0200 Subject: [PATCH 2/4] change behavior, apply tags for all locales --- src/DependencyInjection/Configuration.php | 4 +--- src/Service/Loco.php | 14 +++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 479a55e..3d70517 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -62,9 +62,7 @@ private function getProjectNode() ->prototype('scalar')->end() ->end() ->arrayNode('tags') - ->prototype('array') - ->prototype('scalar')->end() - ->end() + ->prototype('scalar')->end() ->end() ->end() ->end(); diff --git a/src/Service/Loco.php b/src/Service/Loco.php index baa3f04..aa877a9 100644 --- a/src/Service/Loco.php +++ b/src/Service/Loco.php @@ -429,16 +429,16 @@ protected function getUrls(array &$data, array $config, $domain, $useDomainAsFil $fileName = sprintf('%s.%s.%s', $domain, $locale, $this->filesystemService->getFileExtension()); $data[$url] = $fileName; - } - foreach ($config['tags'] as $locale => $tags) { - $query = $this->getExportQueryParams($config['api_key'], $tags); + if (count($config['tags']) !== 0) { + $query = $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)); - $fileName = sprintf('%s.%s.%s', $domain.'-'.(implode($tags, '-')), $locale, $this->filesystemService->getFileExtension()); + // Build url + $url = sprintf('%sexport/locale/%s.%s?%s', self::BASE_URL, $locale, $this->filesystemService->getFileExtension(), http_build_query($query)); + $fileName = sprintf('%s.%s.%s', $domain.'-'.(implode($config['tags'], '-')), $locale, $this->filesystemService->getFileExtension()); - $data[$url] = $fileName; + $data[$url] = $fileName; + } } } From 4ace8505923e124b862cb5d21153765536582ef6 Mon Sep 17 00:00:00 2001 From: yoannlecoguic Date: Fri, 28 Oct 2016 11:39:35 +0200 Subject: [PATCH 3/4] Bugs with url tags that overwrite normal urls --- src/Service/Loco.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/Loco.php b/src/Service/Loco.php index aa877a9..dacae27 100644 --- a/src/Service/Loco.php +++ b/src/Service/Loco.php @@ -431,10 +431,10 @@ protected function getUrls(array &$data, array $config, $domain, $useDomainAsFil $data[$url] = $fileName; if (count($config['tags']) !== 0) { - $query = $this->getExportQueryParams($config['api_key'], $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)); + $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()); $data[$url] = $fileName; From 42379fd0745d7eb54f6a56620ee360e7ee6e761b Mon Sep 17 00:00:00 2001 From: yoannlecoguic Date: Wed, 25 Jan 2017 12:06:34 +0100 Subject: [PATCH 4/4] Replace count !== 0 by empty --- src/Service/Loco.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/Loco.php b/src/Service/Loco.php index dacae27..ebcdf88 100644 --- a/src/Service/Loco.php +++ b/src/Service/Loco.php @@ -430,7 +430,7 @@ protected function getUrls(array &$data, array $config, $domain, $useDomainAsFil $data[$url] = $fileName; - if (count($config['tags']) !== 0) { + if (!empty($config['tags'])) { $query_tags = $this->getExportQueryParams($config['api_key'], $config['tags']); // Build url