babel icon indicating copy to clipboard operation
babel copied to clipboard

Option to skip POT-Creation-Date

Open Dreamsorcerer opened this issue 5 years ago • 12 comments

Could we get an option to skip adding/updating the POT-Creation-Date header when running pybabel extract?

Use case is that we want a pre-commit hook that updates the translations, to ensure our translations are always in sync with the code base. But, because it changes this header every time, it results in a merge conflict with every single branch.

Dreamsorcerer avatar Aug 06 '20 14:08 Dreamsorcerer

I would love this!

We've got a GitHub Action step that runs pybabel extract on every push to master that opens a Pull Request to update the message catalog. This option would allow us to skip creating Pull Requests that only contain changes to the POT-Creation-Date (or any other header changes like Generated-By, etc).

cburmeister avatar Apr 30 '21 19:04 cburmeister

We ended up adding a post-process step to strip out this line (and a couple more bespoke things). So we have a script which basically runs the extract function, then runs some others functions which post-process the files. Given that we've been using it since I opened this issue with little issues, it seems to be pretty stable.

Dreamsorcerer avatar Apr 30 '21 21:04 Dreamsorcerer

@Dreamsorcerer would you mind sharing some of that if possible? I started writing some bash to do this but it got unwieldily fairly quickly 😅

cburmeister avatar Apr 30 '21 21:04 cburmeister

Slightly modified, but this should work (if you change project_path to the correct directory). https://gist.github.com/Dreamsorcerer/9355fd2a308121589d7c2fa5ffaa3e8a

We ended up using the extract function in a pre-commit hook to ensure that translations were always in-sync with the code.

Dreamsorcerer avatar Apr 30 '21 22:04 Dreamsorcerer

@Dreamsorcerer thank you!

cburmeister avatar Apr 30 '21 22:04 cburmeister

This feature would be very useful. Is there any updates on it?

emibcn avatar Feb 15 '23 10:02 emibcn

This feature can be to keep the creation date when updating, change it only on creation.

emibcn avatar Feb 15 '23 10:02 emibcn

PRs are very much welcome :)

akx avatar Feb 17 '23 18:02 akx

@akx Any interest in my PR? https://github.com/python-babel/babel/pull/999

joeportela avatar Apr 26 '23 14:04 joeportela

@akx When will this be published into a new release?

emibcn avatar Sep 15 '23 17:09 emibcn

@akx When will this be published into a new release?

This just got released in 2.13.0!

joeportela avatar Oct 04 '23 20:10 joeportela

@joeportela @akx I have just tested the PO update functionality using the new option --ignore-pot-creation-date and it looks good (no creation date differences):

image

What I am missing now is something similar for the POT extract functionality:

image

emibcn avatar Oct 18 '23 10:10 emibcn

There is nothing left to do here and this should not be added for extract, its extracting, not updating.

This should be closed @akx

StanFromIreland avatar Mar 04 '25 21:03 StanFromIreland

@akx @StanFromIreland POT-Creation-Date is still being modified on extract using Babel 2.17.0.

emibcn avatar Mar 05 '25 14:03 emibcn

Yes and it will be.

StanFromIreland avatar Mar 05 '25 15:03 StanFromIreland

extract doesn't read the file it's writing to, so it can't exactly "not update" a thing it doesn't know about.

If you need functionality to force the POT-Creation-Date to a value you'd prefer (or elide it altogether), that could be considered, but I'd like to know what the usecase is.

akx avatar Mar 05 '25 16:03 akx

To elide it altogether there is always --omit-header

StanFromIreland avatar Mar 05 '25 16:03 StanFromIreland

If you need functionality to force the POT-Creation-Date to a value you'd prefer (or elide it altogether), that could be considered, but I'd like to know what the usecase is.

I think my report clearly says on extract and explains the usecase. I think --omit-header didn't exist at the time though, so maybe that does the job we needed (at the time we just created a post-processing step to get the output we needed, and I'm no longer involved on that project).

Dreamsorcerer avatar Mar 06 '25 07:03 Dreamsorcerer

@akx

I believe it may know about the file used in -o. We create it by:

pybabel -v extract \
    --mapping-file "../babel.cfg" \
    -o "../${POT_FILE}" \
    --input-dirs "${role_path}/tasks" \
    --copyright-holder "${COPYRIGHT_HOLDER}" \
    --msgid-bugs-address "${MSGID_BUGS_ADDRESS}" \
    --project "${PROJECT}" \
    --version "${VERSION}"

emibcn avatar Mar 06 '25 07:03 emibcn

Hi @akx , The usecase would be the same as exposed @Dreamsorcerer at the beginning: If we just added/removed/updated some strings, we don't want all the files to be updated. In the current way, the commits and Pull Requests get much more complicated than what it should be if we'd omit the POT-Creation-Date. And, also, this is misleading, as the file was created before that. Even if you want to add a POT-Update-Date, that should only be updated if anything changed in the POT file, not just because we searched for strings changes.

emibcn avatar Mar 09 '25 13:03 emibcn