Skip to content

PO file flags are lost when running extract #2398

@cornedor

Description

@cornedor

Description

PO file flags (like #, fuzzy or custom flags like #, myTag) are lost when running lingui extract again. The extra.flags field from the existing catalog is not preserved during the merge process.

The bug is in packages/cli/src/api/catalog/mergeCatalog.ts. When merging catalogs, the code takes rest from nextCatalog (extracted messages) which doesn't contain flags, and only preserves translation from prevCatalog. The extra.flags field is silently discarded.

Verifications

  • I've checked the docs and this isn't covered there.
  • I've searched existing issues on GitHub.

Reproduction Steps

1. Create a PO file with a flag

cat > messages.po << 'EOF'
msgid "Hello"
msgstr "Hallo"
#, myTag
EOF

2. Run extract

lingui extract

3. Check the PO file - the flag "#, myTag" is gone

Or programmatically:

import { mergeCatalog } from "@lingui/cli/api"

const prevCatalog = {
  "Hello": {
    translation: "Hallo",
    extra: { flags: ["myTag"] }
  }
}

const nextCatalog = {
  "Hello": {
    message: "Hello",
    origin: [["src/app.ts", 1]]
  }
}


const result = mergeCatalog(prevCatalog, nextCatalog, false, {})
console.log(result["Hello"].extra?.flags) // undefined

Expected Behavior

The flags should be preserved from the existing catalog when running extract. Flags are translator/tooling metadata that should persist across extractions, similar to how translation is preserved.

Macro Support

Not using macro

Lingui Version

5.8.0

Babel Version

@babel/core@7.28.3

Framework

Affects CLI command

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions