From 5dc119f1701ae273aafda1afd3df83735ea20f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Dobro=C5=88?= Date: Wed, 21 Jun 2023 21:29:08 +0200 Subject: [PATCH] Add prettyPrint config --- docs/getting_started.md | 3 ++- src/fbt/FbtConfig.php | 5 +++++ src/fbt/Runtime/Shared/FbtHooks.php | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/getting_started.md b/docs/getting_started.md index 3eafba6..eb223bc 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -44,6 +44,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. @@ -65,7 +66,7 @@ use fbt\Runtime\Gender; class UserDTO implements IntlViewerContextInterface { - public function getLocale(): ?string + public function getLocale(): string { return $this->locale; } diff --git a/src/fbt/FbtConfig.php b/src/fbt/FbtConfig.php index 4c9681e..aac071b 100644 --- a/src/fbt/FbtConfig.php +++ b/src/fbt/FbtConfig.php @@ -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'], ...]. */ diff --git a/src/fbt/Runtime/Shared/FbtHooks.php b/src/fbt/Runtime/Shared/FbtHooks.php index b6fe63b..77e5be9 100644 --- a/src/fbt/Runtime/Shared/FbtHooks.php +++ b/src/fbt/Runtime/Shared/FbtHooks.php @@ -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 = [];