Skip to content

Fix/update uppercase custom function example per latest messageformat@next #46

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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