Skip to content

Commit 768fa6b

Browse files
committed
Add missing translation filter.
1 parent 931ad51 commit 768fa6b

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

Filter/MissingLocaleFilter.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the ONGR package.
5+
*
6+
* (c) NFQ Technologies UAB <info@nfq.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace ONGR\TranslationsBundle\Filter;
13+
14+
use ONGR\ElasticsearchBundle\DSL\Filter\TermsFilter;
15+
use ONGR\ElasticsearchBundle\DSL\Search;
16+
use ONGR\FilterManagerBundle\Filters\FilterState;
17+
use ONGR\FilterManagerBundle\Filters\Widget\Choice\MultiTermChoice;
18+
use ONGR\FilterManagerBundle\Search\SearchRequest;
19+
20+
/**
21+
* Filter to show only missing locales.
22+
*/
23+
class MissingLocaleFilter extends MultiTermChoice
24+
{
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null)
29+
{
30+
if ($state && $state->isActive()) {
31+
$search->addPostFilter(
32+
new TermsFilter($this->getField(), $state->getValue(), ['execution' => 'and']),
33+
'must_not'
34+
);
35+
}
36+
}
37+
}

Resources/config/filters_container.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ parameters:
5555
ongr_translations.filter.locale.class: ONGR\TranslationsBundle\Filter\LocaleFilter
5656
ongr_translations.filter.locale.request_field: locale
5757
ongr_translations.filter.locale.field: locale
58+
59+
ongr_translations.filter.missing_locale.class: ONGR\TranslationsBundle\Filter\MissingLocaleFilter
60+
ongr_translations.filter.missing_locale.request_field: missing_locale
61+
ongr_translations.filter.missing_locale.field: locale
5862

5963
ongr_translations.filter.tag.class: ONGR\FilterManagerBundle\Filters\Widget\Choice\SingleTermChoice
6064
ongr_translations.filter.tag.request_field: tag
@@ -112,6 +116,14 @@ services:
112116
tags:
113117
- { name: ongr_filter_manager.filter, filter_name: locale }
114118

119+
ongr_translations.filter.missing_locale:
120+
class: "%ongr_translations.filter.missing_locale.class%"
121+
calls:
122+
- ["setRequestField", ["%ongr_translations.filter.missing_locale.request_field%"]]
123+
- ["setField", ["%ongr_translations.filter.missing_locale.field%"]]
124+
tags:
125+
- { name: ongr_filter_manager.filter, filter_name: missing_locale }
126+
115127

116128
ongr_translations.filters_container:
117129
class: "%ongr_translations.filters_container.class%"
@@ -121,5 +133,6 @@ services:
121133
- ["set", ["search", "@ongr_translations.filter.match_search"]]
122134
- ["set", ["domain", "@ongr_translations.filter.single_term.domain"]]
123135
- ["set", ["locale", "@ongr_translations.filter.locale"]]
136+
- ["set", ["missing_locale", "@ongr_translations.filter.missing_locale"]]
124137
- ["set", ["tag", "@ongr_translations.filter.tag"]]
125138
- ["set", ["status", "@ongr_translations.filter.status"]]

Resources/translations/ONGRTranslations.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ placeholder.search_for: 'Search for...'
1313
save: Save
1414
close: Close
1515
filter.locale: Locale
16+
filter.missing_locale: Missing translations
1617
filter.domain: Domain
1718
filter.sort: Sort
1819
filter.clear: Clear

Resources/translations/ONGRTranslations.lt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ placeholder.search_for: Ieškoti...
1313
save: Saugoti
1414
close: Uždaryti
1515
filter.locale: Localė
16+
filter.missing_locale: Neišverstos
1617
filter.domain: Domenas
1718
filter.sort: Rikiavimas
1819
filter.clear: Atšaukti

Resources/views/layout.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
{{ filter_macros.dropdown(filters_manager.filters.status, true) }}
3636
{{ filter_macros.dropdown(filters_manager.filters.tag, true) }}
3737
{{ filter_macros.dropdown(filters_manager.filters.locale, true) }}
38+
{{ filter_macros.dropdown(filters_manager.filters.missing_locale, true) }}
3839
{{ filter_macros.dropdown(filters_manager.filters.domain, true) }}
3940
{{ filter_macros.dropdown(filters_manager.filters.sort, false) }}
4041
{% endblock %}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"require": {
1414
"symfony/symfony": "~2.6",
15-
"ongr/elasticsearch-bundle": "~0.9",
15+
"ongr/elasticsearch-bundle": "^0.9.2",
1616
"ongr/filter-manager-bundle": "~0.4",
1717
"friendsofsymfony/jsrouting-bundle": "~1.5"
1818
},

0 commit comments

Comments
 (0)