Upgrade @fluent/react, @fluent/bundle#2631
Conversation
web/src/components/app.tsx
Outdated
| LocalePropsFromState, | ||
| } from './locale-helpers'; | ||
| import { Flags } from '../stores/flags'; | ||
| import { LocalizationProvider } from '@fluent/react'; |
There was a problem hiding this comment.
I dropped the compat build here and everywhere else in voice-web/web. I don't think it's actually needed, and it looks like your build system is capable of transpiling node_modules just fine?
The main reason why I'd prefer not to use compat is that its not currently typed automatically by @fluent/react's build pipeline. I.e. .d.ts files are only produced for the non-compat build.
| discourseLink: <DiscourseLink />, | ||
| githubLink: <GitHubLink />, | ||
| matrixLink: <MatrixLink /> | ||
| }}> |
There was a problem hiding this comment.
The new API is more explicit about the elements passed into translations.
| id="help-reach-hours" | ||
| $hours={10000} | ||
| $language={getString(locale)}> | ||
| vars={{hours: 10000, language: getString(locale)}}> |
There was a problem hiding this comment.
The new API is more explicit about the variables passed into translations as arguments.
| for (const [locale, messages] of localeMessages) { | ||
| const bundle = new FluentBundle(locale, { useIsolating: false }); | ||
| bundle.addMessages( | ||
| bundle.addResource(new FluentResource( |
There was a problem hiding this comment.
This is the FluentBundle API since version 0.14.
|
This is awesome, thanks Stas! |
065b9e0 to
31f7187
Compare
|
I think this is now ready for a review. I tested this locally after merging master into the branch (I didn't include the merge in the PR), and things looked good. I don't know the whole app, however, so I'll be happy to do more manual testing if you'd like me to. |
|
@phirework Can you help me find a reviewer for this, please? |
|
@stasm Apologies for the delay, I'll take a more detailed look today or tomorrow. We've been busy with our migration to Kubernetes and I didn't want to merge in a big change before also changing server environments. |
|
Of course, no worries! I just wanted to make sure this is on your radar. I've also just checked locally, and it looks like there haven't been any new |
|
Sorry for the late update! So I've finally had a chance to look through everything in more detail. Thanks again for doing this work. So the big piece blocking this is that not all of the places we make use of the Off the top of my head, the most fail-safe way to look for all of these would be to start with |
|
It should be fairly easy for me to collect the names of variables and elements used in all messages, and then grep for them in the code. I didn't realize they were passed like this in objects, thanks for pointing it out. I'm not blocked on this PR, thanks for asking. I already released |
222c1c2 to
a2a4f52
Compare
a2a4f52 to
3217a40
Compare
|
I updated the PR to fix the cases where the props to One tricky piece of code was this one: It kind of demonstrates why the old API wasn't ergnomic. In the new API, the above becomes simply: <Localized
id="dataset-description-hours"
vars={globalStats}
elems={{b: <b />}}
>I also found two messages which may need some work:
@phirework Would you mind taking another look at this? |
|
This is awesome, thank you! I will take care of cleaning those two instances up separately, good catch. Super appreciate all your work here. |
|
Thanks, @phirework! |
In projectfluent/fluent.js#458 I've been working on a new version of
@fluent/react(néfluent-react), rewritten in TypeScript. The rewrite required some API changes, and I usedvoice-webas a test project, given it's a large React app also written in TypeScript.I'm opening this draft PR to share my changes so far. Once the new version of
@fluent/reactis released, I'll be happy to finish working on it.