Skip to main content
Internationalization framework for PHP

FBT for PHP

Translate whole sentences, with plurals, genders and names, so that your PHP app reads naturally in every language.

composer require richarddobron/fbt

FBT in action

Write the text once in English. Translators get whole sentences with the variations their language needs, and FBT picks the right one at runtime.

PHP
fbt(
'You have ' .
fbt::plural('unread message', $count, [
'many' => 'unread messages',
'showCount' => 'yes',
'name' => 'count',
]) . '.',
'Unread messages in the inbox',
);
Output · Slovenčina
  • $count = 1
    Máš 1 neprečítanú správu.
  • $count = 3
    Máš 3 neprečítané správy.
  • $count = 5
    Máš 5 neprečítaných správ.
  • $count = 21
    Máš 21 neprečítaných správ.

English and German have two forms. Slovak has three (1, 2–4, 5+), Russian uses the form of 1 also for 21, Turkish keeps the noun singular after a number, and Japanese has no plural at all. Translators just fill in the forms of their language.

The same works with <fbt> in HTML templates. The outputs above are rendered by fbt.

Why FBT?

Getting grammatically correct translations in dynamic applications is hard. Let FBT do the hard work.

Inline translations

Write texts right where they're used, in PHP with fbt() or in HTML templates with <fbt>. No translation keys, no language files to keep in sync.

Grammar done right

Plurals, genders and names are variations translators fill in. Every language gets correct sentences, even with three plural forms or gendered verbs.

Proven at Facebook

A port of fbt, the framework Facebook built to translate its apps, and of fbtee, its maintained fork. Same source strings, same translation formats.

Easy setup

One Composer package and CLI commands to collect texts, generate translation files and build the translations.

Translate in context

Inline translating lets translators edit texts right on the page, where they see how they're used.

Works with your stack

Plain PHP, HTML templates and Latte, with hooks to store phrases and translations anywhere. For Laravel, use FBT for Laravel.

Get started in minutes

In any PHP application, or in Laravel.

composer require richarddobron/fbt

# Wrap texts with fbt(...), then collect them
php ./vendor/bin/fbt collect-fbts --path=./storage/fbt/ --src=./src/
php ./vendor/bin/fbt generate-translations --src=./storage/fbt/.source_strings.json --translations=./translations/*.json

# Translate translations/*.json, then
php ./vendor/bin/fbt translate --path=./storage/fbt/ --translations=./translations/*.json

Read the full guide →

Let your coding agent set it up

Paste this prompt into Claude Code, Cursor or Copilot, it installs fbt and wraps the texts of your app.

Prompt
Add internationalization to this PHP app with fbt (docs: https://richarddobron.github.io/fbt/). For a Laravel app,
use laravel-fbt instead (https://richarddobron.github.io/laravel-fbt/).

1. Install it with `composer require richarddobron/fbt`.
2. Configure it at the start of the application: ` btFbtConfig::set('author', ...)`, `'project'`, `'path'` (storage
of the collected texts and translations) and `'locale'` (the locale of the current request).
3. Make the user class implement `fbtLibIntlViewerContextInterface` (`getLocale()` and `getGender()`) and set it
as the viewer context with ` btFbtConfig::set('viewerContext', $user)`, so that texts use the locale and the
gender of the signed-in user.
4. Wrap every user-facing text in `fbt('Text', 'Description')`, or in `<fbt desc="Description">Text</fbt>` between
`fbtTransform()` and `endFbtTransform()` in templates. Use `fbs()` for plain text (e.g. HTML attributes).
Every text needs a description which explains its context to translators.
5. Never concatenate translated fragments, keep whole sentences in one fbt. Use `fbt::param()` for values,
`fbt::plural()` for counts, `fbt::name()` for names of people (with their gender), `fbt::enum()` and
`fbt::pronoun()`.
6. Collect the texts with `php ./vendor/bin/fbt collect-fbts --path=<path> --src=<source directory>`, generate the
missing translations with `php ./vendor/bin/fbt generate-translations` and build the translations with
`php ./vendor/bin/fbt translate --path=<path> --translations=<translation files>`.

Based on Facebook's fbt

Facebook

and its maintained fork fbtee