-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from Laravel-Lang/5.x
Added a little trick for documentation 😏
- Loading branch information
Showing
11 changed files
with
777 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Services; | ||
|
||
use DragonCode\Support\Facades\Filesystem\File; | ||
|
||
class Locales | ||
{ | ||
protected static string $filePath = __DIR__ . '/../../docs/usage/available-locales.md'; | ||
|
||
public static function generate(): void | ||
{ | ||
static::store( | ||
static::compilePage(static::compileLocales()) | ||
); | ||
} | ||
|
||
protected static function compileLocales(): array | ||
{ | ||
$locales = []; | ||
|
||
foreach (static::available() as $code => $data) { | ||
$locales[] = Template::locale($code, $data); | ||
} | ||
|
||
return $locales; | ||
} | ||
|
||
protected static function available(): array | ||
{ | ||
$locales = require __DIR__ . '/../../vendor/laravel-lang/locales/config/private.php'; | ||
|
||
return $locales['map'] ?? []; | ||
} | ||
|
||
protected static function compilePage(array $locales): string | ||
{ | ||
return Template::page($locales); | ||
} | ||
|
||
protected static function store(string $content): void | ||
{ | ||
File::store(static::$filePath, $content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Services; | ||
|
||
use DragonCode\Support\Facades\Helpers\Str; | ||
|
||
class Template | ||
{ | ||
protected static ?string $localeStub = null; | ||
|
||
protected static ?string $pageStub = null; | ||
|
||
public static function locale(string $code, array $locale): string | ||
{ | ||
return Str::replaceFormat(static::localeStub(), [ | ||
'code' => $code, | ||
'locale' => $locale['name'], | ||
'native' => Str::title($locale['native']), | ||
], '{{%s}}'); | ||
} | ||
|
||
public static function page(array $locales): string | ||
{ | ||
return Str::replaceFormat(static::pageStub(), [ | ||
'content' => implode(PHP_EOL . PHP_EOL, $locales), | ||
], '{{%s}}'); | ||
} | ||
|
||
protected static function localeStub(): string | ||
{ | ||
return static::$localeStub ??= static::stub('available-locale'); | ||
} | ||
|
||
protected static function pageStub(): string | ||
{ | ||
return static::$pageStub ??= static::stub('available-locales'); | ||
} | ||
|
||
protected static function stub(string $filename): string | ||
{ | ||
return trim(file_get_contents(__DIR__ . '/../../resources/stubs/' . $filename . '.stub')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\Services\Locales; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
Locales::generate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.