Skip to content

Commit

Permalink
Do not dump non dotted translation keys by default
Browse files Browse the repository at this point in the history
  • Loading branch information
bambamboole committed Aug 23, 2024
1 parent 05a7ac0 commit 044937e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'dump_translations' => env('DUMP_TRANSLATIONS', false),
'dumper' => \Bambamboole\LaravelTranslationDumper\TranslationDumper::class,
'dump_prefix' => 'x-',
'dump_non_dotted_keys' => false,
'ignore_keys' => [
// These keys are used by Laravel validator to check if a custom validation message is present
'validation.custom',
Expand Down
5 changes: 5 additions & 0 deletions src/DumpingTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function __construct(
private readonly TranslationDumperInterface $translationDumper,
private readonly string $dumpPrefix = 'x-',
private readonly array $ignoreKeys = [],
private readonly bool $dumpNonDottedKeys = false,
) {}

public function get($key, array $replace = [], $locale = null, $fallback = true)
Expand Down Expand Up @@ -61,6 +62,10 @@ public function __destruct()

private function shouldBeIgnored(string $key): bool
{
if (! $this->dumpNonDottedKeys && TranslationIdentifier::identify($key) === TranslationType::JSON) {
return true;
}

foreach ($this->ignoreKeys as $ignoreKey) {
if (str_contains($key, $ignoreKey)) {
return true;
Expand Down
1 change: 1 addition & 0 deletions src/LaravelTranslationDumperServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function register(): void
$app->make(TranslationDumperInterface::class),
$app->make(Repository::class)->get('translation.dump_prefix'),
$app->make(Repository::class)->get('translation.ignore_keys'),
$app->make(Repository::class)->get('translation.dump_non_dotted_keys'),
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/DumpingTranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DumpingTranslatorTest extends TestCase
{
private const TEST_LOCALE = 'de';

private const TEST_KEY = 'foo';
private const TEST_KEY = 'foo.bar';

private const TEST_REPLACEMENTS = ['buzz' => 'light year'];

Expand Down

0 comments on commit 044937e

Please sign in to comment.