32

We have two .po files, each from different branches of a piece of software.

We need to combine these into a single .po file.

There are duplicates between the two files, and the ideal handling would be for one file's strings to be favoured (consistently).

We have a SUSE system so the --output-file doesn't seem to have the behaviour of ignoring/merging duplicates which the Sun version has according to a man page I found from a web search. (We do not have a Sun machine handy!)

fooquency
  • 1,575
  • 3
  • 16
  • 29
  • Possible duplicate of [Merge 2 GetText files](http://stackoverflow.com/questions/355994/merge-2-gettext-files) – DanMan Oct 08 '15 at 13:06

3 Answers3

40

What you are looking for is the msgcat util, it concatenates and merges the specified PO dictionaries.

This is part of gettext utils, for more information please consult gettext manual page on msgcat.

bart
  • 7,640
  • 3
  • 33
  • 40
sorin
  • 161,544
  • 178
  • 535
  • 806
  • Usage as simple as regular `cat`, but check all output for "fuzzy" (you need to pick one version there). – Ctrl-C Aug 30 '13 at 13:09
  • NOTE: Inserted the HTML link into the answer, so @rve's comment doesn't make sense anymore. ;) – lxg Nov 06 '14 at 10:40
  • 2
    As a side-note, while `msgcat` handles collisions when the same string appears in several po files, the `--use-first` options allows to favor the translation of one of the files over the others. – liberforce Jun 05 '15 at 09:20
14

you can use poedit. To merge your current po-file, you must to open it and click:

  • Catalog > Update from POT-file.
  • Set the filter to all files and select your second.po file

Poedit will show you new & obsolete strings

user2306934
  • 149
  • 1
  • 2
  • 1
    If you want GUI, I'd suggest using `virtaal` if that's available for your operating system. – Mikko Rantalainen Apr 25 '13 at 10:10
  • 1
    I think poEdit works just fine for this kind of task! Thanks for the answer, it helped me! – markus Nov 18 '13 at 19:56
  • 3
    Poedit doesn't transfer the actual translations that way though, just the `msgid`s. – DanMan Feb 05 '15 at 11:37
  • What do you mean @DanMan? I needed to update the catalog as the source included "notes for translators" and it also kept the actual translations by updating the catalog that way. The msgstr are there along with the (new) #. notes. – Firsh - justifiedgrid.com Dec 18 '19 at 20:53
2

I use msgmerge:

msgmerge [old_file.po] [new_file.po] > output.po

It works for me, but be aware that it does a silly merge, it is, it discards the entries in the old_file (new file items overwrites old one items).

Ivan
  • 14,692
  • 17
  • 59
  • 96
  • 6
    The `msgmerge` file is meant for applying new template to existing translation. It will discard any localizations in the second file by design! Use `msgcat` for merging localization data. Sadly, it only does stupid catenation instead of real 3-way merge you would want to have with version control. – Mikko Rantalainen Apr 25 '13 at 10:09
  • This is also bad if you have some of the messages in both files. Then you will get "some.po:16008: ...this is the location of the first definition" style messages and it won't concatenate the files. How can I use the first available translation from ANY file? – nagylzs Nov 03 '15 at 06:41
  • 1
    You can try `msgcat --use-first first.po second.po -o output.po` or see https://stackoverflow.com/q/16214067/334451 – see `man msgcat` for details. – Mikko Rantalainen Jun 10 '21 at 07:02