Skip to content

Commit

Permalink
Merge pull request #81 from andrey-helldar/patch/2021-04-01/18-49
Browse files Browse the repository at this point in the history
Added aliases for Laravel Cashier and Laravel Nova
  • Loading branch information
Andrey Helldar committed Apr 1, 2021
2 parents 64d3ca7 + aa02341 commit 30b5629
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 47 deletions.
81 changes: 49 additions & 32 deletions README.md
@@ -1,7 +1,7 @@
# Lang Publisher

Publisher lang files for the [Laravel Framework][link_laravel], [Laravel Jetstream][link_jetstream], [Laravel Fortify][link_fortify] and [Laravel Cashier][link_cashier]
from [Laravel-Lang/lang][link_source] package.
Publisher lang files for the [Laravel Framework][link_laravel], [Laravel Jetstream][link_jetstream], [Laravel Fortify][link_fortify]
, [Laravel Cashier][link_cashier] and [Laravel Nova][link_nova] from [Laravel-Lang/lang][link_source] package.

![lang publisher](https://user-images.githubusercontent.com/10347617/40197727-f26e0aac-5a1c-11e8-81fa-077ad71915d7.png)

Expand All @@ -16,27 +16,6 @@ from [Laravel-Lang/lang][link_source] package.
[![Scrutinizer Code Quality][badge_quality]][link_scrutinizer]


## Table of contents

* [Installation](#installation)
* [Laravel Framework](#laravel-framework)
* [Laravel Jetstream](#laravel-jetstream)
* [Laravel Fortify](#laravel-fortify)
* [Lumen Framework](#lumen-framework)
* [Compatibility table](#compatibility-table)
* [How to use](#how-to-use)
* [Important](#important)
* [General principles](#general-principles)
* [Install locales](#install-locales)
* [Update locales](#update-locales)
* [Uninstall locales](#uninstall-locales)
* [Reset locales](#reset-locales)
* [Features](#features)
* [Alignment](#alignment)
* [Facades](#facades)
* [Config](#config)
* [Locale](#locale)

## Installation

To get the latest version of Laravel Lang Publisher, simply require the project using [Composer](https://getcomposer.org):
Expand Down Expand Up @@ -99,6 +78,42 @@ php artisan lang:install --fortify de

> `--fortify` is an alias for `--json`.
#### Laravel Cashier

The translation file for Laravel Cashier is merged with the Laravel translation json file.

Use the `--json` or `--cash` parameter to install.

For example:

```
php artisan lang:install --json en de ro zh-CN lv
php artisan lang:install --json de
php artisan lang:install --cashier en de ro zh-CN lv
php artisan lang:install --cashier de
```

> `--cashier` is an alias for `--json`.
#### Laravel Nova

The translation file for Laravel Nova is merged with the Laravel translation json file.

Use the `--json` or `--nova` parameter to install.

For example:

```
php artisan lang:install --json en de ro zh-CN lv
php artisan lang:install --json de
php artisan lang:install --nova en de ro zh-CN lv
php artisan lang:install --nova de
```

> `--nova` is an alias for `--json`.
#### Lumen Framework

This package is focused on Laravel development, but it can also be used in Lumen with some workarounds. Because Lumen works a little different, as it is like a
Expand Down Expand Up @@ -159,7 +174,7 @@ He does not touch any other files.

All commands have common key types:

* `--json` (also `-j`) - runs a command to work with translation JSON files;
* `--json` (also `-j`) - runs a command to work with translation JSON files. Available aliases: `--jet`, `--fortify`, `--cashier` and `--nova`;
* `--force` (also `-f`) - runs a command to force execution (works on all but the `reset` command).

Parameters on call (used in all except `update`):
Expand Down Expand Up @@ -489,20 +504,22 @@ Locale::getFallback(): string

[link_build]: https://github.com/andrey-helldar/laravel-lang-publisher/actions

[link_cashier]: https://laravel.com/docs/8.x/billing

[link_fortify]: https://github.com/laravel/fortify

[link_jetstream]: https://jetstream.laravel.com

[link_laravel]: https://laravel.com

[link_license]: LICENSE

[link_nova]: https://nova.laravel.com

[link_packagist]: https://packagist.org/packages/andrey-helldar/laravel-lang-publisher

[link_scrutinizer]: https://scrutinizer-ci.com/g/andrey-helldar/laravel-lang-publisher/?branch=main

[link_source]: https://github.com/Laravel-Lang/lang

[link_styleci]: https://github.styleci.io/repos/119022335

[link_laravel]: https://laravel.com

[link_jetstream]: https://jetstream.laravel.com

[link_fortify]: https://github.com/laravel/fortify

[link_cashier]: https://laravel.com/docs/8.x/billing
6 changes: 5 additions & 1 deletion src/Console/BaseCommand.php
Expand Up @@ -72,7 +72,11 @@ protected function isFull(): bool

protected function wantsJson(): bool
{
return (bool) $this->option('json') || (bool) $this->option('jet') || (bool) $this->option('fortify');
return (bool) $this->option('json')
|| (bool) $this->option('jet')
|| (bool) $this->option('fortify')
|| (bool) $this->option('cashier')
|| (bool) $this->option('nova');
}

protected function setProcessor(string $php, string $json): void
Expand Down
4 changes: 3 additions & 1 deletion src/Console/LangInstall.php
Expand Up @@ -12,7 +12,9 @@ final class LangInstall extends BaseCommand
. ' {--f|force : Override exiting files}'
. ' {--j|json : Install JSON files}'
. ' {--jet : Install Jetstream JSON files. This is an alias for "--json" key. }'
. ' {--fortify : Install Fortify JSON files. This is an alias for "--json" key. }';
. ' {--fortify : Install Fortify JSON files. This is an alias for "--json" key. }'
. ' {--cashier : Install Cashier JSON files. This is an alias for "--json" key. }'
. ' {--nova : Install Nova JSON files. This is an alias for "--json" key. }';

protected $description = 'Install new localizations.';

Expand Down
2 changes: 2 additions & 0 deletions src/Console/LangReset.php
Expand Up @@ -12,6 +12,8 @@ final class LangReset extends BaseCommand
. ' {--j|json : Reset JSON files}'
. ' {--jet : Reset Jetstream JSON files. This is an alias for "--json" key. }'
. ' {--fortify : Reset Fortify JSON files. This is an alias for "--json" key. }'
. ' {--cashier : Reset Cashier JSON files. This is an alias for "--json" key. }'
. ' {--nova : Reset Nova JSON files. This is an alias for "--json" key. }'
. ' {--f|full : Reset files without excluded keys}';

protected $description = 'Resets installed locations.';
Expand Down
4 changes: 3 additions & 1 deletion src/Console/LangUninstall.php
Expand Up @@ -11,7 +11,9 @@ final class LangUninstall extends BaseCommand
. ' {locales?* : Space-separated list of, eg: de tk it}'
. ' {--j|json : Uninstall JSON files}'
. ' {--jet : Uninstall Jetstream JSON files. This is an alias for "--json" key. }'
. ' {--fortify : Uninstall Fortify JSON files. This is an alias for "--json" key. }';
. ' {--fortify : Uninstall Fortify JSON files. This is an alias for "--json" key. }'
. ' {--cashier : Uninstall Cashier JSON files. This is an alias for "--json" key. }'
. ' {--nova : Uninstall Nova JSON files. This is an alias for "--json" key. }';

protected $description = 'Uninstall localizations.';

Expand Down
12 changes: 6 additions & 6 deletions src/Console/LangUpdate.php
Expand Up @@ -7,18 +7,18 @@ final class LangUpdate extends BaseCommand
protected $signature = 'lang:update'
. ' {--j|json : Update JSON files}'
. ' {--jet : Update Jetstream JSON files. This is an alias for "--json" key. }'
. ' {--fortify : Update Fortify JSON files. This is an alias for "--json" key. }';
. ' {--fortify : Update Fortify JSON files. This is an alias for "--json" key. }'
. ' {--cashier : Update Cashier JSON files. This is an alias for "--json" key. }'
. ' {--nova : Update Nova JSON files. This is an alias for "--json" key. }';

protected $description = 'Updating installed localizations.';

public function handle()
{
$this->call('lang:install', [
'locales' => $this->installed(),
'--force' => true,
'--json' => $this->wantsJson(),
'--jet' => $this->wantsJson(),
'--fortify' => $this->wantsJson(),
'locales' => $this->installed(),
'--force' => true,
'--json' => $this->wantsJson(),
]);
}
}
111 changes: 111 additions & 0 deletions tests/Console/Json/InstallCashierTest.php
@@ -0,0 +1,111 @@
<?php

namespace Tests\Console\Json;

use Helldar\LaravelLangPublisher\Exceptions\SourceLocaleFileDoesntExist;
use Helldar\LaravelLangPublisher\Facades\Locale;
use Helldar\LaravelLangPublisher\Services\Processors\PublishJson;
use Illuminate\Support\Facades\Lang;
use Tests\TestCase;

final class InstallCashierTest extends TestCase
{
protected $processor = PublishJson::class;

protected $is_json = true;

public function testWithoutLanguageAttribute()
{
$path = $this->path->target('ar');

method_exists($this, 'assertFileDoesNotExist')
? $this->assertFileDoesNotExist($path)
: $this->assertFileNotExists($path);

$this->artisan('lang:install', ['--cashier' => true])
->expectsConfirmation('Do you want to install all localizations?')
->expectsChoice('What languages to install? (specify the necessary localizations separated by commas)', 'ar', Locale::available())
->assertExitCode(0);

$this->assertFileExists($path);
}

public function testUnknownLanguageFromCommand()
{
$this->expectException(SourceLocaleFileDoesntExist::class);
$this->expectExceptionMessage('The source "foo" localization was not found.');

$this->artisan('lang:install', [
'locales' => 'foo',
'--cashier' => true,
]);
}

public function testUnknownLanguageFromService()
{
$this->expectException(SourceLocaleFileDoesntExist::class);
$this->expectExceptionMessage('The source "foo" localization was not found.');

$locales = 'foo';

$this->localization()
->processor($this->getProcessor())
->run($locales);
}

public function testCanInstallWithoutForce()
{
$locales = ['de', 'ru', 'fr', 'zh_CN'];

$this->deleteLocales($locales);

foreach ($locales as $locale) {
$path = $this->path->target($locale);

method_exists($this, 'assertFileDoesNotExist')
? $this->assertFileDoesNotExist($path)
: $this->assertFileNotExists($path);

$this->localization()
->processor($this->getProcessor())
->run($locale);

$this->assertFileExists($path);
}
}

public function testCanInstallWithForce()
{
$this->copyFixtures();

$this->localization()
->processor($this->getProcessor())
->force()
->run($this->default_locale);

$this->assertSame('This is Bar', Lang::get('Bar'));
$this->assertSame('Remember Me', Lang::get('Remember Me'));
}

public function testExcludes()
{
$this->copyFixtures();

$this->assertSame('This is Foo', Lang::get('Foo'));
$this->assertSame('This is Bar', Lang::get('Bar'));
$this->assertSame('This is Baz', Lang::get('All rights reserved.'));
$this->assertSame('This is Baq', Lang::get('Confirm Password'));

Lang::setLoaded([]);

$this->localization()
->processor($this->getProcessor())
->force()
->run($this->default_locale);

$this->assertSame('This is Foo', Lang::get('Foo'));
$this->assertSame('This is Bar', Lang::get('Bar'));
$this->assertSame('This is Baz', Lang::get('All rights reserved.'));
$this->assertSame('Confirm Password', Lang::get('Confirm Password'));
}
}
2 changes: 1 addition & 1 deletion tests/Console/Json/InstallFortifyTest.php
Expand Up @@ -23,7 +23,7 @@ public function testWithoutLanguageAttribute()
: $this->assertFileNotExists($path);

$this->artisan('lang:install', ['--fortify' => true])
->expectsConfirmation('Do you want to install all localizations?', 'no')
->expectsConfirmation('Do you want to install all localizations?')
->expectsChoice('What languages to install? (specify the necessary localizations separated by commas)', 'ar', Locale::available())
->assertExitCode(0);

Expand Down
2 changes: 1 addition & 1 deletion tests/Console/Json/InstallJetstreamTest.php
Expand Up @@ -23,7 +23,7 @@ public function testWithoutLanguageAttribute()
: $this->assertFileNotExists($path);

$this->artisan('lang:install', ['--jet' => true])
->expectsConfirmation('Do you want to install all localizations?', 'no')
->expectsConfirmation('Do you want to install all localizations?')
->expectsChoice('What languages to install? (specify the necessary localizations separated by commas)', 'ar', Locale::available())
->assertExitCode(0);

Expand Down

0 comments on commit 30b5629

Please sign in to comment.