Skip to content

Commit

Permalink
Merge pull request #42 from ARCANEDEV/upgrade-deps
Browse files Browse the repository at this point in the history
Update the package
  • Loading branch information
arcanedev-maroc committed May 7, 2021
2 parents f14b09e + b0cb9c4 commit a9a8cda
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 175 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.3, 7.4]
php: [7.3, 7.4, 8.0]
dependency-version: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Cache dependencies
uses: actions/cache@v2
Expand All @@ -41,5 +43,5 @@ jobs:
- name: Scrutinizer CI
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
composer require scrutinizer/ocular --dev
vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 4
runs: 6
php_code_sniffer:
enabled: true
config:
Expand Down
3 changes: 1 addition & 2 deletions _docs/2-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ return [

/** @link https://github.com/Laravel-Lang/lang */
'vendor' => [
'php' => base_path('vendor/laravel-lang/lang/src'),
'json' => base_path('vendor/laravel-lang/lang/json'),
base_path('vendor/laravel-lang/lang/locales'),
],

/* -----------------------------------------------------------------
Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"type": "library",
"license": "MIT",
"require": {
"php": "^7.3",
"php": "^7.3|^8.0",
"arcanedev/support": "^8.0",
"laravel-lang/lang": "^7.0.1"
"laravel-lang/lang": "^9.0"
},
"require-dev": {
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.3"
"laravel/framework": "^8.40",
"mockery/mockery": "^1.4.2",
"orchestra/testbench-core": "^6.4",
"phpunit/phpunit": "^9.3.3"
},
"autoload": {
"psr-4": {
Expand All @@ -35,8 +37,9 @@
}
},
"scripts": {
"test": "phpunit",
"coverage": "phpunit --coverage-html build/coverage/html"
"test": "phpunit --colors=always",
"test:dox": "phpunit --testdox --colors=always",
"test:cov": "phpunit --coverage-html coverage"
},
"extra": {
"branch-alias": {
Expand Down
3 changes: 1 addition & 2 deletions config/laravel-lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

/** @link https://github.com/Laravel-Lang/lang */
'vendor' => [
'php' => base_path('vendor/laravel-lang/lang/src'),
'json' => base_path('vendor/laravel-lang/lang/json'),
base_path('vendor/laravel-lang/lang/locales'),
],

/* -----------------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions src/FileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ public function load($locale, $group, $namespace = null): array
{
$defaults = [];

if (empty($this->locales) || $this->isSupported($locale))
$defaults = $this->loadPath($this->getVendorPaths()['php'], $locale, $group);
if (empty($this->locales) || $this->isSupported($locale)) {
foreach ($this->getVendorPaths() as $path) {
if ( ! empty($defaults = $this->loadPath($path, $locale, $group)))
break;
}
}

return array_replace_recursive($defaults, parent::load($locale, $group, $namespace));
}
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class LaravelLang
| -----------------------------------------------------------------
*/

const VERSION = '9.0.0';
const VERSION = '9.1.0';
}
24 changes: 9 additions & 15 deletions src/Providers/DeferredServicesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

namespace Arcanedev\LaravelLang\Providers;

use Illuminate\Support\Collection;
use Arcanedev\LaravelLang\{TransChecker, TransManager, TransPublisher};
use Arcanedev\LaravelLang\Contracts\TransChecker as TransCheckerContract;
use Arcanedev\LaravelLang\Contracts\TransManager as TransManagerContract;
use Arcanedev\LaravelLang\Contracts\TransPublisher as TransPublisherContract;
use Arcanedev\Support\Providers\ServiceProvider;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Foundation\Application;

/**
* Class DeferredServicesProvider
Expand Down Expand Up @@ -60,7 +59,7 @@ public function provides(): array
private function registerTransManager(): void
{
$this->singleton(TransManagerContract::class, function (Application $app) {
return new TransManager($app['files'], $this->getVendorPaths($app));
return new TransManager($app['files'], $this->getPaths($app));
});
}

Expand Down Expand Up @@ -93,22 +92,17 @@ private function registerLangPublisher(): void
}

/**
* Get the vendor paths.
* Get the localization paths.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Contracts\Foundation\Application $app
*
* @return array
*/
private function getVendorPaths(Application $app): array
private function getPaths(Application $app): array
{
return Collection::make($app['config']->get('laravel-lang.vendor', []))
->mapWithKeys(function (string $path, string $group) {
return ["vendor-{$group}" => $path];
})
->put('app', $app->langPath())
->transform(function (string $path) {
return realpath($path);
})
->toArray();
return [
'app' => $app->langPath(),
'vendors' => $app['config']->get('laravel-lang.vendor', []),
];
}
}
72 changes: 43 additions & 29 deletions src/TransManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TransManager implements TransManagerContract
*
* @var array
*/
private $paths = [];
private $paths = [];

/**
* Translations collection.
Expand Down Expand Up @@ -96,49 +96,33 @@ public function getPaths(): array
*/
private function load(): void
{
foreach ($this->getPaths() as $group => $path) {
$this->locales[$group] = $group === 'vendor-json'
? $this->loadJsonDirectory($path)
: $this->loadDirectories($path);
}
}
$paths = $this->getPaths();

/**
* @param string $path
*
* @return \Arcanedev\LaravelLang\Entities\LocaleCollection
*/
private function loadJsonDirectory(string $path): LocaleCollection
{
$locales = new LocaleCollection;
$this->locales['app'] = $this->loadTranslations($paths['app']);

foreach ($this->filesystem->files($path) as $file) {
$locales->addOne(
new Locale($file->getBasename('.json'), $file->getRealPath())
);
foreach ($paths['vendors'] as $path) {
$this->locales['vendor-php'] = $this->loadTranslations($path);
$this->locales['vendor-json'] = $this->loadJsonTranslations($path);
}

return $locales;
}

/**
* Load directories.
* Load translation files.
*
* @param string $dirPath
*
* @return \Arcanedev\LaravelLang\Entities\LocaleCollection
*/
private function loadDirectories(string $dirPath): LocaleCollection
private function loadTranslations(string $dirPath): LocaleCollection
{
$locales = new LocaleCollection;

foreach ($this->filesystem->directories($dirPath) as $path) {
if ($this->isExcluded($path)) {
if ($this->isExcluded($path))
continue;
}

$locales->addOne(
new Locale(basename($path), $path, $this->loadLocaleFiles($path))
new Locale(basename($path), $path, $this->loadTranslationFiles($path))
);
}

Expand All @@ -152,12 +136,14 @@ private function loadDirectories(string $dirPath): LocaleCollection
*
* @return array
*/
private function loadLocaleFiles(string $path): array
private function loadTranslationFiles(string $path): array
{
$files = [];

foreach ($this->filesystem->allFiles($path) as $file) {
/** @var \Symfony\Component\Finder\SplFileInfo $file */
if ($file->getExtension() !== 'php')
continue;

$key = str_replace(
['.php', DIRECTORY_SEPARATOR], ['', '.'], $file->getRelativePathname()
);
Expand All @@ -171,6 +157,34 @@ private function loadLocaleFiles(string $path): array
return $files;
}

/**
* Load json translation files.
*
* @param string $dirPath
*
* @return \Arcanedev\LaravelLang\Entities\LocaleCollection
*/
private function loadJsonTranslations(string $dirPath): LocaleCollection
{
$locales = new LocaleCollection;

foreach ($this->filesystem->directories($dirPath) as $path) {
if ($this->isExcluded($path))
continue;

foreach ($this->filesystem->files($path) as $file) {
if ($file->getExtension() === 'json') {
$locales->addOne(
new Locale($file->getBasename('.json'), $file->getRealPath())
);
break;
}
}
}

return $locales;
}

/**
* Get locale collection by group location.
*
Expand Down Expand Up @@ -261,6 +275,6 @@ public function hasCollection(string $group): bool
*/
private function isExcluded(string $path): bool
{
return in_array($key = basename($path), $this->excludedFolders);
return in_array(basename($path), $this->excludedFolders);
}
}
19 changes: 9 additions & 10 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ abstract class TestCase extends BaseTestCase
* @var array
*/
protected $locales = [
'ar', 'az', 'be', 'bg', 'bn', 'bs', 'ca', 'cs', 'cy', 'da', 'de', 'de_CH', 'el', 'es', 'et', 'eu', 'fa', 'fi',
'fil', 'fr', 'gl', 'he', 'hi', 'hr', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'ka', 'kk', 'km', 'kn', 'ko', 'lt',
'lv', 'me', 'mk', 'mn', 'mr', 'ms', 'nb', 'ne', 'nl', 'nn', 'pl', 'ps', 'pt', 'pt_BR', 'ro', 'ru', 'sc', 'si',
'sk', 'sl', 'sq', 'sr_Cyrillic', 'sr_Latin', 'sv', 'sw', 'tg', 'th', 'tk', 'tl', 'tr', 'ug', 'uk', 'ur',
'uz_Cyrillic', 'uz_Latin', 'vi', 'zh_CN', 'zh_HK', 'zh_TW',
'af', 'ar', 'az', 'be', 'bg', 'bn', 'bs', 'ca', 'cs', 'cy', 'da', 'de', 'de_CH', 'el', 'es', 'et', 'eu', 'fa',
'fi', 'fil', 'fr', 'gl', 'he', 'hi', 'hr', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'ka', 'kk', 'km', 'kn', 'ko',
'lt', 'lv', 'mk', 'mn', 'mr', 'ms', 'nb', 'ne', 'nl', 'nn', 'oc', 'pl', 'ps', 'pt', 'pt_BR', 'ro', 'ru', 'sc',
'si', 'sk', 'sl', 'sq', 'sr_Cyrl', 'sr_Latn', 'sr_Latn_ME', 'sv', 'sw', 'tg', 'th', 'tk', 'tl', 'tr', 'ug', 'uk',
'ur', 'uz_Cyrl', 'uz_Latn', 'vi', 'zh_CN', 'zh_HK', 'zh_TW',
];

/* -----------------------------------------------------------------
Expand Down Expand Up @@ -64,14 +64,13 @@ protected function getEnvironmentSetUp($app): void
$config = $app['config'];

$config->set('laravel-lang', [
'vendor' => [
'php' => realpath($basePath . '/vendor/laravel-lang/lang/src'),
'json' => realpath($basePath . '/vendor/laravel-lang/lang/json'),
'vendor' => [
realpath($basePath . '/vendor/laravel-lang/lang/locales'),
],

'locales' => ['es', 'fr'],
'locales' => ['es', 'fr'],

'check' => [
'check' => [
'ignore' => [
'validation.custom',
'validation.attributes',
Expand Down
5 changes: 2 additions & 3 deletions tests/TransManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ public function it_can_be_instantiated(): void

$paths = $this->manager->getPaths();

static::assertCount(3, $paths);
static::assertCount(2, $paths);
static::assertArrayHasKey('app', $paths);
static::assertArrayHasKey('vendor-php', $paths);
static::assertArrayHasKey('vendor-json', $paths);
static::assertArrayHasKey('vendors', $paths);
}

/** @test */
Expand Down
5 changes: 5 additions & 0 deletions tests/TransPublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function it_can_publish(): void
static::assertEquals([
'published' => [
'es/auth.php',
'es/es.json',
'es/pagination.php',
'es/passwords.php',
'es/validation.php',
Expand All @@ -79,6 +80,7 @@ public function it_can_publish(): void
static::assertEquals([
'published' => [
'es/auth.php',
'es/es.json',
'es/pagination.php',
'es/passwords.php',
'es/validation.php',
Expand All @@ -98,6 +100,7 @@ public function it_can_not_publish_if_is_not_forced(): void
static::assertEquals([
'published' => [
'es/auth.php',
'es/es.json',
'es/pagination.php',
'es/passwords.php',
'es/validation.php',
Expand All @@ -109,6 +112,7 @@ public function it_can_not_publish_if_is_not_forced(): void
'published' => [],
'skipped' => [
'es/auth.php',
'es/es.json',
'es/pagination.php',
'es/passwords.php',
'es/validation.php',
Expand All @@ -127,6 +131,7 @@ public function it_can_publish_on_force(): void
$excepted = [
'published' => [
'es/auth.php',
'es/es.json',
'es/pagination.php',
'es/passwords.php',
'es/validation.php',
Expand Down
4 changes: 2 additions & 2 deletions tests/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public function it_can_translate(): void
{
$expectations = [
'es' => [
'auth.failed' => 'Estas credenciales no coinciden con nuestros registros.'
'auth.failed' => 'Estas credenciales no coinciden con nuestros registros.',
],
'fr' => [
'auth.failed' => 'Ces identifiants ne correspondent pas à nos enregistrements'
'auth.failed' => 'Ces identifiants ne correspondent pas à nos enregistrements.',
],
];

Expand Down

0 comments on commit a9a8cda

Please sign in to comment.