Skip to content

Conversation

@lionel-rowe
Copy link
Contributor

  • Param types fixed (first arg is context: MessageFunctionContext, not locales: string[])
  • Return type fixed — only including toString doesn't work with format or formatToParts
  • Use toLocaleUpperCase with the locales available in the context, rather than locale-less toUpperCase

It seems like building on top of the built-in DefaultFunctions.string is the simplest way to implement a custom string -> string function that correctly implements the contract expected by format and formatToParts. The returned object for input "{messageformat :uppercase}" looks roughly like this:

{
  type: "string",
  source: "|messageformat|",
  dir: "auto",
  selectKey: (keys) => (keys.has(selStr) ? selStr : null),
  toParts: () => [{ type: "string", source: "|messageformat|", locale: "en", value: "MESSAGEFORMAT" }],
  toString: () => "MESSAGEFORMAT",
  valueOf: () => "MESSAGEFORMAT"
}

Copy link
Collaborator

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lucacasonato lucacasonato merged commit 9db404f into unicode-org:main Nov 14, 2025
1 check passed
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 this pull request may close these issues.

3 participants