Skip to content

Commit

Permalink
Merge pull request #74 from einorler/issue65
Browse files Browse the repository at this point in the history
made list of locales formations from configuration
  • Loading branch information
saimaz committed Apr 4, 2016
2 parents 229d160 + 7b700df commit 5190dc9
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
if ($bundleName) {
$this->output->writeln("<info>*** Importing {$bundleName} translation files ***</info>");
$bundle = $this->getApplication()->getKernel()->getBundle($bundleName);
$bundle = $this->getContainer()->get('kernel')->getBundle($bundleName);
$import->importBundlesTranslationFiles([$bundle], true);
} else {
$this->output->writeln('<info>*** Importing application translation files ***</info>');
Expand Down
13 changes: 3 additions & 10 deletions Controller/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,12 @@ public function listAction(Request $request)
*/
private function buildLocalesList($filter)
{
$search = $this->repository->createSearch();

$localeAgg = new TermsAggregation('locale_agg');
$localeAgg->setField('messages.locale');
$search->addAggregation($localeAgg);
$result = $this->repository->execute($search, Result::RESULTS_RAW);
$locales = $this->container->getParameter('ongr_translations.managed_locales');
$list = [];

foreach ($result['aggregations']['agg_locale_agg']['buckets'] as $value) {
$list[$value['key']] = true;
foreach ($locales as $locale) {
$list[$locale] = true;
}
ksort($list);

$activeLocales = [];

if ($filter->getState()->isActive()) {
Expand Down
2 changes: 1 addition & 1 deletion Document/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace ONGR\TranslationsBundle\Document;

use ONGR\ElasticsearchBundle\Annotation as ES;
use ONGR\ElasticsearchBundle\Collection;
use ONGR\ElasticsearchBundle\Collection\Collection;

/**
* Holds translations for certain domain.
Expand Down
16 changes: 8 additions & 8 deletions Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
ongr_translations_list_page:
pattern: /list
path: /list
methods: [GET]
defaults:
_controller: ongr_translations.controller.list:listAction

ongr_translations_api_edit:
pattern: /_api/edit
path: /_api/edit
methods: [POST]
defaults:
_controller: ONGRTranslationsBundle:Api:edit
options:
expose: true

ongr_translations_api_delete:
pattern: /_api/delete
path: /_api/delete
methods: [POST]
defaults:
_controller: ONGRTranslationsBundle:Api:delete
options:
expose: true

ongr_translations_api_add:
pattern: /_api/add
path: /_api/add
methods: [POST]
defaults:
_controller: ONGRTranslationsBundle:Api:add
options:
expose: true

ongr_translations_api_get:
pattern: /_api/get
path: /_api/get
methods: [POST]
defaults:
_controller: ONGRTranslationsBundle:Api:get
options:
expose: true

ongr_translations_api_check:
pattern: /_api/check
path: /_api/check
methods: [POST]
defaults:
_controller: ONGRTranslationsBundle:Api:check
options:
expose: true

ongr_translations_api_export:
pattern: /_api/export
path: /_api/export
methods: [POST]
defaults:
_controller: ONGRTranslationsBundle:Api:export
options:
expose: true

ongr_translations_api_history:
pattern: /_api/history
path: /_api/history
methods: [POST]
defaults:
_controller: ONGRTranslationsBundle:Api:history
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Command/ImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase;
use ONGR\TranslationsBundle\Command\ImportCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

/**
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use ONGR\ElasticsearchBundle\Result\Result;
use ONGR\ElasticsearchDSL\Query\BoolQuery;
use ONGR\ElasticsearchDSL\Filter\TermFilter;
use ONGR\ElasticsearchDSL\Query\TermQuery;
use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase;
use ONGR\TranslationsBundle\Document\History;
use ONGR\TranslationsBundle\Document\Message;
Expand Down Expand Up @@ -371,9 +371,9 @@ public function testHistoryAction()
$manager = $this->getManager();
$repository = $manager->getRepository('ONGRTranslationsBundle:History');
$boolFilter = new BoolQuery();
$boolFilter->add(new TermFilter('key', 'foo'));
$boolFilter->add(new TermFilter('domain', 'barbar'));
$boolFilter->add(new TermFilter('locale', 'en'));
$boolFilter->add(new TermQuery('key', 'foo'));
$boolFilter->add(new TermQuery('domain', 'barbar'));
$boolFilter->add(new TermQuery('locale', 'en'));
$search = $repository->createSearch()->addFilter($boolFilter);

$results = $repository->execute($search, Result::RESULTS_ARRAY);
Expand Down
1 change: 0 additions & 1 deletion Translation/Export/YmlExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function export($file, $translations)

if (pathinfo($file, PATHINFO_EXTENSION) === 'yml') {
$ymlDumper = new Dumper();
$ymlDumper->setIndentation(0);
$ymlContent = '';
$ymlContent .= $ymlDumper->dump($translations, 10);
$bytes = file_put_contents($file, $ymlContent);
Expand Down
8 changes: 4 additions & 4 deletions Translation/HistoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace ONGR\TranslationsBundle\Translation;

use ONGR\ElasticsearchBundle\Result\Result;
use ONGR\ElasticsearchDSL\Filter\TermFilter;
use ONGR\ElasticsearchDSL\Query\TermQuery;
use ONGR\ElasticsearchDSL\Sort\FieldSort;
use ONGR\ElasticsearchBundle\Service\Repository;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -43,9 +43,9 @@ public function history(Request $request)
$content = $this->parseJsonContent($request);

$search = $this->repository->createSearch();
$search->addFilter(new TermFilter('key', $content['key']));
$search->addFilter(new TermFilter('domain', $content['domain']));
$search->addFilter(new TermFilter('locale', $content['locale']));
$search->addFilter(new TermQuery('key', $content['key']));
$search->addFilter(new TermQuery('domain', $content['domain']));
$search->addFilter(new TermQuery('locale', $content['locale']));
$search->addSort(new FieldSort('created_at', FieldSort::DESC));

return $this->repository->execute($search, Result::RESULTS_ARRAY);
Expand Down

0 comments on commit 5190dc9

Please sign in to comment.