Skip to content

Allow filter-out some translatable strings #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions rosetta/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@
# 'translators` group, create individual per-language groups, e.g.
# 'translators-de', 'translators-fr', ...
ROSETTA_LANGUAGE_GROUPS = getattr(settings, 'ROSETTA_LANGUAGE_GROUPS', False)

# Custom filter to filter-out some strings
# Set to function accepting request and list of PO file lines
TRANSLATIONS_FILTER = getattr(settings, 'ROSETTA_TRANSLATIONS_FILTER', None)
15 changes: 10 additions & 5 deletions rosetta/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,21 @@ def fix_nls(in_, out_):
if 'query' in request.REQUEST and request.REQUEST.get('query', '').strip():
query = request.REQUEST.get('query').strip()
rx = re.compile(re.escape(query), re.IGNORECASE)
paginator = Paginator([e for e in rosetta_i18n_pofile if not e.obsolete and rx.search(six.text_type(e.msgstr) + six.text_type(e.msgid) + u''.join([o[0] for o in e.occurrences]))], rosetta_settings.MESSAGES_PER_PAGE)
strings = [e for e in rosetta_i18n_pofile if not e.obsolete and rx.search(six.text_type(e.msgstr) + six.text_type(e.msgid) + u''.join([o[0] for o in e.occurrences]))]
else:
if rosetta_i18n_filter == 'untranslated':
paginator = Paginator(rosetta_i18n_pofile.untranslated_entries(), rosetta_settings.MESSAGES_PER_PAGE)
strings = rosetta_i18n_pofile.untranslated_entries()
elif rosetta_i18n_filter == 'translated':
paginator = Paginator(rosetta_i18n_pofile.translated_entries(), rosetta_settings.MESSAGES_PER_PAGE)
strings = rosetta_i18n_pofile.translated_entries()
elif rosetta_i18n_filter == 'fuzzy':
paginator = Paginator([e for e in rosetta_i18n_pofile.fuzzy_entries() if not e.obsolete], rosetta_settings.MESSAGES_PER_PAGE)
strings = [e for e in rosetta_i18n_pofile.fuzzy_entries() if not e.obsolete]
else:
paginator = Paginator([e for e in rosetta_i18n_pofile if not e.obsolete], rosetta_settings.MESSAGES_PER_PAGE)
strings = [e for e in rosetta_i18n_pofile if not e.obsolete]

if rosetta_settings.TRANSLATIONS_FILTER:
strings = rosetta_settings.TRANSLATIONS_FILTER(request, strings)

paginator = Paginator(strings, rosetta_settings.MESSAGES_PER_PAGE)

if 'page' in request.GET and int(request.GET.get('page')) <= paginator.num_pages and int(request.GET.get('page')) > 0:
page = int(request.GET.get('page'))
Expand Down