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"
}

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.

2 participants