python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.34k stars 448 forks source link

`extract` overwrites existing template, and `update` comments unused #1086

Open maxktz opened 6 months ago

maxktz commented 6 months ago

when i use pybabel extract or pybabel update there is no way to not remove existing translations, unused translations that existed in .pot or .po are being removed or commented.

Please add flag to save them while using this commands.

akx commented 4 months ago

extract never reads existing files – it just overwrites the given output file.

Have you tried --previous for pybabel update? Does it do what you need?

maxktz commented 3 months ago

--previous

About --previous, yes I guess it's what I need, it's just wasn't clear for me, what it really does. I would call it --keep-previous, or --keep-existing, something like that.

About --extract, I was wrong a little bit, that extract creates template, I thought it updates template file. But the problem is that it overwrites existing template.

There are some msgids that extract can't see in files, right? So I add them to template manually.

I want extract to have option to just update template file by extracted msgids, not overwrite, got it?

I have achieved that behavior by doing this (in case someone need it):

I just store manually added msgids in mymessages.pot template

Then run this commands:

# extract to messages.pot template
pybabel extract -F babel.cfg -o messages.pot .

# merge mymessages template to messages.pot
cat mymessages.pot >> messages.pot

# then update catalogs
pybabel update -i messages.pot -d ./translations