Skip to content

Commit

Permalink
Add prettyPrint config
Browse files Browse the repository at this point in the history
  • Loading branch information
richardDobron committed Jun 21, 2023
1 parent a3db7ae commit f7c5559
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/getting_started.md
Expand Up @@ -40,6 +40,7 @@ The following options can be defined:
Below are the less important parameters.

* **collectFbt** `bool`: (Default: `true`) Collect fbt instances from the source and store them to a JSON file.
* **prettyPrint** `bool`: (Default: `true`) Pretty print source strings in a JSON file.
* **hash_module** `string`: (Default: `md5`) Hash module.
* **md5_digest** `string`: (Default: `hex`) MD5 digest.
* **driver** `string`: (Default: `json`) Currently, only JSON storage is supported.
Expand All @@ -61,7 +62,7 @@ use fbt\Runtime\Gender;

class UserDTO implements IntlViewerContextInterface
{
public function getLocale(): ?string
public function getLocale(): string
{
return $this->locale;
}
Expand Down
5 changes: 5 additions & 0 deletions src/fbt/FbtConfig.php
Expand Up @@ -55,6 +55,11 @@ class FbtConfig
*/
'path' => null,

/*
* Pretty print source strings in a JSON file.
*/
'prettyPrint' => true,

/*
* Common string's, e.g. [['text' => 'desc'], ...].
*/
Expand Down
8 changes: 7 additions & 1 deletion src/fbt/Runtime/Shared/FbtHooks.php
Expand Up @@ -185,7 +185,13 @@ public static function storePhrases()
$parentIds[$index] = self::savePhrase($phrase, $parentIds[$parentKey] ?? null);
}

file_put_contents($file, json_encode(self::$sourceStrings), LOCK_EX);
$flags = 0;

if (FbtConfig::get('prettyPrint')) {
$flags |= JSON_PRETTY_PRINT;
}

file_put_contents($file, json_encode(self::$sourceStrings, $flags), LOCK_EX);

FbtTransform::$childToParent = [];
FbtTransform::$phrases = [];
Expand Down

0 comments on commit f7c5559

Please sign in to comment.