Is it possible to combine two .po translation files together?
Asked Answered
B

3

36

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!)

Bubonocele answered 13/10, 2009 at 17:56 Comment(1)
Possible duplicate of Merge 2 GetText filesVolution
L
43

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.

Labial answered 12/12, 2009 at 17:14 Comment(3)
Usage as simple as regular cat, but check all output for "fuzzy" (you need to pick one version there).Quirk
NOTE: Inserted the HTML link into the answer, so @rve's comment doesn't make sense anymore. ;)Trimble
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.Hobnail
H
15

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

Haggadist answered 22/4, 2013 at 10:15 Comment(4)
If you want GUI, I'd suggest using virtaal if that's available for your operating system.Fullfledged
I think poEdit works just fine for this kind of task! Thanks for the answer, it helped me!Semiliterate
Poedit doesn't transfer the actual translations that way though, just the msgids.Volution
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.Seymour
C
4

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).

Catling answered 29/1, 2013 at 10:59 Comment(3)
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.Fullfledged
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?Copacetic
You can try msgcat --use-first first.po second.po -o output.po or see https://mcmap.net/q/427760/-where-39-s-the-3-way-git-merge-driver-for-po-gettext-files/334451 – see man msgcat for details.Fullfledged

© 2022 - 2024 — McMap. All rights reserved.