Skip to content

Commit

Permalink
Update FindAndAddLanguageKeysCommand.php
Browse files Browse the repository at this point in the history
  • Loading branch information
wimurk authored Aug 11, 2023
1 parent 48456db commit e8143c5
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Commands/FindAndAddLanguageKeysCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace SingleQuote\LocaleFinder\Commands;

use Exception;
Expand All @@ -10,16 +9,15 @@
use Illuminate\Support\Str;
use Stichoza\GoogleTranslate\GoogleTranslate;
use Symfony\Component\Finder\Finder;

use const PHP_EOL;
use function collect;
use function config;
use function count;
use function str;

use const PHP_EOL;

class FindAndAddLanguageKeysCommand extends Command
{

/**
* @var string
*/
Expand Down Expand Up @@ -127,7 +125,7 @@ private function findKeysInFiles(): array

$functions = config('locale-finder.translation_methods', []);

if(count($path) > 0) {
if (count($path) > 0) {
$finder = new Finder();

$finder->in($path)->exclude(config('locale-finder.search.exclude', []))
Expand Down Expand Up @@ -158,7 +156,7 @@ private function patternKeys(array|Finder $finder, array $functions): array
}

uksort($keys, 'strnatcasecmp');
dump($keys);

return $this->onlyExcept($keys);
}

Expand All @@ -175,8 +173,8 @@ private function onlyExcept(array $keys): array
$only = explode(',', $this->option('only'));

return collect($keys)->filter(function ($value, $key) use ($only) {
return $this->filterOnlyOnPrefix($key, $only);
})->toArray();
return $this->filterOnlyOnPrefix($key, $only);
})->toArray();
}

/**
Expand Down Expand Up @@ -211,8 +209,8 @@ private function matchPatternKeysByContent(array $functions, array &$keys, strin
private function replaceMatchingBeforeFinding(string $function, string &$content, string $pattern): string
{
return str($content)
->replace("$function($pattern", "translationkeyFindedStart($pattern")
->replace("$pattern)", "{$pattern}translationkeyFindedEnd")
->replace("$function($pattern", "translationkeyFindedStart($pattern")
->replace("$pattern)", "{$pattern}translationkeyFindedEnd")
->value;
}

Expand Down Expand Up @@ -569,7 +567,7 @@ private function translateKey(string $locale, string $key): string
$translated = $key;
}

if(!$translated) {
if (!$translated) {
$translated = $key;
}

Expand Down

0 comments on commit e8143c5

Please sign in to comment.