Git Product home page Git Product logo

Comments (3)

dan-dr avatar dan-dr commented on June 13, 2024

I'm guessing it's

if (token === "#") {

from js-lingui.

dan-dr avatar dan-dr commented on June 13, 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

from js-lingui.

thekip avatar thekip commented on June 13, 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.

from js-lingui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.