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

Dev #2

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
],
"homepage": "https://github.com/solumdesignum/package-translator-loader",
"require": {
"php": "^8.0|^8.1|^8.2",
"illuminate/support": "^9|^10"
"php": "^8.1|^8.2|^8.3",
"illuminate/support": "^10|^11"
},
"require-dev": {
"phpunit/phpunit": "~8|~9|~10",
Expand Down
19 changes: 8 additions & 11 deletions src/PackageTranslatorLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
use Illuminate\Translation\FileLoader;
use Illuminate\Translation\Translator;

use function app;
use function config;

class PackageTranslatorLoader
{
public array $config;

public ?string $locale = null;

private string $translator;
public string $translator;

private Application $app;
public Application $app;

public function __construct(
Application $app,
Expand All @@ -40,7 +37,7 @@ public function __construct(
$this->loadTranslations();
}

private function localeSetter(?string $locale): void
public function localeSetter(?string $locale): void
{
if ($locale !== null) {
$this->locale = $locale;
Expand All @@ -49,7 +46,7 @@ private function localeSetter(?string $locale): void
}
}

final public function setLocale(?string $locale = null): self
public function setLocale(?string $locale = null): self
{
$this->locale = $locale;

Expand All @@ -64,7 +61,7 @@ final public function setLocale(?string $locale = null): self
*
* @return void
*/
final public function loadTranslations(): void
public function loadTranslations(): void
{
$this->app->bind(
$this->translator,
Expand All @@ -91,7 +88,7 @@ function ($app) {
);
}

private function loader(): FileLoader
public function loader(): FileLoader
{
$filesystem = new Filesystem();
$resourcesLangPath = $this->config['packageRootPath'] . $this->config['loaderLangPath'];
Expand All @@ -100,7 +97,7 @@ private function loader(): FileLoader
return new FileLoader($filesystem, $resourcesLangPath);
}

private function locale(Application $app): string
public function locale(Application $app): string
{
return $app
->get('request')
Expand All @@ -109,7 +106,7 @@ private function locale(Application $app): string
) ?: $app->getLocale();
}

final public function trans(): mixed
public function trans(): mixed
{
return app($this->translator);
}
Expand Down
1 change: 1 addition & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @return mixed
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws Exception
*/
function translator(string $translator = null, string $key = null): mixed
{
Expand Down