Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Some translations have been lost in the new version (10.0) #1762

Merged
merged 23 commits into from Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions app/keys.php
@@ -1,10 +1,10 @@
<?php

use LaravelLang\Lang\Processors\Process;
use LaravelLang\Lang\Processors\Keys;

require __DIR__ . '/../vendor/autoload.php';

/** @var \LaravelLang\Lang\Application $app */
$app = require_once __DIR__ . '/bootstrap/app.php';

$app->processor(Process::make());
$app->processor(Keys::make());
8 changes: 5 additions & 3 deletions app/main/Processors/Excludes.php
Expand Up @@ -32,7 +32,7 @@ protected function process(string $target_path, string $filename, string $locale

$content = $this->merge($this->keys, $target, $filename);

$this->sort($content);
$this->sort($content, false);
andrey-helldar marked this conversation as resolved.
Show resolved Hide resolved

$this->store($target_path, array_values($content), $this->stub, true);
}
Expand All @@ -42,7 +42,7 @@ protected function merge(array $source, array $target, string $filename): array
return array_intersect($source, $target);
}

protected function sort(array &$array): void
protected function sort(array &$array, bool $key = true): void
{
$array = Arr::sort(array_unique($array));
}
Expand Down Expand Up @@ -70,6 +70,8 @@ protected function getSourceKeys(string $filename): array
{
$items = $this->load($this->getSourcePath($filename));

return array_keys($items);
return $this->isJson($filename)
? array_values($items)
: array_keys($items);
}
}
Expand Up @@ -4,7 +4,7 @@

use Helldar\Support\Facades\Helpers\Filesystem\File;

final class Process extends Processor
final class Keys extends Processor
{
protected string $target_path = 'locales';

Expand All @@ -23,6 +23,6 @@ public function run(): void

protected function files(string $locale): array
{
return File::names($this->getTargetPath($locale), recursive: true);
return File::names($this->getTargetPath($locale));
}
}
5 changes: 3 additions & 2 deletions app/main/Processors/Packages.php
Expand Up @@ -8,6 +8,7 @@
final class Packages extends Processor
{
protected array $packages = [
'laravel/breeze' => 'packages/breeze.json',
'laravel/fortify' => 'packages/fortify.json',
'laravel/jetstream' => 'packages/jetstream.json',
];
Expand All @@ -21,15 +22,15 @@ public function run(): void

$content = $this->map($items);

$this->sort($content);
$this->sort($content, false);

$this->store($path, $content);
}
}

protected function map(array $items): array
{
return Arr::renameKeys($items, static fn ($key, $value) => $value);
return Arr::values($items);
}

protected function files(string $package): array
Expand Down
31 changes: 28 additions & 3 deletions app/main/Processors/Processor.php
Expand Up @@ -5,6 +5,7 @@
use Helldar\Support\Concerns\Makeable;
use Helldar\Support\Facades\Helpers\Arr;
use Helldar\Support\Facades\Helpers\Filesystem\Directory;
use Helldar\Support\Facades\Helpers\Filesystem\File;
use Helldar\Support\Tools\Stub;
use LaravelLang\Lang\Application;
use LaravelLang\Lang\Concerns\Contains;
Expand Down Expand Up @@ -73,7 +74,29 @@ protected function source(string $filename): array
return $this->source[$filename];
andrey-helldar marked this conversation as resolved.
Show resolved Hide resolved
}

return $this->source[$filename] = $this->load($this->getSourcePath($filename));
return $this->source[$filename] = $this->isJson($filename) ? $this->sourceJson() : $this->loadSource($filename);
}

protected function loadSource(string $filename): array
{
return $this->load($this->getSourcePath($filename));
}

protected function sourceJson(): array
{
$path = $this->getSourcePath();

$files = File::names($path, fn ($filename) => $this->isJson($filename), true);

$array = [];

foreach ($files as $file) {
$items = $this->loadSource($file);

$array = Arr::addUnique($array, $items);
}

return Arr::renameKeys($array, static fn ($key, $value) => $value);
}

protected function getFallbackValue(array $source, array $target, string $key)
Expand Down Expand Up @@ -102,9 +125,11 @@ protected function filter(array $first, array $second): array
return Arr::only($first, $keys);
}

protected function sort(array &$array): void
protected function sort(array &$array, bool $key = true): void
{
$array = Arr::ksort($array);
$array = $key
? Arr::ksort($array)
: Arr::sort($array);
}

protected function load(string $path): array
Expand Down
49 changes: 0 additions & 49 deletions app/main/Processors/Splitters/CleanUp.php

This file was deleted.

29 changes: 0 additions & 29 deletions app/main/Processors/Splitters/Locales.php

This file was deleted.

13 changes: 0 additions & 13 deletions app/main/Processors/Splitters/Main.php

This file was deleted.

43 changes: 0 additions & 43 deletions app/main/Processors/Splitters/Processor.php

This file was deleted.

44 changes: 0 additions & 44 deletions app/main/Processors/Splitters/Structure.php

This file was deleted.

2 changes: 1 addition & 1 deletion app/main/Processors/Statuses/Processor.php
Expand Up @@ -122,7 +122,7 @@ protected function files(): array
return $this->source_files;
}

$files = File::names($this->getSourcePath(), recursive: true);
$files = File::names($this->getSourcePath());

$items = Arr::sort($files, function (string $a, string $b) {
$sorter = Sorter::defaultCallback();
Expand Down
21 changes: 13 additions & 8 deletions app/main/Support/Finder.php
Expand Up @@ -16,38 +16,43 @@ class Finder
protected array $files = [];

public function __construct(
protected SymfonyFinder $instance
protected SymfonyFinder $finder
) {
}

public function get(string|array $path): array
{
$this->search($path);

return $this->files();
return $this->files($path);
}

protected function search(string|array $path): void
{
foreach ($this->find($path) as $file) {
$this->push($file->getRealPath());
$this->push($path, $file->getRealPath());
}
}

protected function find(string|array $path): SymfonyFinder
{
return $this->instance->in($path)->files()
return $this->finder()->in($path)->files()
->name($this->names)
->contains($this->contains);
}

protected function push(string $path): void
protected function push(string|array $source, string $path): void
{
$this->files[] = $path;
$this->files[$source][] = $path;
}

protected function files(): array
protected function files(string|array $path): array
{
return $this->files;
return $this->files[$path] ?? [];
}

protected function finder(): SymfonyFinder
{
return clone $this->finder;
}
}
4 changes: 2 additions & 2 deletions app/main/Support/Package.php
Expand Up @@ -9,7 +9,7 @@ class Package
{
protected ?string $path;

protected array $filter = ['$this', 'self::', 'auth.', 'pagination.', 'passwords.', 'validation.'];
protected array $filter = ['$', 'self::', 'static::', 'auth.', 'pagination.', 'passwords.', 'validation.'];

public function __construct(
protected Finder $finder,
Expand Down Expand Up @@ -52,6 +52,6 @@ protected function parsed(array $files): array

protected function filter(array $items): array
{
return array_filter(array_keys($items), fn ($value) => ! Str::startsWith($value, $this->filter));
return array_filter(array_keys($items), fn ($value) => ! Str::contains($value, $this->filter));
}
}