Common FBT strings

The fbt framework provides a way to define common simple strings in one shared location. The expected format is as a text to description map.

E.g

// OurCommonStrings.js
module.exports = {
"Photo": "Still image ...",
"Video": "Moving pictures ...",
...
};

FBT Transform

It accepts these common strings via the main Babel transform, babel-plugin-fbt, as a plugin option.

Example Babel setup:

{
plugins: [
['babel-plugin-fbt', {
fbtCommonPath: "/path/to/OurCommonStrings.js",
// OR inlined...
fbtCommon: {
"Photo": "...",
...
},
...
}],
...
]
}

Runtime API

To use the strings at runtime, there is the fbt.c(...) function call or the <fbt common=true>...</fbt> JSX API.

NOTE: The transform will throw if it encounters a common string not in the map provided.

E.g.

<button>
{fbt.c('Photo')}
</button>

or

<button>
<fbt common>Photo</fbt>
</button>

Both examples above function as if the engineer had also included the description with the text.

<fbt desc="Still image ...">Photo</fbt>

All of these instances would produce the same identifying hash at collection time, and thus coalesce into the same translation.

Last updated on by David Han Sze Chuen