From 856e939c212bd1e27ef16c9969de7604f1a33a29 Mon Sep 17 00:00:00 2001 From: Peter Pfeufer Date: Mon, 20 Jan 2025 04:35:10 +0100 Subject: [PATCH] [ADD] Locale mapping for DataTables and Moment.JS --- .pre-commit-config.yaml | 13 +- .../templates/authentication/tokens.html | 12 +- .../templates/corputils/corpstats.html | 6 + .../corputils/templates/corputils/search.html | 4 + .../templates/groupmanagement/audit.html | 4 + .../groupmanagement/groupmembers.html | 4 + .../templates/groupmanagement/groups.html | 7 +- .../templates/permissions_tool/audit.html | 4 + .../templates/permissions_tool/overview.html | 4 + .../project_name/settings/base.py | 33 +++ .../mumble/mumble_connection_history.html | 5 + allianceauth/srp/templates/srp/data.html | 4 + .../DataTables/Plugins/2.2.1/i18n/cs.json | 247 ++++++++++++++++++ .../DataTables/Plugins/2.2.1/i18n/de-DE.json | 243 +++++++++++++++++ .../DataTables/Plugins/2.2.1/i18n/es-ES.json | 244 +++++++++++++++++ .../DataTables/Plugins/2.2.1/i18n/fr-FR.json | 245 +++++++++++++++++ .../DataTables/Plugins/2.2.1/i18n/it-IT.json | 244 +++++++++++++++++ .../DataTables/Plugins/2.2.1/i18n/ja.json | 84 ++++++ .../DataTables/Plugins/2.2.1/i18n/ko.json | 122 +++++++++ .../DataTables/Plugins/2.2.1/i18n/nl-NL.json | 246 +++++++++++++++++ .../DataTables/Plugins/2.2.1/i18n/pl.json | 240 +++++++++++++++++ .../DataTables/Plugins/2.2.1/i18n/ru.json | 247 ++++++++++++++++++ .../DataTables/Plugins/2.2.1/i18n/uk.json | 186 +++++++++++++ .../Plugins/2.2.1/i18n/zh-HANT.json | 240 +++++++++++++++++ .../libs/moment.js/2.29.4/locale/cs.js | 191 ++++++++++++++ .../libs/moment.js/2.29.4/locale/de.js | 89 +++++++ .../libs/moment.js/2.29.4/locale/es.js | 121 +++++++++ .../libs/moment.js/2.29.4/locale/fr.js | 119 +++++++++ .../libs/moment.js/2.29.4/locale/it.js | 117 +++++++++ .../libs/moment.js/2.29.4/locale/ja.js | 159 +++++++++++ .../libs/moment.js/2.29.4/locale/ko.js | 86 ++++++ .../libs/moment.js/2.29.4/locale/nl.js | 115 ++++++++ .../libs/moment.js/2.29.4/locale/pl.js | 151 +++++++++++ .../libs/moment.js/2.29.4/locale/ru.js | 224 ++++++++++++++++ .../libs/moment.js/2.29.4/locale/uk.js | 178 +++++++++++++ .../libs/moment.js/2.29.4/locale/zh-cn.js | 131 ++++++++++ allianceauth/templates/bundles/moment-js.html | 15 +- allianceauth/templatetags/aa_i18n.py | 90 +++++++ .../timerboard/templates/timerboard/view.html | 7 +- 39 files changed, 4459 insertions(+), 22 deletions(-) create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/cs.json create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/de-DE.json create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/es-ES.json create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/fr-FR.json create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/it-IT.json create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/ja.json create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/ko.json create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/nl-NL.json create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/pl.json create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/ru.json create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/uk.json create mode 100644 allianceauth/static/allianceauth/libs/DataTables/Plugins/2.2.1/i18n/zh-HANT.json create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/cs.js create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/de.js create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/es.js create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/fr.js create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/it.js create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/ja.js create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/ko.js create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/nl.js create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/pl.js create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/ru.js create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/uk.js create mode 100644 allianceauth/static/allianceauth/libs/moment.js/2.29.4/locale/zh-cn.js create mode 100644 allianceauth/templatetags/aa_i18n.py 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 %} +