diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 41e51892..f2517d66 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -50,6 +50,15 @@ repos: entry: ./script/check_compiled_translations language: system files: \.po$ + - repo: local + hooks: + - id: po-file-handler + name: PO file timestamp homogenizer + entry: ./script/po_file_handler + language: python + files: \.(po|pot)$ + stages: [pre-commit] + additional_dependencies: ["babel==2.15.0"] # Specify the version you need - repo: local hooks: - id: husky-run-pre-commit-lint diff --git a/amt/locale/base.pot b/amt/locale/base.pot index c12a70a9..3be6b69d 100644 --- a/amt/locale/base.pot +++ b/amt/locale/base.pot @@ -8,14 +8,14 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2024-10-20 20:26+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"POT-Creation-Date: 0001-01-01 00:00+0000\n" +"PO-Revision-Date: 0001-01-01 00:00+0000\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: Babel 2.16.0\n" +"Generated-By: Babel 2.15.0\n" #: amt/api/ai_act_profile.py:24 msgid "Type" diff --git a/amt/locale/en_US/LC_MESSAGES/messages.po b/amt/locale/en_US/LC_MESSAGES/messages.po index e9d104c8..7545cfd8 100644 --- a/amt/locale/en_US/LC_MESSAGES/messages.po +++ b/amt/locale/en_US/LC_MESSAGES/messages.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2024-10-20 20:26+0200\n" -"PO-Revision-Date: 2024-07-25 21:01+0200\n" +"POT-Creation-Date: 0001-01-01 00:00+0000\n" +"PO-Revision-Date: 0001-01-01 00:00+0000\n" "Last-Translator: FULL NAME \n" "Language: en_US\n" "Language-Team: en_US \n" @@ -16,7 +16,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.16.0\n" +"Generated-By: Babel 2.15.0\n" #: amt/api/ai_act_profile.py:24 msgid "Type" diff --git a/amt/locale/nl_NL/LC_MESSAGES/messages.po b/amt/locale/nl_NL/LC_MESSAGES/messages.po index f1a23964..23b10d08 100644 --- a/amt/locale/nl_NL/LC_MESSAGES/messages.po +++ b/amt/locale/nl_NL/LC_MESSAGES/messages.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2024-10-20 20:26+0200\n" -"PO-Revision-Date: 2024-07-25 21:01+0200\n" +"POT-Creation-Date: 0001-01-01 00:00+0000\n" +"PO-Revision-Date: 0001-01-01 00:00+0000\n" "Last-Translator: FULL NAME \n" "Language: nl_NL\n" "Language-Team: nl_NL \n" @@ -16,7 +16,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.16.0\n" +"Generated-By: Babel 2.15.0\n" #: amt/api/ai_act_profile.py:24 msgid "Type" diff --git a/script/po_file_handler b/script/po_file_handler new file mode 100755 index 00000000..ccfa6523 --- /dev/null +++ b/script/po_file_handler @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +import argparse +from datetime import MINYEAR, UTC, datetime + +from babel.messages import pofile + + +def remove_timestamps(filename: str) -> bool: + with open(filename, "rb") as f: + catalog = pofile.read_po(f) + + modified = False + if catalog.creation_date or catalog.revision_date: + min_datetime = datetime(MINYEAR, 1, 1, 0, 0, 0, 0, tzinfo=UTC) + if catalog.creation_date == min_datetime and catalog.revision_date == min_datetime: + return modified + catalog.creation_date = min_datetime + catalog.revision_date = min_datetime + modified = True + + if modified: + with open(filename, "wb") as f: + pofile.write_po(f, catalog, ignore_obsolete=True, include_previous=True) + + return modified + + +def main() -> int: + parser = argparse.ArgumentParser() + parser.add_argument("filenames", nargs="*") + args = parser.parse_args() + + return_code = 0 + for filename in args.filenames: + if remove_timestamps(filename): + print(f"Removed timestamps from {filename}") + return_code = 1 + return return_code + + +if __name__ == "__main__": + exit(main())