Skip to content

Commit

Permalink
Add po file homogenizer
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherSpelt committed Oct 21, 2024
1 parent acb831a commit 1be023d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions amt/locale/base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\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"
Expand Down
6 changes: 3 additions & 3 deletions amt/locale/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ 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 <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\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"
Expand Down
6 changes: 3 additions & 3 deletions amt/locale/nl_NL/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ 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 <EMAIL@ADDRESS>\n"
"Language: nl_NL\n"
"Language-Team: nl_NL <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\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"
Expand Down
43 changes: 43 additions & 0 deletions script/po_file_handler
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit 1be023d

Please sign in to comment.