Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message context (msgctxt) not working #1198

Closed
tfhult opened this issue Jan 21, 2022 · 20 comments · Fixed by #1440
Closed

Message context (msgctxt) not working #1198

tfhult opened this issue Jan 21, 2022 · 20 comments · Fixed by #1440
Assignees
Labels
Milestone

Comments

@tfhult
Copy link

tfhult commented Jan 21, 2022

Describe the bug
When providing context to a message, the context is treated like an ID in the generated en.po file.

To Reproduce
With the version 3.13.1 with create-react-app, and not specifying orderBy in lingui.config.js:

import { Trans } from "@lingui/react"

export default function App() {
  return <div>
    <Trans context='ctxtA'>My string</Trans>
    <Trans context='ctxtB'>My string</Trans>
    <Trans>My string</Trans>
  </div>
}

Expected behavior
3 messages should be created in the generated en.po file, like this:

#: src/App.tsx:11
msgid "My string"
msgstr "My string"

#: src/App.tsx:12
msgctxt "ctxtA"
msgid "My string"
msgstr "My string"

#: src/App.tsx:13
msgctxt "ctxtB"
msgid "My string"
msgstr "My string"

Actual behavior
This is created in the en.po file.

#: src/App.tsx:11
msgid "My string"
msgstr "My string"

msgid "ctxtA"
msgstr "ctxtA"

msgid "ctxtB"
msgstr "ctxtB"

Additional context
If using orderBy: 'origin' in lingui.config.js, an exception is thrown in getFirstOrigin() when running extract.

  • jsLingui version 3.13.1
  • Using create-react-app
@semoal
Copy link
Contributor

semoal commented Jan 24, 2022

Thanks, I'll try to fix as soon as I can. Contributions are welcome =)

@JSteunou
Copy link
Contributor

JSteunou commented Feb 4, 2022

@semoal I started #1205

For now all I succeed to do is adding more tests to find out where the issue might be. With my little knowledge on lingui's internal, it seems the 1st implementation is wrong: context is used as message way to early in the chain. The context information does not arrive at the catalog build step. I added failing tests that shows this. Catalog to PO is fine according to other tests.

With extracted catalog in JS the issue does not pop-up, but for every intermediate or final format other than JS this is broken I think.

@JSteunou
Copy link
Contributor

JSteunou commented Feb 4, 2022

@nakkamarra if you have some time to put on this one I would appreciate ;)

@stale
Copy link

stale bot commented Apr 6, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 6, 2022
@JSteunou
Copy link
Contributor

JSteunou commented Apr 7, 2022

Can anybody help me on this one plz?

@stale stale bot removed the wontfix label Apr 7, 2022
@semoal
Copy link
Contributor

semoal commented Apr 24, 2022

Will find time this week Jérôme, sorry 4 the delay, been really busy

@JSteunou
Copy link
Contributor

@semoal I will have a bit a free time next month but I still need help / guidance on this one

This is a very nice and awaited feature, let's make it work :)

@JSteunou
Copy link
Contributor

JSteunou commented Jul 8, 2022

Do you have any time soon @semoal or @tricoder42 to help me on this one (at least re-open it, and the MR and prevent stale bot to close it again (about that, you might want to config the bot so it does not close qualified issues)

This is really painful when using PO files

@stale
Copy link

stale bot commented Sep 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 8, 2022
@tfhult
Copy link
Author

tfhult commented Sep 12, 2022

I've verified that the issue remains with version 3.14.0. Would be great to get it working!

@stale stale bot removed the wontfix label Sep 12, 2022
@JSteunou
Copy link
Contributor

We (at my company) have a working fix @tfhult , PR is incoming for the next days.

@semoal or @tricoder42 or anyone, are you still maintaining this project?

@semoal
Copy link
Contributor

semoal commented Sep 12, 2022

Yes, I do. I’ll take care of everything at the end of this week

@JSteunou
Copy link
Contributor

Any news @semoal ?

@stale
Copy link

stale bot commented Dec 3, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Dec 3, 2022
@JSteunou
Copy link
Contributor

JSteunou commented Dec 5, 2022

@semoal or anyone managing this repository, please prevent stale bot to close this issue, the related PR took days of effort, and we really like to see it integrated into linguijs instead of going with a fork.

@stale stale bot closed this as completed Dec 17, 2022
@JSteunou
Copy link
Contributor

Seriously? Is this project that much dead?

@fdev
Copy link
Contributor

fdev commented Dec 17, 2022

Seriously? Is this project that much dead?

I've been subscribed to this issue for a long time and I'm disappointed as well. If there is a working fix ready to be reviewed it should not take this long, and the issue should definitely not get autoclosed for being stale. Does stale mean a lack of interest from the community, or lack of response from the maintainers?

@timofei-iatsenko timofei-iatsenko mentioned this issue Jan 23, 2023
8 tasks
@andrii-bodnar andrii-bodnar added this to the v4 milestone Feb 13, 2023
@andrii-bodnar andrii-bodnar linked a pull request Feb 16, 2023 that will close this issue
14 tasks
@yanndinendal
Copy link

yanndinendal commented Feb 17, 2023

Workaround in the mean time:

import { Trans } from "@lingui/react"

export default function App() {
  // Workaround for translation context
  // until https://github.com/lingui/js-lingui/issues/1198
  // is fixed.
  const ctxtA = '';
  const ctxB = '';
  return <div>
      <Trans>{ctxtA}My string</Trans>
      <Trans>{ctxtB}My string</Trans>
      <Trans>My string</Trans>
  </div>
}

=>

#: src/App.tsx:11
msgid "My string"
msgstr "My string"

#: src/App.tsx:12
msgid "{ctxtA}My string"
msgstr "{ctxtA}My string"

#: src/App.tsx:13
msgid "{ctxtB}My string"
msgstr "{ctxtB}My string"

for example, it could allow to have two keys for Disabled and {keys}Disabled:
Désactivé / Désactivées (which would both display "Disabled" in English).

@JSteunou
Copy link
Contributor

That is what we used to do before forking and publishing it as a PR, but it does not work well with plural and / or variables. Try using [ctxtA] instead.

@timofei-iatsenko
Copy link
Collaborator

😬 context implementation is almost ready, stay tuned )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
8 participants