Skip to content

Commit

Permalink
Fixed agent dependency, fixes akaunting#39
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbilling committed Sep 19, 2024
1 parent 83285fb commit c723ad1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
],
"require": {
"php": ">=5.6.4",
"laravel/framework": ">=5.4.0",
"jenssegers/agent": "2.6.*"
"laravel/framework": ">=5.4.0"
},
"autoload": {
"psr-4": {
Expand Down
18 changes: 14 additions & 4 deletions src/Middleware/SetLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Akaunting\Language\Middleware;

use Closure;
use Jenssegers\Agent\Agent;

class SetLocale
{
Expand Down Expand Up @@ -46,9 +45,20 @@ private function setLocale($locale)
public function setDefaultLocale()
{
if (config('language.auto')) {
$languages = (new Agent())->languages();

$this->setLocale(reset($languages));
$http_header_languages = request()->header('Accept-Language');
if ($http_header_languages) {
$languages = [];
foreach (explode(',', $http_header_languages) as $language) {
$parts = explode(';', $language);
$language = strtolower($parts[0]);
$priority = empty($parts[1]) ? 1. : floatval(str_replace('q=', '', $parts[1]));
$languages[$language] = $priority;
}
arsort($languages);
$this->setLocale(reset($languages));
} else {
$this->setLocale(config('app.locale'));
}
} else {
$this->setLocale(config('app.locale'));
}
Expand Down
3 changes: 0 additions & 3 deletions src/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
use Jenssegers\Agent\AgentServiceProvider;

class Provider extends ServiceProvider
{
Expand All @@ -30,8 +29,6 @@ public function boot(Router $router)

$router->aliasMiddleware('language', config('language.middleware'));

$this->app->register(AgentServiceProvider::class);

$this->app->singleton('language', function ($app) {
return new Language($app);
});
Expand Down

0 comments on commit c723ad1

Please sign in to comment.