# 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/common/tracker.py
# def commits_links(commits):
#     """Replace commits or branches by GitHub URLs."""
#     if not commits:
#         return ''
# 
#     # read SVG with git commit/branch
#     filename = project_path_join('templates', 'svg', 'git-commit.html')
#     with open(filename, 'r', encoding='utf-8') as _file:
#         svg_commit = _file.read().strip()
#     filename = project_path_join('templates', 'svg', 'git-branch.html')
#     with open(filename, 'r', encoding='utf-8') as _file:
#         svg_branch = _file.read().strip()
# 
#     images = []
#     for commit in commits.split(','):
#         objtype = 'commit'
#         link = svg_commit
#         if commit.startswith('commit/'):
#             commit = commit[7:]
#         if commit.startswith('tree/'):
#             objtype = 'tree'
#             commit = commit[5:]
#             link = svg_branch
#         repo, commit_id = split_commit(commit)
#         images.append(f'<a href="https://github.com/{repo}/{objtype}/'
#                       f'{commit_id}" target="_blank" rel="noopener">'
#                       f'{link}</a>')
#     return mark_safe(' '.join(images))
# 
# def tracker_links(tracker):
#     """Replace tracker items by URLs.
# 
#     Replace GitHub tracker item(s) (for example: "closes #123")
#     and savannah tracker item(s) (for example: "bug #12345")
#     by URL(s) to this/these item(s).
#     """
#     if not tracker:
#         return ''
#     items = [_replace_link(item) for item in tracker.split(',')]
#     return mark_safe('<br>'.join(items))


from django.db import models
from django.db.models.signals import post_save
from django.utils.safestring import mark_safe
from django.utils.translation import gettext, gettext_noop
from weechat.common.i18n import i18n_autogen
from weechat.common.templatetags.localdate import localdate
from weechat.common.tracker import commits_links, tracker_links
        """Return severity index based on CVSS score."""
        return get_severity(self.cvss_score)

    def severity_i18n(self):
        """Return translated severity based on CVSS score."""
        text = dict(SECURITY_SEVERITIES).get(self.severity_index(), '')
        return gettext(text) if text else ''

    def score_bar(self):
        """Return HTML code with score bar."""
        return mark_safe(get_score_bar(self.cvss_score))

    def affected_html(self):
        """Return list of affected versions, as HTML."""
        list_affected = []
        for version in self.affected.split(','):
            if '-' in version:
                version1, version2 = version.split('-', 1)
                list_affected.append(f'{version1} → {version2}')
            else:
                list_affected.append(version)
        return mark_safe(', '.join(list_affected))

    def fixed_html(self):
        """Return fixed version, as HTML."""
        return mark_safe(f'<span class="text-success fw-bold">'
                         f'{self.fixed}</span>')

    def release_date_l10n(self):
        """Return the release date formatted with localized date format."""

# 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/common/tracker.py
# def commits_links(commits):
#     """Replace commits or branches by GitHub URLs."""
#     if not commits:
#         return ''
# 
#     # read SVG with git commit/branch
#     filename = project_path_join('templates', 'svg', 'git-commit.html')
#     with open(filename, 'r', encoding='utf-8') as _file:
#         svg_commit = _file.read().strip()
#     filename = project_path_join('templates', 'svg', 'git-branch.html')
#     with open(filename, 'r', encoding='utf-8') as _file:
#         svg_branch = _file.read().strip()
# 
#     images = []
#     for commit in commits.split(','):
#         objtype = 'commit'
#         link = svg_commit
#         if commit.startswith('commit/'):
#             commit = commit[7:]
#         if commit.startswith('tree/'):
#             objtype = 'tree'
#             commit = commit[5:]
#             link = svg_branch
#         repo, commit_id = split_commit(commit)
#         images.append(f'<a href="https://github.com/{repo}/{objtype}/'
#                       f'{commit_id}" target="_blank" rel="noopener">'
#                       f'{link}</a>')
#     return mark_safe(' '.join(images))
# 
# def tracker_links(tracker):
#     """Replace tracker items by URLs.
# 
#     Replace GitHub tracker item(s) (for example: "closes #123")
#     and savannah tracker item(s) (for example: "bug #12345")
#     by URL(s) to this/these item(s).
#     """
#     if not tracker:
#         return ''
#     items = [_replace_link(item) for item in tracker.split(',')]
#     return mark_safe('<br>'.join(items))


# Path: weechat/doc/models.py
from django.db import models
from django.db.models.signals import post_save
from django.utils.safestring import mark_safe
from django.utils.translation import gettext, gettext_noop
from weechat.common.i18n import i18n_autogen
from weechat.common.templatetags.localdate import localdate
from weechat.common.tracker import commits_links, tracker_links

        """Return severity index based on CVSS score."""
        return get_severity(self.cvss_score)

    def severity_i18n(self):
        """Return translated severity based on CVSS score."""
        text = dict(SECURITY_SEVERITIES).get(self.severity_index(), '')
        return gettext(text) if text else ''

    def score_bar(self):
        """Return HTML code with score bar."""
        return mark_safe(get_score_bar(self.cvss_score))

    def affected_html(self):
        """Return list of affected versions, as HTML."""
        list_affected = []
        for version in self.affected.split(','):
            if '-' in version:
                version1, version2 = version.split('-', 1)
                list_affected.append(f'{version1} → {version2}')
            else:
                list_affected.append(version)
        return mark_safe(', '.join(list_affected))

    def fixed_html(self):
        """Return fixed version, as HTML."""
        return mark_safe(f'<span class="text-success fw-bold">'
                         f'{self.fixed}</span>')

    def release_date_l10n(self):
        """Return the release date formatted with localized date format."""

        return localdate(self.release_date)