# msgfmt: duplicate message definition in po file

## TL;DR

Fixes the msgfmt error when a PO file defines the same msgid twice. Merge the two entries into one, keeping the best translation. Use when msgfmt reports a duplicate definition. Not for fuzzy entries.

## The error

```text
po/de.po:87: duplicate message definition...
```

## Fix it

### Step 1: Find both definitions

```bash
grep -n 'msgid "cart.title"' po/de.po
```

Expected: You see the two line numbers defining the same msgid.

### Step 2: Compare the two translations

```bash
sed -n '80,95p' po/de.po
```

Expected: You see both msgstr values and pick the correct one.

### Step 3: Merge into a single entry and recompile

```bash
msgfmt --check po/de.po -o /dev/null
```

Expected: msgfmt compiles cleanly with no duplicates.

## When to use this

- msgfmt reports a duplicate message definition
- A merge created two entries for one msgid

## When NOT to use this

- msgfmt reports fuzzy entries, that is a separate check flag
- The file fails to parse, fix the syntax first

## Tool and version compatibility

- GNU gettext msgfmt
- Any PO-based workflow

## Variant phrasings

### duplicates after a branch merge

Both branches added the same new string. Keep one entry during conflict resolution.

### duplicate with different contexts

Add msgctxt to distinguish them; context makes the msgid unique.

## Why it happens

PO files require unique msgids (plus context). Two tools or two branches adding the same string independently create duplicates, and msgfmt refuses to compile because it cannot know which translation wins.

## Edge cases

- Same msgid in different files is fine; duplicates are per-file
- msgctxt distinguishes otherwise identical msgids
- Automated merges should dedupe on msgid plus context

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_ZQDMwlbi0AdikRBwJXZbog
