Integrating into your app
We recommend you read the best practices for advice on how to best prepare your applications. We strongly encourage you to do so.
π¦ Installing
These steps are required:
- Publish config file:
- We recommend setting the author and project options in /config/fbt.php.
- Run migrations:
π§ Configuration
Options
The following options can be defined:
- project
string
: (Default:website app
) Project to which the text belongs - author
string
: Text author - preserveWhitespace
bool
: (Default:false
)- FBT normally consolidates whitespace down to one space (
' '
). - Turn this off by setting this to
true
- FBT normally consolidates whitespace down to one space (
- viewerContext
string
: (Default:\fbt\Runtime\Shared\IntlViewerContext::class
) - locale
string
: (Default:en_US
) User locale. - fbtCommon
string
: (Default:[]
) common string's, e.g.[['text' => 'desc'], ...]
- fbtCommonPath
string
: (Default:null
) Path to the common string's module.
Below are the less important parameters.
- logger
bool
: (Default:false
) Logging of string impressions. - collectFbt
bool
: (Default:true
) Collect fbt instances from the source and store them in a database or a JSON file. - hash_module
string
: (Default:md5
) Hash module. - md5_digest
string
: (Default:hex
) MD5 digest. - driver
string
: (Default:json
) Driver. - path
string
: Cache storage path for generated translations & source strings.
π IntlInterface
Optional implementation of IntlInterface on User Model.
Example code:
Note: auth()->user()
will be attached to viewerContext
automatically.
π Artisan Commands
- This command collects FBT strings across whole application in PHP files.
Read more about FBTs extracting.
- This command generates the missing translation hashes from collected source strings.
- This command creates translation payloads stored in database/JSON file.
Read more about translating.
π API
- fbt(...);
- fbt::param(...);
- fbt::enum(...);
- fbt::name(...);
- fbt::plural(...);
- fbt::pronoun(...);
- fbt::sameParam(...);
- fbt::c(...);
π¨ Blade Directives
@fbtTransform & @endFbtTransform
@fbtTransform: This directive will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.
@endFbtTransform: This directive will send the contents of the topmost output buffer (if any) and turn this output buffer off.
@fbt
Encoding in Blade
PhpStorm integration
The PhpStorm IDE can recognize the custom Blade directive if is set in File > Settings > Languages & Frameworks > PHP > Blade > Directives by adding a new one with the following properties:
- Name: fbt
- Has parameters: yes
- Prefix:
<?php echo \fbt(
- Suffix:
); ?>
- Name: fbs
- Has parameters: yes
- Prefix:
<?php echo \fbs(
- Suffix:
); ?>
- Name: fbtTransform
- Has parameters: no
- Name: endFbtTransform
- Has parameters: no