diff --git a/config/public.php b/config/public.php index 71e8fbb..0eb3cab 100644 --- a/config/public.php +++ b/config/public.php @@ -153,6 +153,17 @@ 'suffix' => 'Translation', + /* + * This option determines the need to filter localizations loaded + * in the relay when using eager loading. + * + * By default, true. + */ + + 'filter' => [ + 'enabled' => (bool) env('LOCALIZATION_FILTER_ENABLED', true), + ], + /* * This option specifies a folder to store helper files for the IDE. * diff --git a/src/Data/Shared/ModelsData.php b/src/Data/Shared/ModelsData.php index 246807e..b3c7a58 100644 --- a/src/Data/Shared/ModelsData.php +++ b/src/Data/Shared/ModelsData.php @@ -8,6 +8,7 @@ class ModelsData { public function __construct( public string $suffix, - public string $helpers + public string $helpers, + public ModelsFilterData $filter, ) {} } diff --git a/src/Data/Shared/ModelsFilterData.php b/src/Data/Shared/ModelsFilterData.php new file mode 100644 index 0000000..a44f3db --- /dev/null +++ b/src/Data/Shared/ModelsFilterData.php @@ -0,0 +1,12 @@ +value(Name::Shared, 'models.suffix', fallback: 'Translation'), helpers: $this->value(Name::Shared, 'models.helpers', fallback: Path::helpers()), + filter : $this->modelsFilter(), + ); + } + + protected function modelsFilter(): ModelsFilterData + { + return new ModelsFilterData( + enabled: $this->value(Name::Shared, 'models.filter.enabled'), ); } diff --git a/tests/Unit/SharedWithEnvTest.php b/tests/Unit/SharedWithEnvTest.php index 4ddc5bc..5ab1a8c 100644 --- a/tests/Unit/SharedWithEnvTest.php +++ b/tests/Unit/SharedWithEnvTest.php @@ -113,6 +113,7 @@ test('models', function () { config()->set(Name::Shared() . '.models.suffix', 'qwerty'); config()->set(Name::Shared() . '.models.helpers', realpath(dirname(__DIR__))); + config()->set(Name::Shared() . '.models.filter.enabled', false); expect(Config::shared()->models->suffix) ->toBeString() @@ -123,6 +124,10 @@ ->toBeString() ->toBe(realpath(dirname(__DIR__))) ->toBe(config('localization.models.helpers')); + + expect(Config::shared()->models->filter) + ->enabled->toBeFalse() + ->enabled->toBe(config('localization.models.filter.enabled')); }); test('translators: all', function () { diff --git a/tests/Unit/SharedWithoutEnvTest.php b/tests/Unit/SharedWithoutEnvTest.php index 83a16af..1004a5b 100644 --- a/tests/Unit/SharedWithoutEnvTest.php +++ b/tests/Unit/SharedWithoutEnvTest.php @@ -111,6 +111,10 @@ ->toBeString() ->toBe(realpath(dirname(__DIR__))) ->toBe(config('localization.models.helpers')); + + expect(Config::shared()->models->filter) + ->enabled->toBeTrue() + ->enabled->toBe(config('localization.models.filter.enabled')); }); test('translators: all', function () { @@ -126,9 +130,7 @@ ->enabled->toBeFalse() ->priority->toBe(2) ->translator->toBe('\LaravelLang\Translator\Integrations\Deepl') - ->credentials->toBe([ - 'key' => null, - ]); + ->credentials->key->toBeEmpty(); expect(Config::shared()->translators->channels->all['yandex']) ->toBeInstanceOf(TranslatorData::class) @@ -136,8 +138,8 @@ ->priority->toBe(3) ->translator->toBe('\LaravelLang\Translator\Integrations\Yandex') ->credentials->toBe([ - 'key' => null, - 'folder' => null, + 'key' => '', + 'folder' => '', ]); });