Giter Club home page Giter Club logo

Comments (5)

thekip avatar thekip commented on May 25, 2024 1

will be fixed by #1850

from js-lingui.

jozefmery avatar jozefmery commented on May 25, 2024

Hi, I investigated this issue and I believe the core of the issue is that the interpolation here runs before the replaceOctothorpe function that uses the String#replace method. By interpolating first, there is no easy way of knowing where the # originated from in the component hierarchy. Furthermore, by using the String#replace method, only the first occurence is replaced as the provided # pattern here is a string. Currently, there is no escape hatch for the replacement of the # symbol that I know of.

To solve this issue I propose the following: Remove the # related behavior entirely

I believe that a better and simpler solution to include the actual number in a plural sentence is to use the well-established templating approach of Lingui (e.g.: There are ${count} apples). replaceOctothorpe additionally formats the number for you (number style by default), but you may do that as you would anywhere else: There are ${i18n.number(count, ...)} apples. This approach covers more (albeit edge-case) use-case as it allows you to include the number any times, and eliminates the issues related to a bespoke templating systems that sort of goes against the philosophy of the library.

I would love to hear your feedback and please let me know if I missed anything.

from js-lingui.

thekip avatar thekip commented on May 25, 2024

Thanks for digging into the issue, the "octothorpe" symbol is part of ICU messages spec, so that's why there are here.

from js-lingui.

jozefmery avatar jozefmery commented on May 25, 2024

Thank you for the rapid response. You are correct I did not consider that, so the replacing of the # is correct, except I believe every instance should be replaced. Furthmore, literal # and any other special symbols are supported by enclosing them in single quotes '#' and a single quote is represented by two consecutive ones ''. It is described here. You can check out this online editor.

from js-lingui.

kiejo avatar kiejo commented on May 25, 2024

Thanks for fixing this! I'm looking forward to the release which will include the fix :)

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.