diff --git a/Makefile b/Makefile index c01f28c09cf5705070a3f059c9be758b48cb2d3b..6094327bf8d39eddf2fbf2dbaa67893ec1a324aa 100644 --- a/Makefile +++ b/Makefile @@ -512,9 +512,9 @@ mpybabel-update: FORCE mpybabel-compile: FORCE @echo "\n$(GREEN)*** Compiling translations for Mentat ***$(NC)\n" - @$(PYBABEL) compile -d $(DIR_TEMPLATES_INFORMANT)/translations - @$(PYBABEL) compile -d $(DIR_TEMPLATES_REPORTER)/translations - @$(PYBABEL) compile -d $(DIR_TEMPLATES_UTEST)/translations + @$(PYBABEL) compile -d $(DIR_TEMPLATES_INFORMANT)/translations --statistics + @$(PYBABEL) compile -d $(DIR_TEMPLATES_REPORTER)/translations --statistics + @$(PYBABEL) compile -d $(DIR_TEMPLATES_UTEST)/translations --statistics # # Compile all available translations. diff --git a/conf/templates/informant/_labels.j2 b/conf/templates/informant/_labels.j2 new file mode 100644 index 0000000000000000000000000000000000000000..e952eb06d10d29a8a65cdd738ba92cb66534f354 --- /dev/null +++ b/conf/templates/informant/_labels.j2 @@ -0,0 +1,36 @@ +{#- + + This helper macro is responsible for rendering section label for each report + section. + +-#} +{%- macro section_label_evt(key) -%} +{%- + set labels = { + 'ips': _('Number of processed events per source IP'), + 'categories': _('Number of processed events per category'), + 'detectors': _('Number of processed events per detector'), + 'analyzers': _('Number of processed events per analyzer'), + 'abuses': _('Number of processed events per abuse group'), + 'asns': _('Number of processed events per autonomous system'), + 'countries': _('Number of processed events per source country') + } +-%} +{{ labels[key] }} +{%- endmacro -%} + +{%- macro section_label_rep(key) -%} +{%- + set labels = { + 'emails': _('Number of sent email reports'), + 'ips': _('Number of reported events per source IP'), + 'categories': _('Number of reported events per category'), + 'detectors': _('Number of reported events per detector'), + 'analyzers': _('Number of reported events per analyzer'), + 'abuses': _('Number of reported events per abuse group'), + 'asns': _('Number of reported events per autonomous system'), + 'countries': _('Number of reported events per source country') + } +-%} +{{ labels[key] }} +{%- endmacro -%} diff --git a/conf/templates/informant/default.html.j2 b/conf/templates/informant/default.html.j2 index 5acbdaf275b8b8bf494b7076ac8af56da36a370d..dc7b491ab9f0516a10767edf32d376ef25846680 100644 --- a/conf/templates/informant/default.html.j2 +++ b/conf/templates/informant/default.html.j2 @@ -6,6 +6,8 @@ Author: Jan Mach <jan.mach@cesnet.cz> #} +{%- import '_labels.j2' as report_labels -%} + {%- macro render_stats_table(chstats, chsection) %} {%- if chsection in chstats %} {%- set chdata = chstats[chsection] %} @@ -98,7 +100,9 @@ <ol type="1"> {%- for chsection in ('ips', 'categories', 'detectors', 'analyzers', 'abuses', 'asns', 'countries') %} <li> - <a href="#section-A-{{ loop.index }}">{{ _('Number of processed events per') }} <strong>{{ format_section_name(chsection) }}</strong></a> + <a href="#section-A-{{ loop.index }}"> + {{ report_labels.section_label_evt(chsection) }} + </a> </li> {%- endfor %} </ol> @@ -106,9 +110,11 @@ <li> <a href="#section-B">{{ _('Event reporting statistics') }}</a> <ol type="1"> -{%- for chsection in ('ips', 'categories', 'detectors', 'analyzers', 'abuses', 'asns', 'countries') %} +{%- for chsection in ('emails', ips', 'categories', 'detectors', 'analyzers', 'abuses', 'asns', 'countries') %} <li> - <a href="#section-A-{{ loop.index }}">{{ _('Number of reported events per') }} <strong>{{ format_section_name(chsection) }}</strong></a> + <a href="#section-A-{{ loop.index }}"> + {{ report_labels.section_label_rep(chsection) }} + </a> </li> {%- endfor %} </ol> @@ -121,7 +127,9 @@ {%- for chsection in ('ips', 'categories', 'detectors', 'analyzers', 'abuses', 'asns', 'countries') %} <h3> - <a name="section-A-{{ loop.index }}">{{ 'A.{:d}'.format(loop.index) }} {{ _('Number of processed events per') }} <strong>{{ format_section_name(chsection) }}</strong></a> + <a name="section-A-{{ loop.index }}"> + {{ 'A.{:d}'.format(loop.index) }} {{ report_labels.section_label_evt(chsection) }} + </a> </h3> {{ render_stats_table( @@ -137,7 +145,9 @@ {%- for chsection in ('emails', 'ips', 'categories', 'detectors', 'analyzers', 'abuses', 'asns', 'countries') %} <h3> - <a name="section-B-{{ loop.index }}">{{ 'B.{:d}'.format(loop.index) }} {{ _('Number of reported events per') }} <strong>{{ format_section_name(chsection) }}</strong></a> + <a name="section-B-{{ loop.index }}"> + {{ 'B.{:d}'.format(loop.index) }} {{ report_labels.section_label_rep(chsection) }} + </a> </h3> {{ render_stats_table( diff --git a/conf/templates/informant/default.txt.j2 b/conf/templates/informant/default.txt.j2 index c07d5e07728a0252bc2950e7af93fcd9d43b3922..a0bb900773321a79433a840a52e20b8999edb1aa 100644 --- a/conf/templates/informant/default.txt.j2 +++ b/conf/templates/informant/default.txt.j2 @@ -6,6 +6,8 @@ Author: Jan Mach <jan.mach@cesnet.cz> #} +{%- import '_labels.j2' as report_labels -%} + {%- macro render_stats_table(chstats, chsection) %} {%- if chsection in chstats %} {%- set chdata = chstats[chsection] %} @@ -37,11 +39,11 @@ {{ '{}'.format('=' * 90) }} A. {{ _('Event processing statistics') }} {%- for chsection in ('ips', 'categories', 'detectors', 'analyzers', 'abuses', 'asns', 'countries') %} -{{ 'A.{:d}'.format(loop.index) }} {{ _('Number of processed events per') }} '{{ format_section_name(chsection) }}': +{{ 'A.{:d}'.format(loop.index) }} {{ report_labels.section_label_evt(chsection) }}: {%- endfor %} B. {{ _('Event reporting statistics') }} -{%- for chsection in ('ips', 'categories', 'detectors', 'analyzers', 'abuses', 'asns', 'countries') %} -{{ 'B.{:d}'.format(loop.index) }} {{ _('Number of reported events per') }} '{{ format_section_name(chsection) }}': +{%- for chsection in ('emails', 'ips', 'categories', 'detectors', 'analyzers', 'abuses', 'asns', 'countries') %} +{{ 'B.{:d}'.format(loop.index) }} {{ report_labels.section_label_rep(chsection) }}: {%- endfor %} @@ -49,7 +51,7 @@ A. {{ _('Event processing statistics') }} {{ '{}'.format('=' * 90) }} {%- for chsection in ('ips', 'categories', 'detectors', 'analyzers', 'abuses', 'asns', 'countries') %} -{{ '[A.{:d}]'.format(loop.index) }} {{ _('Number of processed events per') }} '{{ format_section_name(chsection) }}' +{{ '[A.{:d}]'.format(loop.index) }} {{ report_labels.section_label_evt(chsection) }} {{ render_stats_table( stats_events['stats_overall'], @@ -62,7 +64,7 @@ A. {{ _('Event reporting statistics') }} {{ '{}'.format('=' * 90) }} {%- for chsection in ('emails', 'ips', 'categories', 'detectors', 'analyzers', 'abuses', 'asns', 'countries') %} -{{ '[A.{:d}]'.format(loop.index) }} {{ _('Number of reported events per') }} '{{ format_section_name(chsection) }}' +{{ '[A.{:d}]'.format(loop.index) }} {{ report_labels.section_label_rep(chsection) }} {{ render_stats_table( stats_reports, diff --git a/conf/templates/informant/translations/cs/LC_MESSAGES/messages.po b/conf/templates/informant/translations/cs/LC_MESSAGES/messages.po index ce244f27ef860164304031c4d8b321d7098fb699..3b0fca5d56a04a4890403b7f7aea25ccf3c5863f 100644 --- a/conf/templates/informant/translations/cs/LC_MESSAGES/messages.po +++ b/conf/templates/informant/translations/cs/LC_MESSAGES/messages.po @@ -3,7 +3,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2019-05-22 11:34+0200\n" +"POT-Creation-Date: 2019-05-23 11:43+0200\n" "PO-Revision-Date: 2017-09-22 15:33+0200\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language: cs\n" @@ -14,6 +14,51 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.6.0\n" +msgid "Number of processed events per source IP" +msgstr "PoÄŤet zpracovanĂ˝ch událostĂ dle zdrojovĂ© IP" + +msgid "Number of processed events per category" +msgstr "PoÄŤet zpracovanĂ˝ch událostĂ dle kategorie" + +msgid "Number of processed events per detector" +msgstr "PoÄŤet zpracovanĂ˝ch událostĂ dle detektoru" + +msgid "Number of processed events per analyzer" +msgstr "PoÄŤet zpracovanĂ˝ch událostĂ dle analyzátoru" + +msgid "Number of processed events per abuse group" +msgstr "PoÄŤet zpracovanĂ˝ch událostĂ dle abuse skupiny" + +msgid "Number of processed events per autonomous system" +msgstr "PoÄŤet zpracovanĂ˝ch událostĂ dle autonomnĂho systĂ©mu" + +msgid "Number of processed events per source country" +msgstr "PoÄŤet zpracovanĂ˝ch událostĂ dle zemÄ› pĹŻvodu" + +msgid "Number of sent email reports" +msgstr "PoÄŤet odeslanĂ˝ch reportĹŻ emailem" + +msgid "Number of reported events per source IP" +msgstr "PoÄŤet reportovanĂ˝ch událostĂ dle zdrojovĂ© IP" + +msgid "Number of reported events per category" +msgstr "PoÄŤet reportovanĂ˝ch událostĂ dle kategorie" + +msgid "Number of reported events per detector" +msgstr "PoÄŤet reportovanĂ˝ch událostĂ dle detektoru" + +msgid "Number of reported events per analyzer" +msgstr "PoÄŤet reportovanĂ˝ch událostĂ dle analyzátoru" + +msgid "Number of reported events per abuse group" +msgstr "PoÄŤet reportovanĂ˝ch událostĂ dle abuse skupiny" + +msgid "Number of reported events per autonomous system" +msgstr "PoÄŤet reportovanĂ˝ch událostĂ dle autonomnĂho systĂ©mu" + +msgid "Number of reported events per source country" +msgstr "PoÄŤet reportovanĂ˝ch událostĂ dle zemÄ› pĹŻvodu" + msgid "No data" msgstr "Žádná data" @@ -44,15 +89,9 @@ msgstr "Obsah" msgid "Event processing statistics" msgstr "Statistiky zpracovánĂ událostĂ" -msgid "Number of processed events per" -msgstr "PoÄŤet zpracovanĂ˝ch událostĂ dle" - msgid "Event reporting statistics" msgstr "Statistiky reportovánĂ událostĂ" -msgid "Number of reported events per" -msgstr "PoÄŤet reportovanĂ˝ch událostĂ dle" - msgid "Have a nice day" msgstr "HezkĂ˝ den pĹ™eje" @@ -140,27 +179,6 @@ msgstr "základnĂ" msgid "advanced" msgstr "pokroÄŤilĂ©" -msgid "source IP" -msgstr "zdrojovĂ© IP" - -msgid "category" -msgstr "kategorie" - -msgid "detector" -msgstr "detektoru" - -msgid "abuse group" -msgstr "abuse skupiny" - -msgid "analyzer" -msgstr "analyzátoru" - -msgid "autonomous system" -msgstr "autonomnĂho systĂ©mu" - -msgid "source country" -msgstr "zemÄ› pĹŻvodu" - msgid "Periodical statistical summary report" msgstr "PravidelnĂ˝ statistickĂ˝ souhrnnĂ˝ report" diff --git a/conf/templates/reporter/translations/cs/LC_MESSAGES/messages.po b/conf/templates/reporter/translations/cs/LC_MESSAGES/messages.po index a8897d4e2a916ca1573f5ae1972bbb99018dbdb2..00a7eda9782791d358455382df694528382c6291 100644 --- a/conf/templates/reporter/translations/cs/LC_MESSAGES/messages.po +++ b/conf/templates/reporter/translations/cs/LC_MESSAGES/messages.po @@ -3,7 +3,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2019-05-22 11:35+0200\n" +"POT-Creation-Date: 2019-05-23 11:43+0200\n" "PO-Revision-Date: 2017-09-22 15:33+0200\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language: cs\n" diff --git a/conf/templates/utest/translations/cs/LC_MESSAGES/messages.po b/conf/templates/utest/translations/cs/LC_MESSAGES/messages.po index fd5f5f99ad3d9e1acdbfb9b6c9ab049213b2dfa0..e860153f7f35930f325b256c166b6ca1d3601cc2 100644 --- a/conf/templates/utest/translations/cs/LC_MESSAGES/messages.po +++ b/conf/templates/utest/translations/cs/LC_MESSAGES/messages.po @@ -3,7 +3,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2019-05-22 11:35+0200\n" +"POT-Creation-Date: 2019-05-23 11:43+0200\n" "PO-Revision-Date: 2017-09-22 15:33+0200\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language: cs\n" diff --git a/lib/mentat/reports/overview.py b/lib/mentat/reports/overview.py index 60a30df88cd339a32884a376edefdaf90c39ad89..41ad4ac67c2a8b5cd50b5d2b083c5e9efa243cdf 100644 --- a/lib/mentat/reports/overview.py +++ b/lib/mentat/reports/overview.py @@ -34,17 +34,6 @@ from mentat.emails.informant import ReportEmail from mentat.reports.base import BaseReporter -REPORT_SECTION_NAMES = { - 'ips': tr_('source IP'), - 'categories': tr_('category'), - 'detectors': tr_('detector'), - 'abuses': tr_('abuse group'), - 'analyzers': tr_('analyzer'), - 'asns': tr_('autonomous system'), - 'countries': tr_('source country') -} -"""Dictionary for translating section identifiers to section names.""" - REPORT_SUBJECT = tr_("Periodical statistical summary report") """Subject for report emails.""" @@ -70,8 +59,7 @@ class OverviewReporter(BaseReporter): """ renderer = super()._setup_renderer(templates_dir) - renderer.globals['format_section_key'] = lambda x,y: self.format_section_key(x,y) - renderer.globals['format_section_name'] = lambda x: self.format_section_name(x) + renderer.globals['format_section_key'] = self.format_section_key return renderer @@ -89,13 +77,6 @@ class OverviewReporter(BaseReporter): return 'AS {}'.format(key) return key - def format_section_name(self, section): - """ - Simple wrapper around :py:func:babel.dates.format_datetime` function - that takes care of figuring out the appropriate locale. - """ - return self.translator.gettext(REPORT_SECTION_NAMES.get(section, section)) - #---------------------------------------------------------------------------