Use fbt in component libraries? #219
Replies: 2 comments 2 replies
-
Hi @alexandernanberg! I just started working on something similar: https://github.com/adeira/sx-design I also wanted to have FBT behind the scenes because it's so good. And you are right it's necessary to call Basically, this change will allow you to take the existing translations and merge them together with the translations from your component library (since FBT cannot live inside another FBT). Unfortunately, it's not been released yet and it's available only on master. In a meantime, you can merge both of these translations together manually. |
Beta Was this translation helpful? Give feedback.
-
I might give that a shot once it's released then. Thinking if there should be an option to scope fbt to a single module/package. Maybe something like import {createFbt} from 'fbt'
const fbt = createFbt(translations)
function App() {
return <fbt desc="Welcome message">Hello world</fbt>
} I guess the core issue is that fbt uses a singleton for translations, but with the above it would be simpler for libs to use fbt |
Beta Was this translation helpful? Give feedback.
-
I'd really like to use
fbt
in component libraries that bundles their own translations, but from what I can tell this isn't possible since you need to runinit
etc etcThe API I want to expose from the component lib looks something like this
the
LocaleProvider
passes down the locale thru context and theDatePicker
picks it up. The date picker then formats all strings/dates with the provided locale (the component contains all the necessary translations for the locale)Has anyone built something similar to this? Or would it even be possible?
Beta Was this translation helpful? Give feedback.
All reactions