How to use xgettext iteratively to update .po files for translation
Asked Answered
I

1

6

I'm looking at using xgettext to aid translation of large codebase, and I have two questions:

  • if I have one .po file per-language, is there an easy way to update them all using a single xgettext scan of the codebase, or must I run xgettext once for each language?
  • if I add the target langauge to the .po file header with poedit, xgettext seems to overwrite this with default headers. How can I stop this?

Maybe I'm using the wrong tool, in which case suggestions are welcome. What I want is to be able to scan the code and update the .po files with any new strings, but leaving any header information intact.

EDIT: I know that poedit can scan code, but I was hoping to find a command line application to perform the scanning to automate the process more easily.

Invitatory answered 30/3, 2009 at 14:52 Comment(0)
M
13

Yes, basically you're using the tools wrong.

xgettext extracts the tags and creates the template file. (e.g. *.pot file)

The msgmerge command updates a .po file with changes from the .pot file.

We have make rules to update the .po files, like the one below:

%.en.po : %.pot
    -[ -e $@ ] && msgmerge --width=110 --update $@ $<
    [ -e $@ ] || cp $< $@
Mildred answered 30/3, 2009 at 16:2 Comment(5)
That's the missing piece of the puzzle. Many thanks for that.Invitatory
if I'm understanding well, also you can add -j to the xgettext command, to only append missing keys. Join messages with existing file.Carmencita
@Carmencita I don't know whether that will remove messages that have been deleted - msgmerge will comment out messages in the po files which have been removed from the source.Mildred
How does this rule work? What language is this? Where to apply it?Endodermis
Hi @Endodermis This is a Makefile rule, to generate or update .po files after changes in the .pot file.Mildred

© 2022 - 2024 — McMap. All rights reserved.