Skip to content

Commit

Permalink
Merge pull request #1748 from andrey-helldar/patch/2021-05-13/20-09
Browse files Browse the repository at this point in the history
Splitting projects
  • Loading branch information
caouecs committed May 20, 2021
2 parents ffee21f + 7dfe19c commit 8d81938
Show file tree
Hide file tree
Showing 661 changed files with 120,122 additions and 59,658 deletions.
36 changes: 20 additions & 16 deletions .github/workflows/self-update.yml
Expand Up @@ -30,64 +30,68 @@ jobs:
- name: Install dependencies
run: composer update --prefer-stable --prefer-dist --no-progress --no-interaction

- name: Keys actualization
- name: Scanning packages
id: commit_packages
if: success()
run: php app/keys.php
run: |
IS_DIRTY=1
php app/packages.php
{ git add . && git commit -a -m "Updating package files"; } || IS_DIRTY=0
- name: Commit files after checking keys
echo ::set-output name=is_dirty::${IS_DIRTY}
- name: Keys actualization
id: commit_keys
if: success()
run: |
IS_DIRTY=1
php app/keys.php
{ git add . && git commit -a -m "Updating translations keys"; } || IS_DIRTY=0
echo ::set-output name=is_dirty::${IS_DIRTY}
- name: Updating referents
if: success()
run: php app/referents.php

- name: Commit files after referents update
id: referents
if: success()
run: |
IS_DIRTY=1
php app/referents.php
{ git add . && git commit -a -m "Updating the `docs/referents.md` file"; } || IS_DIRTY=0
echo ::set-output name=is_dirty::${IS_DIRTY}
- name: Checking for excludes
if: success()
run: php app/excludes.php

- name: Commit files after checking for excludes
id: excludes
if: success()
run: |
IS_DIRTY=1
php app/excludes.php
{ git add . && git commit -a -m "Updating excludes files"; } || IS_DIRTY=0
echo ::set-output name=is_dirty::${IS_DIRTY}
- name: Status update
if: success()
run: php app/status.php

- name: Commit file
id: commit_status
if: success()
run: |
IS_DIRTY=1
php app/status.php
{ git add . && git commit -a -m "Updated status of translations"; } || IS_DIRTY=0
echo ::set-output name=is_dirty::${IS_DIRTY}
- name: Push changes
uses: ad-m/github-push-action@master
if: success() && (steps.commit_keys.outputs.is_dirty == 1 || steps.referents.outputs.is_dirty == 1 || steps.excludes.outputs.is_dirty == 1 || steps.commit_status.outputs.is_dirty == 1)
if: success() && (steps.commit_packages.outputs.is_dirty == 1 || steps.commit_keys.outputs.is_dirty == 1 || steps.referents.outputs.is_dirty == 1 || steps.excludes.outputs.is_dirty == 1 || steps.commit_status.outputs.is_dirty == 1)
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -11,11 +11,12 @@ In this repository, you can find the lang files for the [Laravel Framework 4/5/6

## News

* in version 6.1, we propose a new file by language: `validation-inline.php` ( see [#1268](https://github.com/Laravel-Lang/lang/issues/1268) )
* in version 7, we propose new directory names to follow ISO-15897 ( see [#1269](https://github.com/Laravel-Lang/lang/issues/1269) )
* in version 8, we propose new directory names to follow Php Intl ( see [#1453](https://github.com/Laravel-Lang/lang/pull/1453) )
* in version 9, we propose new structure of files ( see [#1606](https://github.com/Laravel-Lang/lang/discussions/1606), [#1607](https://github.com/Laravel-Lang/lang/pull/1607) )
* in version 10, we split translation keys into Laravel packages ([#1748](https://github.com/Laravel-Lang/lang/pull/1748), [discussion](https://github.com/Laravel-Lang/lang/discussions/1702#discussioncomment-703215))
* in version 9.1, we include machine translations, with review by humans for some languages ( see [Discussions](https://github.com/Laravel-Lang/lang/discussions/1692) )
* in version 9, we propose new structure of files ( see [#1606](https://github.com/Laravel-Lang/lang/discussions/1606), [#1607](https://github.com/Laravel-Lang/lang/pull/1607) )
* in version 8, we propose new directory names to follow Php Intl ( see [#1453](https://github.com/Laravel-Lang/lang/pull/1453) )
* in version 7, we propose new directory names to follow ISO-15897 ( see [#1269](https://github.com/Laravel-Lang/lang/issues/1269) )
* in version 6.1, we propose a new file by language: `validation-inline.php` ( see [#1268](https://github.com/Laravel-Lang/lang/issues/1268) )

## Translation managers

Expand Down
6 changes: 2 additions & 4 deletions app/keys.php
@@ -1,12 +1,10 @@
<?php

use LaravelLang\Lang\Processors\Json;
use LaravelLang\Lang\Processors\Php;
use LaravelLang\Lang\Processors\Process;

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

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

$app->processor(Json::make());
$app->processor(Php::make());
$app->processor(Process::make());
27 changes: 22 additions & 5 deletions app/main/Concerns/Contains.php
Expand Up @@ -2,8 +2,30 @@

namespace LaravelLang\Lang\Concerns;

use Helldar\Support\Facades\Helpers\Filesystem\Directory;
use Helldar\Support\Facades\Helpers\Str;
use LaravelLang\Lang\Constants\Locales;

trait Contains
{
protected function isMainJson(string $filename): bool
{
if ($this->isEnglishJson($filename)) {
return true;
}

$locale = Str::before($filename, '.');

$path = $this->app->localePath($locale);

return $this->isJson($filename) && Directory::exists($path);
}

protected function isEnglishJson(string $filename): bool
{
return $this->isJson($filename) && str_starts_with($filename, Locales::ENGLISH);
}

protected function isJson(string $filename): bool
{
return str_ends_with($filename, 'json');
Expand All @@ -14,11 +36,6 @@ protected function isMarkdown(string $filename): bool
return str_ends_with($filename, 'md');
}

protected function isPhp(string $filename): bool
{
return ! $this->isJson($filename);
}

protected function isValidation(string $filename): bool
{
return str_starts_with($filename, 'validation');
Expand Down
2 changes: 2 additions & 0 deletions app/main/Concerns/Template.php
Expand Up @@ -13,6 +13,8 @@ protected function template(string $filename, array $values = [], bool $trim = f
{
$template = $this->getTemplate($filename, $trim);

$values = array_merge($this->extend, $values);

return $this->replace($template, $values, $return_empty);
}

Expand Down
8 changes: 8 additions & 0 deletions app/main/Constants/Locales.php
@@ -0,0 +1,8 @@
<?php

namespace LaravelLang\Lang\Constants;

final class Locales
{
public const ENGLISH = 'en';
}
32 changes: 32 additions & 0 deletions app/main/Facades/Package.php
@@ -0,0 +1,32 @@
<?php

namespace LaravelLang\Lang\Facades;

use Helldar\Support\Facades\BaseFacade;
use LaravelLang\Lang\Support\Finder;
use LaravelLang\Lang\Support\Package as Support;
use LaravelLang\Lang\Support\Parser;
use Symfony\Component\Finder\Finder as SymfonyFinder;

/**
* @method static Support some()
*/
class Package extends BaseFacade
{
protected static function getFacadeAccessor(): Support
{
return new Support(self::resolveFinder(), self::resolveParser());
}

protected static function resolveFinder(): Finder
{
$finder = SymfonyFinder::create();

return Finder::make($finder);
}

protected static function resolveParser(): Parser
{
return Parser::make();
}
}
2 changes: 1 addition & 1 deletion app/main/Processors/Excludes.php
Expand Up @@ -58,7 +58,7 @@ protected function loadKeys(): void

protected function sourceFiles(): array
{
return File::names($this->getSourcePath());
return File::names($this->getSourcePath(), recursive: true);
}

protected function targetFiles(): array
Expand Down
17 changes: 0 additions & 17 deletions app/main/Processors/Json.php

This file was deleted.

46 changes: 46 additions & 0 deletions app/main/Processors/Packages.php
@@ -0,0 +1,46 @@
<?php

namespace LaravelLang\Lang\Processors;

use Helldar\Support\Facades\Helpers\Arr;
use LaravelLang\Lang\Facades\Package;

final class Packages extends Processor
{
protected array $packages = [
'laravel/fortify' => 'packages/fortify.json',
'laravel/jetstream' => 'packages/jetstream.json',
];

public function run(): void
{
foreach ($this->packages as $package => $filename) {
$items = $this->files($package);

$path = $this->getSourcePath($filename);

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

$this->sort($content);

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

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

protected function files(string $package): array
{
$path = $this->vendorPath($package);

return Package::some()->path($path)->content();
}

protected function vendorPath(string $package): string
{
return $this->app->path('vendor/' . $package);
}
}
Expand Up @@ -4,7 +4,7 @@

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

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

Expand All @@ -14,13 +14,15 @@ public function run(): void
foreach ($this->files($locale) as $file) {
$target_path = $this->getTargetPath($locale . '/' . $file);

$this->process($target_path, $file, $locale);
$filename = $this->isMainJson($file) ? 'en.json' : $file;

$this->process($target_path, $filename, $locale);
}
}
}

protected function files(string $locale): array
{
return File::names($this->getTargetPath($locale), fn ($filename) => $this->isPhp($filename));
return File::names($this->getTargetPath($locale), recursive: true);
}
}
16 changes: 15 additions & 1 deletion app/main/Processors/Processor.php
Expand Up @@ -39,7 +39,7 @@ public function application(Application $app): Processable

protected function merge(array $source, array $target, string $filename): array
{
$target = Arr::only($target, array_keys($source));
$target = $this->filter($target, $source);

$this->sort($source);
$this->sort($target);
Expand Down Expand Up @@ -95,6 +95,13 @@ protected function getSourcePath(string $filename = null): string
return $this->app->sourcePath($filename);
}

protected function filter(array $first, array $second): array
{
$keys = array_keys($second);

return Arr::only($first, $keys);
}

protected function sort(array &$array): void
{
$array = Arr::ksort($array);
Expand All @@ -110,6 +117,11 @@ protected function locales(): array
return Directory::names($this->getTargetPath());
}

protected function resolveFilename(string $filename, string $locale): string
{
return $this->isMainJson($filename) ? $locale . '.json' : $filename;
}

protected function getFilesystem(string $filename): Filesystem
{
$class = $this->getFilesystemClass($filename);
Expand All @@ -125,7 +137,9 @@ protected function getFilesystemClass(string $path): string
{
return match (true) {
$this->isJson($path) => JsonFilesystem::class,

$this->isMarkdown($path) => MarkdownFilesystem::class,

default => PhpFilesystem::class,
};
}
Expand Down

0 comments on commit 8d81938

Please sign in to comment.