# Path: weechat/common/i18n.py
# def i18n_autogen(app, name, strings):
#     """Create a file '_i18n_xxx.py' with strings to translate."""
#     # build content of file
#     content = [
#         '# This file is auto-generated after changes in database, '
#         'DO NOT EDIT!',
#         '',
#         f'"""Translations for {app}/{name}."""',
#         '',
#         '# flake8: noqa',
#         '# pylint: disable=line-too-long,too-many-statements',
#     ]
#     if strings:
#         content += [
#             '',
#             'from django.utils.translation import gettext_noop',
#             '',
#             '',
#             f'def __i18n_{app}_{name}():',
#             f'    """Translations for {app}/{name}."""',
#         ]
#         done = set()
#         for string in sorted(strings):
#             if isinstance(string, tuple):
#                 # if type is tuple of 2 strings: use the second as note for
#                 # translators
#                 (message, translators) = (string[0], string[1])
#             else:
#                 # single string (no note for translators)
#                 (message, translators) = (string, None)
#             # add string if not already done
#             if message not in done:
#                 if translators:
#                     content.append(f'    # Translators: {translators}')
#                 message = (message
#                            .replace('\\', '\\\\')
#                            .replace('"', '\\"')
#                            .replace('\r\n', '\\n'))
#                 content.append(f'    gettext_noop("{message}")')
#                 done.add(message)
#     content.append('')
#     # write file
#     filename = project_path_join(app, f'_i18n_{name}.py')
#     with open(filename, 'w', encoding='utf-8') as _file:
#         data = '\n'.join(content)
#         if hasattr(data, 'decode') and isinstance(data, str):
#             data = data.decode('utf-8')
#         _file.write(data)
# 
# Path: weechat/common/templatetags/localdate.py
# @register.filter()
# def localdate(value, fmt='date'):
#     """
#     Format date with localized date/time format.
#     If fmt == "date", the localized date format is used.
#     If fmt == "datetime", the localized date/fime format is used.
#     Another fmt it is used as-is.
#     """
#     if fmt == 'date':
#         fmt = gettext(settings.DATE_FORMAT)
#     elif fmt == 'datetime':
#         fmt = gettext(settings.DATETIME_FORMAT)
#     date_iso = value.isoformat()
#     date_fmt = dateformat.format(value, fmt)
#     return mark_safe(f'<time datetime="{date_iso}">{date_fmt}</time>')


from django.db import models
from django.db.models.signals import post_save
from django.utils.translation import gettext, gettext_lazy
from weechat.common.i18n import i18n_autogen
from weechat.common.templatetags.localdate import localdate
    class Meta:
        """Meta class for ScreenShot."""
        ordering = ['priority']


class Keydate(models.Model):
    """A WeeChat key date."""
    date = models.DateField()
    version = models.TextField(max_length=32)
    text = models.TextField()

    def __str__(self):
        str_version = f'{self.version}: ' if self.version else ''
        return f'{self.date} - {str_version}{self.text}'

    def text_i18n(self):
        """Return translated key date."""
        return gettext(self.text.replace('\r\n', '\n'))

    class Meta:
        """Meta class for KeyDate."""
        ordering = ['-date']


def handler_keydate_saved(sender, **kwargs):
    """Write file _i18n_keydates.py with key dates to translate."""
    # pylint: disable=unused-argument
    strings = []
    for keydate in Keydate.objects.order_by('-date'):
        strings.append(keydate.text)

# Path: weechat/common/i18n.py
# def i18n_autogen(app, name, strings):
#     """Create a file '_i18n_xxx.py' with strings to translate."""
#     # build content of file
#     content = [
#         '# This file is auto-generated after changes in database, '
#         'DO NOT EDIT!',
#         '',
#         f'"""Translations for {app}/{name}."""',
#         '',
#         '# flake8: noqa',
#         '# pylint: disable=line-too-long,too-many-statements',
#     ]
#     if strings:
#         content += [
#             '',
#             'from django.utils.translation import gettext_noop',
#             '',
#             '',
#             f'def __i18n_{app}_{name}():',
#             f'    """Translations for {app}/{name}."""',
#         ]
#         done = set()
#         for string in sorted(strings):
#             if isinstance(string, tuple):
#                 # if type is tuple of 2 strings: use the second as note for
#                 # translators
#                 (message, translators) = (string[0], string[1])
#             else:
#                 # single string (no note for translators)
#                 (message, translators) = (string, None)
#             # add string if not already done
#             if message not in done:
#                 if translators:
#                     content.append(f'    # Translators: {translators}')
#                 message = (message
#                            .replace('\\', '\\\\')
#                            .replace('"', '\\"')
#                            .replace('\r\n', '\\n'))
#                 content.append(f'    gettext_noop("{message}")')
#                 done.add(message)
#     content.append('')
#     # write file
#     filename = project_path_join(app, f'_i18n_{name}.py')
#     with open(filename, 'w', encoding='utf-8') as _file:
#         data = '\n'.join(content)
#         if hasattr(data, 'decode') and isinstance(data, str):
#             data = data.decode('utf-8')
#         _file.write(data)
# 
# Path: weechat/common/templatetags/localdate.py
# @register.filter()
# def localdate(value, fmt='date'):
#     """
#     Format date with localized date/time format.
#     If fmt == "date", the localized date format is used.
#     If fmt == "datetime", the localized date/fime format is used.
#     Another fmt it is used as-is.
#     """
#     if fmt == 'date':
#         fmt = gettext(settings.DATE_FORMAT)
#     elif fmt == 'datetime':
#         fmt = gettext(settings.DATETIME_FORMAT)
#     date_iso = value.isoformat()
#     date_fmt = dateformat.format(value, fmt)
#     return mark_safe(f'<time datetime="{date_iso}">{date_fmt}</time>')


# Path: weechat/about/models.py
from django.db import models
from django.db.models.signals import post_save
from django.utils.translation import gettext, gettext_lazy
from weechat.common.i18n import i18n_autogen
from weechat.common.templatetags.localdate import localdate

    class Meta:
        """Meta class for ScreenShot."""
        ordering = ['priority']


class Keydate(models.Model):
    """A WeeChat key date."""
    date = models.DateField()
    version = models.TextField(max_length=32)
    text = models.TextField()

    def __str__(self):
        str_version = f'{self.version}: ' if self.version else ''
        return f'{self.date} - {str_version}{self.text}'

    def text_i18n(self):
        """Return translated key date."""
        return gettext(self.text.replace('\r\n', '\n'))

    class Meta:
        """Meta class for KeyDate."""
        ordering = ['-date']


def handler_keydate_saved(sender, **kwargs):
    """Write file _i18n_keydates.py with key dates to translate."""
    # pylint: disable=unused-argument
    strings = []
    for keydate in Keydate.objects.order_by('-date'):
        strings.append(keydate.text)

    i18n_autogen('about', 'keydates', strings)