Skip to content

Files

Latest commit

f01982f · Aug 5, 2022

History

History
73 lines (55 loc) · 1.48 KB

common.md

File metadata and controls

73 lines (55 loc) · 1.48 KB
id title sidebar_label
common
Common FBT strings
Common 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.json
{
  "Photo": "Still image ...",
  "Video": "Moving pictures ...",
  ...
}

or

// OurCommonStrings.php
<?php

return [
  "Photo": "Still image ...",
  "Video": "Moving pictures ...",
  ...
]

FBT Transform

It accepts these common strings via the main transform, FbtTransform, as an option.

Example setup:

\fbt\FbtConfig::set('fbtCommonPath', '/path/to/OurCommonStrings.json');
// OR inlined...
\fbt\FbtConfig::set('fbtCommon', [
    'Post' => 'Button to post a comment',
]);

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="true">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.