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

# is being replaced by%__lingui_octothorpe__% outside plural and selectordinal #1927

Closed
1 of 3 tasks
dan-dr opened this issue Apr 30, 2024 · 3 comments · Fixed by #1928
Closed
1 of 3 tasks

# is being replaced by%__lingui_octothorpe__% outside plural and selectordinal #1927

dan-dr opened this issue Apr 30, 2024 · 3 comments · Fixed by #1928

Comments

@dan-dr
Copy link
Contributor

dan-dr commented Apr 30, 2024

Describe the bug
Given a regular messages that has # in it , when trying to display the message it is replaced with %__lingui_octothorpe__%

EDIT: it seems to happen only if the translated message starts with #

To Reproduce

import { Trans } from "@lingui/macro"

export default function App() {
   return <Trans>#{standing} in leaderboard</Trans>
}

Resulting in po:

msgid "#{standing} in the leaderboard"
msgstr "#{standing} in the leaderboard"

Expected behavior
#7 in leaderboard

Actual result
%__lingui_octothorpe__%7 in leaderboard

Additional context
Add any other context about the problem here.

  • jsLingui version 4.7.1
  • Babel version 7.12.3 (i think, CRA)
  • Macro support:
  • I'm using SWC with @lingui/swc-plugin
  • I'm using Babel with babel-macro-plugin
  • I'm not using macro
  • Create React App
@dan-dr dan-dr changed the title pound symbol in non-plural messages replaced with %__lingui_octothorpe__% pound symbol in non-plural messages replaced with %__lingui_octothorpe__% if it's the first character Apr 30, 2024
@dan-dr
Copy link
Contributor Author

dan-dr commented Apr 30, 2024

I'm guessing it's

if (token === "#") {

@dan-dr dan-dr changed the title pound symbol in non-plural messages replaced with %__lingui_octothorpe__% if it's the first character messages starting with # symbol followed by variable outputs %__lingui_octothorpe__% in the translation Apr 30, 2024
@dan-dr
Copy link
Contributor Author

dan-dr commented Apr 30, 2024

I narrowed it, the bug seems to occur only when the translation starts with # followed by variable.

EDIT: found more test cases that fail
It seems to happen whenever # is tokenized by itself (I think it only happens when it's next to a variable)

Here's a test case for i18n.test.ts:

it("._ should not bug when with #", () => {
    const messages = {
      Bad: "#{standing} in leaderboard",
      BadToo: "leaderboard standing is {standing}#",
      BadTooToo: "your id is {name}#{tag}",
      Good: "# standing in leaderboard",
      GoodToo: "standing is #{standing} in leaderboard",
      GoodTooToo: "leaderboard standing is #{standing}",
    }

    const i18n = setupI18n({
      locale: "en",
      messages: { en: messages },
    })
    expect(i18n._({ id: "Bad", values: { standing: 7 } })).toEqual(
      "#7 in leaderboard"
    )
    expect(i18n._({ id: "BadToo", values: { standing: 7 } })).toEqual(
      "leaderboard standing is 7#"
    )
    expect(
      i18n._({ id: "BadTooToo", values: { name: "hey", tag: "you" } })
    ).toEqual("your id is hey#you")
    expect(i18n._({ id: "Good", values: { standing: 7 } })).toEqual(
      "# standing in leaderboard"
    )
    expect(i18n._({ id: "GoodToo", values: { standing: 7 } })).toEqual(
      "standing is #7 in leaderboard"
    )
    expect(i18n._({ id: "GoodTooToo", values: { standing: 7 } })).toEqual(
      "leaderboard standing is #7"
    )
  })

image

@dan-dr dan-dr changed the title messages starting with # symbol followed by variable outputs %__lingui_octothorpe__% in the translation # is being replaced by%__lingui_octothorpe__% outside plural and selectordinal May 1, 2024
@thekip
Copy link
Collaborator

thekip commented May 6, 2024

it seems there is an issue in message format parser, it shouldn't treat '#' symbol as octothorpe outside { } expressions. Anyway, thanks for digging it and fixing.

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 a pull request may close this issue.

2 participants