Skip to content

Commit

Permalink
Merge pull request #33 from Laravel-Lang/1.x
Browse files Browse the repository at this point in the history
Added a new parameter for filtering relations
  • Loading branch information
andrey-helldar authored Aug 31, 2024
2 parents df5efcb + a017109 commit ee2ab72
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
11 changes: 11 additions & 0 deletions config/public.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 2 additions & 1 deletion src/Data/Shared/ModelsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ModelsData
{
public function __construct(
public string $suffix,
public string $helpers
public string $helpers,
public ModelsFilterData $filter,
) {}
}
12 changes: 12 additions & 0 deletions src/Data/Shared/ModelsFilterData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace LaravelLang\Config\Data\Shared;

class ModelsFilterData
{
public function __construct(
public bool $enabled,
) {}
}
9 changes: 9 additions & 0 deletions src/Services/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use LaravelLang\Config\Data\Hidden\ModelsData as HiddenModelsData;
use LaravelLang\Config\Data\HiddenData;
use LaravelLang\Config\Data\Shared\ModelsData;
use LaravelLang\Config\Data\Shared\ModelsFilterData;
use LaravelLang\Config\Data\Shared\RouteNameData;
use LaravelLang\Config\Data\Shared\RoutesData;
use LaravelLang\Config\Data\Shared\SmartPunctuationData;
Expand Down Expand Up @@ -96,6 +97,14 @@ protected function models(): ModelsData
return new ModelsData(
suffix : $this->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'),
);
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/SharedWithEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 () {
Expand Down
12 changes: 7 additions & 5 deletions tests/Unit/SharedWithoutEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -126,18 +130,16 @@
->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)
->enabled->toBeFalse()
->priority->toBe(3)
->translator->toBe('\LaravelLang\Translator\Integrations\Yandex')
->credentials->toBe([
'key' => null,
'folder' => null,
'key' => '',
'folder' => '',
]);
});

Expand Down

0 comments on commit ee2ab72

Please sign in to comment.