fluent.js icon indicating copy to clipboard operation
fluent.js copied to clipboard

@fluent/bundle how to use FluentType.toString

Open danilobuerger opened this issue 4 years ago • 5 comments

Recently Scope was introduced which is now needed to use FluentType.toString. However, Scope is currently not exported. So how can we use toString from outside the library without having access to Scope?

danilobuerger avatar Aug 21 '19 19:08 danilobuerger

What is your the use-case?

We're exposing FluentType so that you can use them to pass "tainted" variables into Fluent, that is, hints about date and number formatting to use in formatPattern in the end.

Pike avatar Aug 22 '19 10:08 Pike

Right now I don't have a special use case. I am just wondering whether toString belongs to the public api, and if so, one should be able to use it.

danilobuerger avatar Aug 24 '19 14:08 danilobuerger

I don't consider Scope to be part of our public API right now.

There's a question of opinion on toString() being part of the public API of any JS object. I wonder what to do about that. I'll leave this open for that. We're probably not going to make changes to this before November.

Pike avatar Aug 26 '19 10:08 Pike

A potential solution could be allowing to pass a Bundle or a Scope. If its a Bundle then inside toString a Scope could easily be created.

danilobuerger avatar Aug 26 '19 10:08 danilobuerger

Let's revisit the parameters to toString when we work on #383. The parts yielded from formatToParts would likely need to be toString'ed, which might mean it would be better to pass a Bundle instance rather than Scope, as you mention. This might also impact how we report errors from formatters.

stasm avatar Dec 13 '19 11:12 stasm