FBT (Facebook's Internationalization Framework) provides a JavaScript runtime for building grammatically correct, translatable user interfaces. Currently at version 1.0.2, this package handles the client-side execution of FBT-transformed strings. It doesn't provide translations itself but offers the APIs to manage them. FBT differentiates itself by enabling translatable text to reside directly within JSX, enhancing searchability and developer experience. It robustly supports complex localization features like plural variations, gender-based pronouns, and enumerations natively. The framework leverages Babel plugins during the build process to extract strings and generate optimized translation payloads, which are then utilized by this runtime package.
npm install fbtVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic FBT usage within a React component, showing both JSX and functional API for internationalized strings, along with essential FBT runtime initialization and locale display.
Ensure your build pipeline is correctly configured with `babel-plugin-fbt` and `babel-plugin-fbt-runtime`. Implement the FBT-specific workflow scripts (`fbt-manifest`, `fbt-collect`, `fbt-translate`) to generate translation files before runtime.
Develop a translation workflow to generate `.source_strings.json` using `fbt-collect`, have human translators populate these files for each locale, and then use `fbt-translate` to create the final runtime translation payloads.
Ensure you have the necessary `@types/fbt` package installed (if available) and your `tsconfig.json` includes appropriate settings for JSX (`jsxFactory`, `jsxFragmentFactory`) and `esModuleInterop`. Manual type declaration augmentation might be necessary if `@types/fbt` is insufficient.
Change your import statement to `import fbt from 'fbt';` to ensure the JSX transform correctly identifies the FBT component.
Call `fbt.init({ translations: { ... }, locale: '...' })` once at the very beginning of your application's lifecycle, typically in your main entry file (e.g., `index.js` or `App.js`), before any components using FBT are rendered.Ensure `fbt.init()` is called globally at the application entry point with valid translation data and locale, which sets up the `IntlViewerContext`.