diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 04c74b56..91268822 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,9 +33,9 @@ repos: - id: detect-private-key - id: check-case-conflict # Python checks - # - id: check-docstring-first +# - id: check-docstring-first - id: debug-statements - # - id: requirements-txt-fixer +# - id: requirements-txt-fixer - id: fix-encoding-pragma args: [--remove] - id: fix-byte-order-marker @@ -50,7 +50,8 @@ repos: \.min\.js| \.po| \.mo| - swagger\.json + swagger\.json| + static/(.*)/libs/ ) - id: check-executables-have-shebangs - id: end-of-file-fixer @@ -60,7 +61,8 @@ repos: \.min\.js| \.po| \.mo| - swagger\.json + swagger\.json| + static/(.*)/libs/ ) - repo: https://github.com/editorconfig-checker/editorconfig-checker.python rev: 2.7.3 @@ -72,7 +74,8 @@ repos: allianceauth\/static\/allianceauth\/css\/themes\/bootstrap-locals.less| \.po| \.mo| - swagger\.json + swagger\.json| + static/(.*)/libs/ ) - repo: https://github.com/igorshubovych/markdownlint-cli rev: v0.41.0 diff --git a/allianceauth/authentication/templates/authentication/tokens.html b/allianceauth/authentication/templates/authentication/tokens.html index 42e3c61b..4453efd7 100644 --- a/allianceauth/authentication/templates/authentication/tokens.html +++ b/allianceauth/authentication/templates/authentication/tokens.html @@ -1,5 +1,6 @@ {% extends "allianceauth/base-bs5.html" %} +{% load aa_i18n %} {% load i18n %} {% block page_title %} @@ -50,20 +51,23 @@ {% block extra_javascript %} {% include "bundles/datatables-js-bs5.html" %} + {% get_datatables_language_static LANGUAGE_CODE as DT_LANG_PATH %} + {% endblock %} diff --git a/allianceauth/permissions_tool/templates/permissions_tool/audit.html b/allianceauth/permissions_tool/templates/permissions_tool/audit.html index 3aa50e63..5055dc03 100644 --- a/allianceauth/permissions_tool/templates/permissions_tool/audit.html +++ b/allianceauth/permissions_tool/templates/permissions_tool/audit.html @@ -1,5 +1,6 @@ {% extends "allianceauth/base-bs5.html" %} +{% load aa_i18n %} {% load i18n %} {% block page_title %} @@ -57,11 +58,14 @@ {% include "bundles/datatables-js-bs5.html" %} {% include "bundles/filterdropdown-js.html" %} + {% get_datatables_language_static LANGUAGE_CODE as DT_LANG_PATH %} + {% if locale and LANGUAGE_CODE != 'en' %} - - {% get_current_language as LANGUAGE_CODE %} - {% get_language_info for LANGUAGE_CODE as lang %} + + {% get_momentjs_language_static LANGUAGE_CODE as MOMENTJS_LANG_PATH %} - {% if lang.code == 'zh-hans' %} - - - {% else %} - - - {% endif %} + {% endif %} diff --git a/allianceauth/templatetags/aa_i18n.py b/allianceauth/templatetags/aa_i18n.py new file mode 100644 index 00000000..216eca6b --- /dev/null +++ b/allianceauth/templatetags/aa_i18n.py @@ -0,0 +1,90 @@ +""" +Template tags for language mapping +""" + +from django.conf import settings +from django.template.defaulttags import register +from django.templatetags.static import static + + +@register.simple_tag +def get_datatable_language_code(language: str) -> str: + """ + Get the correct language code for DataTables + + :param language: Django's language code + :type language: str + :return: Mapped language code + :rtype: str + """ + + mapped_language = ( + settings.LANGUAGE_MAPPING["DataTables"].get(language) + if language != "en" + else "" + ) + + return mapped_language + + +@register.simple_tag +def get_momentjs_language_code(language: str) -> str: + """ + Get the correct language code for Moment.JS + + :param language: Django's language code + :type language: str + :return: Mapped language code + :rtype: str + """ + + mapped_language = ( + settings.LANGUAGE_MAPPING["MomentJS"].get(language) if language != "en" else "" + ) + + return mapped_language + + +@register.simple_tag +def get_datatables_language_static(language: str) -> str: + """ + Get the correct language code URL for DataTables + + :param language: Django's language code + :type language: str + :return: Mapped language code + :rtype: str + """ + + mapped_language = get_datatable_language_code(language) + static_url = ( + static( + path=f"allianceauth/libs/DataTables/Plugins/2.2.1/i18n/{mapped_language}.json" + ) + if mapped_language + else "" + ) + + return static_url + + +@register.simple_tag +def get_momentjs_language_static(language: str) -> str: + """ + Get the correct language code URL for Moment.JS + + :param language: Django's language code + :type language: str + :return: Mapped language code + :rtype: str + """ + + mapped_language = get_momentjs_language_code(language) + + static_url = ( + static(path=f"allianceauth/libs/moment.js/2.29.4/locale/{mapped_language}.js") + if mapped_language + else "" + ) + + return static_url diff --git a/allianceauth/timerboard/templates/timerboard/view.html b/allianceauth/timerboard/templates/timerboard/view.html index a39fc027..8746eb6c 100644 --- a/allianceauth/timerboard/templates/timerboard/view.html +++ b/allianceauth/timerboard/templates/timerboard/view.html @@ -1,5 +1,6 @@ {% extends "allianceauth/base-bs5.html" %} +{% load aa_i18n %} {% load i18n %} {% load evelinks %} @@ -94,6 +95,8 @@ {% include "bundles/timers-js.html" %} {% include "bundles/datatables-js-bs5.html" %} + {% get_datatables_language_static LANGUAGE_CODE as DT_LANG_PATH %} +