Search code examples
mergecommand-line-interfacetranslationgnugettext

Merge two PO files and overwrite matching translation rules


I'm attempting to merge two PO files.

I have a base.po file that has general translations.

I have an extra.po which has extra translations that I'd like to add to the base file OR overwrite translations for if there are matching translation IDs.

I've tried using msgmerge:

$ msgmerge extra.po base.po -o merge.po

But this comments out any translations with matching IDs.

Looking at the msgmerge documentation, it doesn't look like there is any option to effect this behavior.

I'd like to be able to have multiple extra translation files (extra1.po, extra2.po, etc.) so I can merge them with the base translation file and use them in different contexts.

Does anyone know how to do what I'm attempting?


Solution

  • Turns out I needed to be using msgcat instead.

    The below command creates a PO file merge.po that contains all of the translations from extra.po and adds any additional translations from base.po.

    The --use-first option specifies that if there is a matching translation id between the two files, to choose the translation from extra.po.

    $ msgcat extra.po base.po -o merge.po --use-first