diff --git a/.gitignore b/.gitignore index 66c56dfb..48d59988 100644 --- a/.gitignore +++ b/.gitignore @@ -49,8 +49,8 @@ coverage.xml .pytest_cache/ # Translations -*.mo -*.pot +#*.mo +#*.pot # Django stuff: *.log diff --git a/locales/notifiers.pot b/locales/notifiers.pot new file mode 100644 index 00000000..5026666f --- /dev/null +++ b/locales/notifiers.pot @@ -0,0 +1,65 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , 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 \n" +"Language-Team: LANGUAGE \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 "" + diff --git a/pyouroboros/config.py b/pyouroboros/config.py index 92286da0..aaa4a144 100644 --- a/pyouroboros/config.py +++ b/pyouroboros/config.py @@ -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 @@ -27,6 +27,7 @@ class Config(object): self_update = False label_enable = False labels_only = False + language = 'en' repo_user = None repo_pass = None diff --git a/pyouroboros/notifiers.py b/pyouroboros/notifiers.py index 7d577260..18cf2cc8 100644 --- a/pyouroboros/notifiers.py +++ b/pyouroboros/notifiers.py @@ -1,4 +1,5 @@ import apprise +import gettext from logging import getLogger from datetime import datetime, timezone @@ -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( @@ -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] diff --git a/pyouroboros/ouroboros.py b/pyouroboros/ouroboros.py index 6e53b253..765783c4 100644 --- a/pyouroboros/ouroboros.py +++ b/pyouroboros/ouroboros.py @@ -64,6 +64,9 @@ def main(): 'EXAMPLE: -N discord://1234123412341234/jasdfasdfasdfasddfasdf ' 'mailto://user:pass@gmail.com') + core_group.add_argument('-la', '--language', nargs='+', default=Config.language, dest='LANGUAGE', + help='Set the language of the translation\nDEFAULT: en') + docker_group = parser.add_argument_group("Docker", "Configuration of docker functionality") docker_group.add_argument('-m', '--monitor', nargs='+', default=Config.monitor, dest='MONITOR', help='Which container(s) to monitor\n'