Skip to content
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

[FEATURE] Translation of application texts #408

Open
wants to merge 5 commits into
base: master
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: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ coverage.xml
.pytest_cache/

# Translations
*.mo
*.pot
#*.mo
#*.pot

# Django stuff:
*.log
Expand Down
Binary file added locales/es_ES/LC_MESSAGES/notifiers.mo
Binary file not shown.
65 changes: 65 additions & 0 deletions locales/es_ES/LC_MESSAGES/notifiers.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2021-03-02 21:54+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#: pyouroboros/notifiers.py:37
msgid "Could not add notifier %s"
msgstr "No se pudo agregar el notificador %s"

#: pyouroboros/notifiers.py:44
msgid "Ouroboros has started"
msgstr "Ouroboros ha comenzado"

#: pyouroboros/notifiers.py:46
msgid "Host: %s"
msgstr "Servidor: %s"

#: pyouroboros/notifiers.py:51
msgid "%Y-%m-%d %H:%M:%S"
msgstr "%d/%m/%Y %H:%M:%S"

#: pyouroboros/notifiers.py:47
msgid "Time: %s"
msgstr "Fecha: %s"

#: pyouroboros/notifiers.py:48
msgid "Next Run: %s"
msgstr "Siguiente ejecución: %s"

#: pyouroboros/notifiers.py:50
msgid "Ouroboros has updated containers!"
msgstr "!Ouroboros ha actualizado contenedores!"

#: pyouroboros/notifiers.py:52
msgid "Host/Socket: %s / %s"
msgstr "Servidor/Socket: %s / %s"

#: pyouroboros/notifiers.py:53
msgid "Containers Monitored: %d"
msgstr "Contenedores monitorizados: %d"

#: pyouroboros/notifiers.py:54
msgid "Total Containers Updated: %d"
msgstr "Total contenedores actualizados: %d"

#: pyouroboros/notifiers.py:55
msgid "Containers updated this pass: %d"
msgstr "Contenedores actualizados en iteración: %d"

#: pyouroboros/notifiers.py:59
msgid "{} updated from {} to {}"
msgstr "{} actualizado desde {} a {}"

Binary file added locales/es_ES/LC_MESSAGES/ouroboros.mo
Binary file not shown.
53 changes: 53 additions & 0 deletions locales/es_ES/LC_MESSAGES/ouroboros.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2021-03-03 21:33+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#: pyouroboros/ouroboros.py:158
msgid "Version: %s-%s"
msgstr "Versión: %s-%s"

#: pyouroboros/ouroboros.py:161
msgid "Ouroboros configuration: %s"
msgstr "Configuración de Ouroboros: %s"

#: pyouroboros/ouroboros.py:177
msgid "Run Once container update for %s"
msgstr "Ejecutar una vez la actualización del contenedor para %s"

#: pyouroboros/ouroboros.py:180
msgid "Self Check for %s"
msgstr "Autocomprobación de %s"

#: pyouroboros/ouroboros.py:184
msgid "Cron container update for %s"
msgstr "Actualización de contenedor cron para %s"

#: pyouroboros/ouroboros.py:196
msgid "Initial run interval container update for %s"
msgstr "Actualización del contenedor del intervalo de ejecución inicial para %s"

#: pyouroboros/ouroboros.py:200
msgid "Interval container update for %s"
msgstr "Actualización de contenedor de intervalo para %s"

#: pyouroboros/ouroboros.py:204
msgid "Could not connect to socket %s. Check your config"
msgstr "No se pudo conectar al socket %s. Comprueba tu configuración"

#: pyouroboros/ouroboros.py:212
msgid "%Y-%m-%d %H:%M:%S"
msgstr "%d/%m/%Y %H:%M:%S"

65 changes: 65 additions & 0 deletions locales/notifiers.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2021-03-03 21:07+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#: pyouroboros/notifiers.py:41
msgid "Could not add notifier %s"
msgstr ""

#: pyouroboros/notifiers.py:48
msgid "Ouroboros has started"
msgstr ""

#: pyouroboros/notifiers.py:50
msgid "Host: %s"
msgstr ""

#: pyouroboros/notifiers.py:51
msgid "%Y-%m-%d %H:%M:%S"
msgstr ""

#: pyouroboros/notifiers.py:51
msgid "Time: %s"
msgstr ""

#: pyouroboros/notifiers.py:52
msgid "Next Run: %s"
msgstr ""

#: pyouroboros/notifiers.py:54
msgid "Ouroboros has updated containers!"
msgstr ""

#: pyouroboros/notifiers.py:56
msgid "Host/Socket: %s / %s"
msgstr ""

#: pyouroboros/notifiers.py:57
msgid "Containers Monitored: %d"
msgstr ""

#: pyouroboros/notifiers.py:58
msgid "Total Containers Updated: %d"
msgstr ""

#: pyouroboros/notifiers.py:59
msgid "Containers updated this pass: %d"
msgstr ""

#: pyouroboros/notifiers.py:63
msgid "{} updated from {} to {}"
msgstr ""

53 changes: 53 additions & 0 deletions locales/ouroboros.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2021-03-03 21:33+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#: pyouroboros/ouroboros.py:158
msgid "Version: %s-%s"
msgstr ""

#: pyouroboros/ouroboros.py:161
msgid "Ouroboros configuration: %s"
msgstr ""

#: pyouroboros/ouroboros.py:177
msgid "Run Once container update for %s"
msgstr ""

#: pyouroboros/ouroboros.py:180
msgid "Self Check for %s"
msgstr ""

#: pyouroboros/ouroboros.py:184
msgid "Cron container update for %s"
msgstr ""

#: pyouroboros/ouroboros.py:196
msgid "Initial run interval container update for %s"
msgstr ""

#: pyouroboros/ouroboros.py:200
msgid "Interval container update for %s"
msgstr ""

#: pyouroboros/ouroboros.py:204
msgid "Could not connect to socket %s. Check your config"
msgstr ""

#: pyouroboros/ouroboros.py:212
msgid "%Y-%m-%d %H:%M:%S"
msgstr ""

3 changes: 2 additions & 1 deletion pyouroboros/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Config(object):
'PROMETHEUS_PORT', 'NOTIFIERS', 'REPO_USER', 'REPO_PASS', 'CLEANUP', 'RUN_ONCE', 'CRON',
'INFLUX_URL', 'INFLUX_PORT', 'INFLUX_USERNAME', 'INFLUX_PASSWORD', 'INFLUX_DATABASE', 'INFLUX_SSL',
'INFLUX_VERIFY_SSL', 'DATA_EXPORT', 'SELF_UPDATE', 'LABEL_ENABLE', 'DOCKER_TLS', 'LABELS_ONLY',
'DRY_RUN', 'HOSTNAME', 'DOCKER_TLS_VERIFY', 'SWARM', 'SKIP_STARTUP_NOTIFICATIONS']
'DRY_RUN', 'HOSTNAME', 'DOCKER_TLS_VERIFY', 'SWARM', 'SKIP_STARTUP_NOTIFICATIONS', 'LANGUAGE']

hostname = environ.get('HOSTNAME')
interval = 300
Expand All @@ -27,6 +27,7 @@ class Config(object):
self_update = False
label_enable = False
labels_only = False
language = 'en'

repo_user = None
repo_pass = None
Expand Down
34 changes: 22 additions & 12 deletions pyouroboros/notifiers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import apprise
import gettext

from logging import getLogger
from datetime import datetime, timezone
Expand All @@ -11,6 +12,15 @@ def __init__(self, config, data_manager):
self.logger = getLogger()

self.apprise = self.build_apprise()
self._ = None

try:
language = gettext.translation('notifiers', localedir='locales', languages=self.config.language)
language.install()
self._ = language.gettext
except FileNotFoundError:
self.logger.error("Can't find the '%s' language", self.config.language)
self._ = gettext.gettext

def build_apprise(self):
asset = apprise.AppriseAsset(
Expand All @@ -28,29 +38,29 @@ def build_apprise(self):
for notifier in self.config.notifiers:
add = apprise_obj.add(notifier)
if not add:
self.logger.error('Could not add notifier %s', notifier)
self.logger.error(_('Could not add notifier %s'), notifier)

return apprise_obj

def send(self, container_tuples=None, socket=None, kind='update', next_run=None, mode='container'):
if kind == 'startup':
now = datetime.now(timezone.utc).astimezone()
title = f'Ouroboros has started'
now = datetime.now(timezone.utc).astimezone()
title = _('Ouroboros has started')
body_fields = [
f'Host: {self.config.hostname}',
f'Time: {now.strftime("%Y-%m-%d %H:%M:%S")}',
f'Next Run: {next_run}']
_('Host: %s') % self.config.hostname,
_('Time: %s') % now.strftime(_("%Y-%m-%d %H:%M:%S")),
_('Next Run: %s') % next_run]
else:
title = 'Ouroboros has updated containers!'
title = _('Ouroboros has updated containers!')
body_fields = [
f"Host/Socket: {self.config.hostname} / {socket.split('//')[1]}",
f"Containers Monitored: {self.data_manager.monitored_containers[socket]}",
f"Total Containers Updated: {self.data_manager.total_updated[socket]}",
f"Containers updated this pass: {len(container_tuples)}"
_('Host/Socket: %s / %s') % (self.config.hostname, socket.split('//')[1]),
_('Containers Monitored: %d') % self.data_manager.monitored_containers[socket],
_('Total Containers Updated: %d') % self.data_manager.total_updated[socket],
_('Containers updated this pass: %d') % len(container_tuples)
]
body_fields.extend(
[
"{} updated from {} to {}".format(
_("{} updated from {} to {}").format(
container.name,
old_image if mode == 'service' else old_image.short_id.split(':')[1],
new_image.short_id.split(':')[1]
Expand Down
Loading