Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore babel timestamp diffs #237

Closed
anneschuth opened this issue Oct 9, 2024 · 0 comments · Fixed by #295
Closed

Ignore babel timestamp diffs #237

anneschuth opened this issue Oct 9, 2024 · 0 comments · Fixed by #295
Assignees

Comments

@anneschuth
Copy link
Member

This should will help set up a pre-commit hook to automatically remove timestamps from PO files before committing, preventing merge conflicts.

Step 1: Create the PO file handler script

Create a file named po_file_handler.py in the scripts folder:

#!/usr/bin/env python
import argparse
from babel.messages import pofile

def remove_timestamps(filename):
    with open(filename, 'rb') as f:
        catalog = pofile.read_po(f)
    
    modified = False
    if catalog.creation_date or catalog.revision_date:
        catalog.creation_date = None
        catalog.revision_date = None
        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():
    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())

make the file executable

Step 2: Create or update the pre-commit configuration

Create or update the .pre-commit-config.yaml file in your repository root:

repos:
- repo: local
  hooks:
  - id: po-file-handler
    name: PO file timestamp remover
    entry: python po_file_handler.py
    language: python
    files: \.(po|pot)$
    stages: [commit]
    additional_dependencies: ['babel==2.15.0']  # Specify the version you need
@anneschuth anneschuth converted this from a draft issue Oct 9, 2024
@ChristopherSpelt ChristopherSpelt self-assigned this Oct 21, 2024
@ChristopherSpelt ChristopherSpelt linked a pull request Oct 21, 2024 that will close this issue
5 tasks
@github-project-automation github-project-automation bot moved this from 👷 In Progress to ✅ Done in 👾 AI Validation Team Planning Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants