fbtee - React Internationalization Framework

1.7.3 · active · verified Sun Apr 19

fbtee (Far Better Translations, Extended Edition) is a robust internationalization framework for JavaScript and React applications, currently stable at version 1.7.3. It differentiates itself by building upon Facebook's battle-tested `fbt` library, which has served billions of users in production environments for over a decade. The framework emphasizes an intuitive developer experience through inline translations embedded directly in code, eliminating the need for translation keys or wrapper functions. It uses a compiler-based approach to extract translatable strings and optimizes runtime performance by compiling translations into an Intermediate Representation. fbtee supports dynamic content, pluralization, lists, and provides straightforward integration with modern build tools like Vite and Next.js, often with pre-configured templates available for quick setup. It maintains an active development cycle with regular releases, enhancing features and streamlining the i18n workflow.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to set up `fbtee` in a Vite project with React 19, including the necessary Babel preset configuration, and how to use the `fbt` component with `FbtParam` for dynamic internationalized strings.

/*
  package.json (excerpt for context):
  {
    "name": "fbtee-quickstart",
    "private": true,
    "version": "0.0.0",
    "type": "module",
    "scripts": {
      "dev": "vite",
      "build": "tsc && vite build",
      "collect": "fbtee collect",
      "translate": "fbtee translate"
    },
    "dependencies": {
      "fbtee": "^1.7.3",
      "react": "^19.0.0",
      "react-dom": "^19.0.0"
    },
    "devDependencies": {
      "@nkzw/babel-preset-fbtee": "^1.7.3",
      "@vitejs/plugin-react": "^4.2.1",
      "typescript": "^5.2.2",
      "vite": "^5.2.0"
    }
  }
*/

// vite.config.ts
import fbteePreset from '@nkzw/babel-preset-fbtee';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    react({
      babel: {
        presets: [fbteePreset]
      }
    })
  ]
});

// src/App.tsx
import { fbt, FbtParam } from 'fbtee';
import React from 'react';

const Name = ({ name }: { name: string }) => (
  <FbtParam name="name">{name}</FbtParam>
);

const App = () => {
  const userName = 'Alice';
  const itemCount = 5;

  return (
    <div style={{ fontFamily: 'sans-serif', padding: '20px' }}>
      <h1>
        <fbt desc="Welcome title">
          Welcome to <FbtParam name="app">fbtee Demo</FbtParam>!
        </fbt>
      </h1>
      <p>
        <fbt desc="Greeting message">
          Hello, <Name name={userName} />! You have{' '}
          <FbtParam name="count" number={itemCount}>
            {itemCount}
          </FbtParam>{' '}
          new items in your cart.
        </fbt>
      </p>
      <p>
        <fbt desc="Simple goodbye message">Goodbye!</fbt>
      </p>
      <button onClick={() => alert('Locale switching not implemented in this snippet.')}>
        Switch Locale (conceptual)
      </button>
      <p>
        <em>Remember to run `npm run collect` and `npm run translate`!</em>
      </p>
    </div>
  );
};

export default App;

view raw JSON →