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

Avoid methods in MessageValue #36

Open
littledan opened this issue Dec 5, 2023 · 3 comments
Open

Avoid methods in MessageValue #36

littledan opened this issue Dec 5, 2023 · 3 comments

Comments

@littledan
Copy link
Member

MessageValue has a number of methods. This is different from how the rest of Intl formatToParts works, which is entirely data-based. I don't quite understand why these methods are needed, and would prefer that we reduce the overall size of the interface. I would also prefer to remove the options from the parts, out of a similar preference for minimalism.

I'm looking forward to @ryzokuken 's effort to prototype usage of the Intl.MessageFormat API in the context of rendering to styled React components, and hope this gives us more information on what's really needed.

@eemeli
Copy link
Member

eemeli commented Dec 5, 2023

The methods on MessageValue enable us to define how a function like :number works internally, and how a user could define another custom function like it. For example, its toString() method provides the representation for the placeholder when formatting to a string, while its toParts() method provides its formatted-parts representation.

The output of MF.p.formatToParts() does not include any methods, it's MessagePart[] rather than MessageValue[].

@littledan
Copy link
Member Author

@eemeli Sorry, I missed this response and should've responded a while ago. Why do we have both formatting methods in the options bag, as well as this?

@eemeli
Copy link
Member

eemeli commented Jan 30, 2024

Here's an example message that we need to be able to support, which uses a user-provided :moz:number function that works as both a selector and a formatter:

.input {$num :moz:number}
.match {$num}
one {{You have {$num} thing}}
* {{You have {$num} things}}

To allow for the $num to be used within the message as a selector, and to be formatted either to a string or to parts, the user needs to provide a function in the options bag that can take the actual external value of $num and return a MessageValue. That function gets called when processing the .input line, and the methods on the object it returns are called during selection and formatting.

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

No branches or pull requests

2 participants