Skip to content

feat(po-format): print source message as translation for explicit id#2390

Merged
andrii-bodnar merged 2 commits intomainfrom
feature/po-formatter
Jan 8, 2026
Merged

feat(po-format): print source message as translation for explicit id#2390
andrii-bodnar merged 2 commits intomainfrom
feature/po-formatter

Conversation

@timofei-iatsenko
Copy link
Collaborator

@timofei-iatsenko timofei-iatsenko commented Jan 8, 2026

Description

While working on #2388 i noticed that when we have an "explicit id" and extract with po formatter, the information about original message is not stored anywhere. So if those PO files than imported into some other systems it's hard to figure out what source text associated with this key.

In general, po files is not designed to work with "key" approach. Current implementation when key printed into msgid
(by the po spec msgid should contain a source message) is a workaround and kept historically during rewrite between v3-v4.

I have better idea how to do this, but any changes in this matter requires migration of catalogs and would be a big disruption - but i still have this on my plans.

So in this PR, source message would be printed to source locale and template catalog into the translation.

Before (after extraction):

en.po

        #. js-lingui-explicit-id
        msgid "custom.id"
        msgstr ""

After change in this PR:

en.po

        #. js-lingui-explicit-id
        msgid "custom.id"
        msgstr "with explicit id" <!-- source message printed

So printing original message to translation is also not strictly following the spec, but also not breaking it.

Also this PR adds more sanity to the PO Formatters, it cleans up after itself the comments used as serialization flags, such as js-lingui-explicit-id they make sense only for formatter itself, and should not be propagated to the lingui internal data model.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Examples update

Fixes # (issue)

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

@vercel
Copy link

vercel bot commented Jan 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
js-lingui Ready Ready Preview Jan 8, 2026 11:33am

@github-actions
Copy link

github-actions bot commented Jan 8, 2026

size-limit report 📦

Path Size
packages/core/dist/index.mjs 1.88 KB (0%)
packages/detect-locale/dist/index.mjs 618 B (0%)
packages/react/dist/index.mjs 1.38 KB (0%)

@timofei-iatsenko timofei-iatsenko marked this pull request as ready for review January 8, 2026 11:45
Copy link
Contributor

@andrii-bodnar andrii-bodnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timofei-iatsenko thank you! This is actually a pretty common approach. In Crowdin, we support a special flag that allows you to import source strings from msgstr instead of msgid. https://store.crowdin.com/gnu-gettext

@andrii-bodnar andrii-bodnar merged commit 94efdc0 into main Jan 8, 2026
10 checks passed
@andrii-bodnar andrii-bodnar deleted the feature/po-formatter branch January 8, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants