Top Related Projects
🌍 📖 A readable, automated, and optimized (3 kb) internationalization for JavaScript
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Give your JavaScript the ability to speak many languages.
i18next: learn once - translate everywhere
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Quick Overview
FBT (Facebook Translation) is an internationalization framework designed for efficient translation and localization of web applications. It provides a set of tools and APIs to manage translations, handle plurals, and optimize the localization process for large-scale applications.
Pros
- Seamless integration with React and other JavaScript frameworks
- Powerful handling of complex pluralization and gender cases
- Efficient runtime performance with minimal overhead
- Supports extraction and management of translatable strings
Cons
- Steeper learning curve compared to simpler i18n solutions
- Limited community support outside of Facebook's ecosystem
- Requires additional build steps and tooling setup
- Documentation can be sparse for advanced use cases
Code Examples
- Basic text translation:
import fbt from 'fbt';
function Welcome() {
return <div>{fbt('Welcome to our website!', 'Greeting message')}</div>;
}
- Handling plurals:
import {fbt, plural} from 'fbt';
function ItemCount({count}) {
return (
<fbt desc="Item count message">
You have{' '}
<fbt:plural count={count} many="items">
<fbt:param name="count" number={count} />
{count === 1 ? 'item' : 'items'}
</fbt:plural>
.
</fbt>
);
}
- Using parameters:
import fbt from 'fbt';
function Greeting({name}) {
return (
<fbt desc="Greeting with name">
Hello, <fbt:param name="name">{name}</fbt:param>!
</fbt>
);
}
Getting Started
-
Install FBT:
npm install fbt babel-plugin-fbt babel-plugin-fbt-runtime
-
Configure Babel in your
.babelrc
:{ "plugins": [ ["fbt", { "fbtEnumManifest": "./fbt/enum-manifest.json" }], "fbt-runtime" ] }
-
Use FBT in your React components:
import fbt from 'fbt'; function MyComponent() { return <div>{fbt('Hello, world!', 'Greeting')}</div>; }
-
Run the FBT collection command to extract translatable strings:
node ./node_modules/.bin/fbt-collect --options-path .fbt
Competitor Comparisons
🌍 📖 A readable, automated, and optimized (3 kb) internationalization for JavaScript
Pros of js-lingui
- More flexible and easier to integrate with various JavaScript frameworks
- Supports both ICU MessageFormat and custom plurals
- Offers a command-line interface for managing translations
Cons of js-lingui
- Less optimized for large-scale applications compared to fbt
- May require more setup and configuration
- Lacks some advanced features present in fbt, such as inline translations
Code Comparison
js-lingui:
import { t } from "@lingui/macro";
function Welcome({ name }) {
return <h1>{t`Hello ${name}`}</h1>;
}
fbt:
const fbt = require('fbt');
function Welcome({ name }) {
return <h1><fbt desc="Welcome message">Hello <fbt:param name="name">{name}</fbt:param></fbt></h1>;
}
Key Differences
- Syntax: js-lingui uses a more straightforward template literal approach, while fbt employs XML-like tags
- Configuration: js-lingui typically requires more initial setup but offers greater flexibility
- Performance: fbt is generally more performant for large-scale applications
- Framework support: js-lingui is more adaptable to various JavaScript frameworks, while fbt is primarily designed for React applications
- Learning curve: js-lingui may be easier for developers to pick up, especially those familiar with ICU MessageFormat
Both libraries aim to solve internationalization challenges in JavaScript applications, but they cater to different project scales and developer preferences.
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Pros of FormatJS
- Wider ecosystem support with integrations for various frameworks (React, Vue, Angular)
- More comprehensive internationalization features, including pluralization and gender-aware formatting
- Active community and frequent updates
Cons of FormatJS
- Steeper learning curve due to more complex API
- Potentially larger bundle size when using all features
Code Comparison
FBT:
<fbt desc="Welcome message">
Hello, <fbt:name>name</fbt:name>!
</fbt>
FormatJS:
<FormattedMessage
id="welcome"
defaultMessage="Hello, {name}!"
values={{ name: userName }}
/>
Summary
FormatJS offers a more comprehensive internationalization solution with broader framework support, while FBT provides a simpler API focused primarily on React applications. FormatJS excels in handling complex localization scenarios but may require more setup and learning. FBT, being developed by Facebook, integrates seamlessly with React but has a more limited feature set. The choice between the two depends on the specific project requirements, target frameworks, and the complexity of internationalization needs.
Give your JavaScript the ability to speak many languages.
Pros of Polyglot.js
- Lightweight and simple to use, with a smaller learning curve
- Supports pluralization and interpolation out of the box
- Can be easily integrated into various JavaScript frameworks
Cons of Polyglot.js
- Less powerful for complex localization scenarios
- Lacks advanced features like gender-aware translations
- No built-in extraction tools for managing translations
Code Comparison
Polyglot.js:
const polyglot = new Polyglot();
polyglot.extend({"hello": "Hello"});
polyglot.t("hello"); // "Hello"
FBT:
import fbt from 'fbt';
<fbt desc="Greeting">Hello</fbt>
Key Differences
- FBT is more tightly integrated with React and Facebook's ecosystem
- Polyglot.js is more flexible and can be used in various JavaScript environments
- FBT offers more advanced features for complex localization scenarios
- Polyglot.js has a simpler API and is easier to get started with
Use Cases
- Choose Polyglot.js for simpler projects or when working with various JavaScript frameworks
- Opt for FBT when dealing with complex localization needs, especially in React applications
Community and Support
- Polyglot.js has a larger community and more third-party resources
- FBT has strong backing from Facebook and is used in large-scale applications
i18next: learn once - translate everywhere
Pros of i18next
- Broader ecosystem with numerous plugins and integrations
- More flexible and adaptable to various frameworks and environments
- Active community and frequent updates
Cons of i18next
- Steeper learning curve for complex localization scenarios
- Less optimized for compile-time extraction compared to fbt
Code Comparison
i18next:
import i18next from 'i18next';
i18next.init({
lng: 'en',
resources: {
en: {
translation: {
key: 'Hello, {{name}}!'
}
}
}
});
console.log(i18next.t('key', { name: 'John' }));
fbt:
const fbt = require('fbt');
<fbt desc="Greeting">
Hello, <fbt:param name="name">John</fbt:param>!
</fbt>
Key Differences
- i18next uses a key-based approach, while fbt uses JSX-like syntax
- fbt is more tightly integrated with React and Facebook's tooling
- i18next offers more flexibility for various project types and frameworks
- fbt provides stronger type checking and compile-time optimizations
Both libraries are powerful internationalization solutions, but i18next is more versatile across different environments, while fbt excels in React-based projects with a focus on performance and static analysis.
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Pros of FormatJS
- Wider ecosystem support with integrations for various frameworks (React, Vue, Angular)
- More comprehensive internationalization features, including pluralization and gender-aware formatting
- Active community and frequent updates
Cons of FormatJS
- Steeper learning curve due to more complex API
- Potentially larger bundle size when using all features
Code Comparison
FBT:
<fbt desc="Welcome message">
Hello, <fbt:name>name</fbt:name>!
</fbt>
FormatJS:
<FormattedMessage
id="welcome"
defaultMessage="Hello, {name}!"
values={{ name: userName }}
/>
Summary
FormatJS offers a more comprehensive internationalization solution with broader framework support, while FBT provides a simpler API focused primarily on React applications. FormatJS excels in handling complex localization scenarios but may require more setup and learning. FBT, being developed by Facebook, integrates seamlessly with React but has a more limited feature set. The choice between the two depends on the specific project requirements, target frameworks, and the complexity of internationalization needs.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
FBT is an internationalization framework for JavaScript designed to be not just powerful and flexible, but also simple and intuitive. It helps with the following:
- Organizing your source text for translation
- Composing grammatically correct translatable UI
- Eliminating verbose boilerplate for generating UI
Online Resources
Examples
Requirements
Building the fbt library
git clone git@github.com:facebook/fbt.git
cd fbt
yarn install
NOTE: if you make changes to the fbt runtime that you'd like to test in the demo-app, be sure to run this command to rebuild the JS code:
yarn build-runtime
Using fbt
See how to use the source directly with Babel and Webpack in our demo-app.
How FBT works
FBT works by transforming your <fbt>
and fbt(...)
constructs via
Babel plugins. These plugins serve to extract strings from source and
lookup translated payloads generated at build-time. FBT creates tables
of all possible variations for the given fbt phrase and accesses this
at runtime.
Join the fbt community
See the CONTRIBUTING file for how to help out.
Change log
See CHANGELOG.
List of npm modules published from this repo:
- babel-plugin-fbt (build-time / server-side)
- See package.json
- babel-plugin-fbt-runtime (server-side)
- See package.json
- @fbtjs/default-collection-transform (build-time)
- See package.json
- fb-babel-plugin-utils (server-side, used by
babel-plugin-fbt-runtime
)- See package.json
- fbt (client-side)
- See package.json
- fb-tiger-hash (build-time)
- See package.json
- gulp-rewrite-flowtyped-modules (build-time)
- See package.json
- gulp-strip-docblock-pragmas (build-time)
- See package.json
- react-native-fbt (build-time)
- See package.json
License
FBT is MIT licensed, as found in the LICENSE file.
Top Related Projects
🌍 📖 A readable, automated, and optimized (3 kb) internationalization for JavaScript
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Give your JavaScript the ability to speak many languages.
i18next: learn once - translate everywhere
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot