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

Splitting projects #1748

Merged
merged 71 commits into from May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
0aaad58
File location changed
May 13, 2021
92976ff
Added Laravel Cashier installation in dev dependencies
May 13, 2021
e50de9d
Removed Cashier dependencies
May 13, 2021
ba6e950
Laravel Cashier Paddle project does not contain translation keys
May 13, 2021
9fbea9e
Laravel Cashier Stripe translation keys added to project
May 13, 2021
54b8215
Renamed source files
May 13, 2021
2d61d0d
Added Laravel Jetstream and Fortify installation in dev dependencies
May 13, 2021
7cfab95
Added search for Laravel Fortify and Jetstream keys
May 13, 2021
58530d0
Added file splitting
May 13, 2021
587186e
Updated English localization files
May 13, 2021
a777a76
Updated tests
May 13, 2021
36fd7b6
Added a call to search for translation keys when pushing to the main …
May 13, 2021
3a8b84b
Revert file structure
May 14, 2021
b82ea14
Regular expression for searching translations changed
May 14, 2021
b252890
Fixed Parser
May 14, 2021
0b983c9
Argument matches the parameter's default value
May 14, 2021
9d66bed
Update Parser
May 14, 2021
8f6aa5c
Direct links to repository files have been added to the documentation…
May 14, 2021
43ebedf
Refactoring app
May 14, 2021
e108045
Updated tests
May 14, 2021
a87a874
Merge remote-tracking branch 'caouecs/master' into patch/2021-05-13/2…
May 16, 2021
8b39ba6
RC
May 16, 2021
323f995
Update regex
May 17, 2021
e5be541
Fixed Parser.php
May 17, 2021
36ea68d
Revert locales
May 17, 2021
329a0b0
Key parsing bug fixed
May 17, 2021
1f0c0b2
Reorder strings
May 18, 2021
7439f17
Update contributing-to-dev.md
May 18, 2021
c931403
Update README.md
May 18, 2021
35bf348
Update changelog.md
May 18, 2021
ba19191
Conflict fixed
May 19, 2021
37ad269
Merge branch 'patch/2021-05-13/20-09' into patch/2021-05-19/21-00
May 19, 2021
e16106a
Conflict fixed
May 19, 2021
f920b23
Resolved conflict docs/changelog.md
May 19, 2021
532a136
Conflict fixed
May 19, 2021
ba414e1
File location changed
May 13, 2021
5322b0f
Added Laravel Cashier installation in dev dependencies
May 13, 2021
2c2c2f8
Removed Cashier dependencies
May 13, 2021
7d8bd5a
Laravel Cashier Paddle project does not contain translation keys
May 13, 2021
b681c98
Laravel Cashier Stripe translation keys added to project
May 13, 2021
ce9e91a
Renamed source files
May 13, 2021
02c810b
Added Laravel Jetstream and Fortify installation in dev dependencies
May 13, 2021
2f56a32
Added search for Laravel Fortify and Jetstream keys
May 13, 2021
67c40e3
Added file splitting
May 13, 2021
948842c
Updated English localization files
May 13, 2021
cbf4132
Updated tests
May 13, 2021
2907e91
Added a call to search for translation keys when pushing to the main …
May 13, 2021
f9ff3ae
Revert file structure
May 14, 2021
02c98c9
Regular expression for searching translations changed
May 14, 2021
3ea2a9b
Fixed Parser
May 14, 2021
dd97e1f
Argument matches the parameter's default value
May 14, 2021
0e6406e
Update Parser
May 14, 2021
39faf12
Direct links to repository files have been added to the documentation…
May 14, 2021
a64dfde
Refactoring app
May 14, 2021
0b216a9
Updated tests
May 14, 2021
470bc8e
RC
May 16, 2021
991cdf0
Update regex
May 17, 2021
402ecab
Fixed Parser.php
May 17, 2021
662be89
Revert locales
May 17, 2021
a7c1fee
Key parsing bug fixed
May 17, 2021
0ffeac9
Reorder strings
May 18, 2021
2ff7abb
Update contributing-to-dev.md
May 18, 2021
a55f5b3
Update README.md
May 18, 2021
36326d7
Update changelog.md
May 18, 2021
9eecc45
Conflict fixed
May 19, 2021
9d17e7c
Conflict fixed
May 19, 2021
72ca6a4
Conflict fixed
May 19, 2021
6a6a1c1
Conflict fixed
May 19, 2021
1380030
Merge branch 'patch/2021-05-19/21-00' into patch/2021-05-13/20-09
May 19, 2021
baa494f
Fixed test validation bug
May 19, 2021
7dfe19c
Updated docs/index.md
May 20, 2021
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
  •  
  •  
  •  
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