Commit 9db404f
authored
* 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:
```ts
{
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"
}
```
1 parent 376fff2 commit 9db404f
1 file changed
+11
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
192 | 194 | | |
193 | 195 | | |
194 | 196 | | |
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| 201 | + | |
| 202 | + | |
199 | 203 | | |
200 | 204 | | |
201 | 205 | | |
| |||
0 commit comments