Skip to content

Commit

Permalink
Admin Area Translations (#965)
Browse files Browse the repository at this point in the history
* Init

* Health Page

* Admin API Keys

* Update API Keys

* Database Hosts

* Mounts

* remove `s`

* Users

* Webhooks

* Server

never again...

* Fix Server

* Settings

* Update Mounts

* Update Databasehost

* Update Server

* Oops, Update Server

* Nodes

* Update User

* Dashboard

* Update Server

* Profile

* Egg

* Role & Update Egg

* Add base Laravel lang files

* update apikey

* remove html back to settings, remove comment

* add `:resource` to create_action

* Update Egg

* Update Egg v2

* Update 1

* trans cf info label

* Update charts

* more trans

* Update Webhook

* update Health

* Update Server

* Update Role

* Fixes

* Bulk Update

* AnotherOne

* Fix relation button label

* rename `admin1` to `admin`

Leftover from testing... oops

* More Translations

* Updates

* `pint` + Relation Manager Titles
  • Loading branch information
notAreYouScared authored Feb 9, 2025
1 parent 513117c commit f8ad720
Show file tree
Hide file tree
Showing 594 changed files with 2,080 additions and 23,292 deletions.
58 changes: 58 additions & 0 deletions app/Checks/CacheCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Checks;

use Exception;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;

class CacheCheck extends Check
{
protected ?string $driver = null;

public function driver(string $driver): self
{
$this->driver = $driver;

return $this;
}

public function run(): Result
{
$driver = $this->driver ?? $this->defaultDriver();

$result = Result::make()->meta([
'driver' => $driver,
]);

try {
return $this->canWriteValuesToCache($driver)
? $result->ok(trans('admin/health.results.cache.ok'))
: $result->failed(trans('admin/health.results.cache.failed_retrieve'));
} catch (Exception $exception) {
return $result->failed(trans('admin/health.results.cache.failed', ['error' => $exception->getMessage()]));
}
}

protected function defaultDriver(): ?string
{
return config('cache.default', 'file');
}

protected function canWriteValuesToCache(?string $driver): bool
{
$expectedValue = Str::random(5);

$cacheName = "laravel-health:check-{$expectedValue}";

Cache::driver($driver)->put($cacheName, $expectedValue, 10);

$actualValue = Cache::driver($driver)->get($cacheName);

Cache::driver($driver)->forget($cacheName);

return $actualValue === $expectedValue;
}
}
42 changes: 42 additions & 0 deletions app/Checks/DatabaseCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Checks;

use Exception;
use Illuminate\Support\Facades\DB;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;

class DatabaseCheck extends Check
{
protected ?string $connectionName = null;

public function connectionName(string $connectionName): self
{
$this->connectionName = $connectionName;

return $this;
}

public function run(): Result
{
$connectionName = $this->connectionName ?? $this->getDefaultConnectionName();

$result = Result::make()->meta([
'connection_name' => $connectionName,
]);

try {
DB::connection($connectionName)->getPdo();

return $result->ok(trans('admin/health.results.database.ok'));
} catch (Exception $exception) {
return $result->failed(trans('admin/health.results.database.failed', ['error' => $exception->getMessage()]));
}
}

protected function getDefaultConnectionName(): string
{
return config('database.default');
}
}
44 changes: 44 additions & 0 deletions app/Checks/DebugModeCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Checks;

use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;

use function config;

class DebugModeCheck extends Check
{
protected bool $expected = false;

public function expectedToBe(bool $bool): self
{
$this->expected = $bool;

return $this;
}

public function run(): Result
{
$actual = config('app.debug');

$result = Result::make()
->meta([
'actual' => $actual,
'expected' => $this->expected,
])
->shortSummary($this->convertToWord($actual));

return $this->expected === $actual
? $result->ok()
: $result->failed(trans('admin/health.results.debugmode.failed', [
'actual' => $this->convertToWord($actual),
'expected' => $this->convertToWord($this->expected),
]));
}

protected function convertToWord(bool $boolean): string
{
return $boolean ? 'true' : 'false';
}
}
38 changes: 38 additions & 0 deletions app/Checks/EnvironmentCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Checks;

use Illuminate\Support\Facades\App;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;

class EnvironmentCheck extends Check
{
protected string $expectedEnvironment = 'production';

public function expectEnvironment(string $expectedEnvironment): self
{
$this->expectedEnvironment = $expectedEnvironment;

return $this;
}

public function run(): Result
{
$actualEnvironment = (string) App::environment();

$result = Result::make()
->meta([
'actual' => $actualEnvironment,
'expected' => $this->expectedEnvironment,
])
->shortSummary($actualEnvironment);

return $this->expectedEnvironment === $actualEnvironment
? $result->ok(trans('admin/health.results.environment.ok'))
: $result->failed(trans('admin/health.results.environment.failed', [
'actual' => $actualEnvironment,
'expected' => $this->expectedEnvironment,
]));
}
}
10 changes: 6 additions & 4 deletions app/Checks/NodeVersionsCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public function run(): Result
$all = Node::query()->count();

if ($all === 0) {
$result = Result::make()->notificationMessage('No Nodes created')->shortSummary('No Nodes');
$result = Result::make()
->notificationMessage(trans('admin/health.results.nodeversions.no_nodes_created'))
->shortSummary(trans('admin/health.results.node_version.no_nodes'));
$result->status = Status::skipped();

return $result;
Expand All @@ -34,10 +36,10 @@ public function run(): Result
'all' => $all,
'outdated' => $outdated,
])
->shortSummary($outdated === 0 ? 'All up-to-date' : "{$outdated}/{$all} outdated");
->shortSummary($outdated === 0 ? trans('admin/health.results.nodeversions.all_up_to_date') : trans('admin/health.results.nodeversions.outdated', ['outdated' => $outdated, 'all' => $all]));

return $outdated === 0
? $result->ok('All Nodes are up-to-date.')
: $result->failed(':outdated/:all Nodes are outdated.');
? $result->ok(trans('admin/health.results.nodeversions.ok'))
: $result->failed(trans('admin/health.results.nodeversions.failed', ['outdated' => $outdated, 'all' => $all]));
}
}
9 changes: 6 additions & 3 deletions app/Checks/PanelVersionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ public function run(): Result
'currentVersion' => $currentVersion,
'latestVersion' => $latestVersion,
])
->shortSummary($isLatest ? 'up-to-date' : 'outdated');
->shortSummary($isLatest ? trans('admin/health.results.panelversion.up_to_date') : trans('admin/health.results.panelversion.outdated'));

return $isLatest
? $result->ok('Panel is up-to-date.')
: $result->failed('Installed version is `:currentVersion` but latest is `:latestVersion`.');
? $result->ok(trans('admin/health.results.panelversion.ok'))
: $result->failed(trans('admin/health.results.panelversion.failed', [
'currentVersion' => $currentVersion,
'latestVersion' => $latestVersion,
]));
}
}
78 changes: 78 additions & 0 deletions app/Checks/ScheduleCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace App\Checks;

use Carbon\Carbon;
use Composer\InstalledVersions;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;

class ScheduleCheck extends Check
{
protected string $cacheKey = 'health:checks:schedule:latestHeartbeatAt';

protected ?string $cacheStoreName = null;

protected int $heartbeatMaxAgeInMinutes = 1;

public function useCacheStore(string $cacheStoreName): self
{
$this->cacheStoreName = $cacheStoreName;

return $this;
}

public function getCacheStoreName(): string
{
return $this->cacheStoreName ?? config('cache.default');
}

public function cacheKey(string $cacheKey): self
{
$this->cacheKey = $cacheKey;

return $this;
}

public function heartbeatMaxAgeInMinutes(int $heartbeatMaxAgeInMinutes): self
{
$this->heartbeatMaxAgeInMinutes = $heartbeatMaxAgeInMinutes;

return $this;
}

public function getCacheKey(): string
{
return $this->cacheKey;
}

public function run(): Result
{
$result = Result::make()->ok(trans('admin/health.results.schedule.ok'));

$lastHeartbeatTimestamp = cache()->store($this->cacheStoreName)->get($this->cacheKey);

if (!$lastHeartbeatTimestamp) {
return $result->failed(trans('admin/health.results.schedule.failed_not_ran'));
}

$latestHeartbeatAt = Carbon::createFromTimestamp($lastHeartbeatTimestamp);

$carbonVersion = InstalledVersions::getVersion('nesbot/carbon');

$minutesAgo = $latestHeartbeatAt->diffInMinutes();

if (version_compare($carbonVersion,
'3.0.0', '<')) {
$minutesAgo += 1;
}

if ($minutesAgo > $this->heartbeatMaxAgeInMinutes) {
return $result->failed(trans('admin/health.results.schedule.failed_last_ran', [
'time' => $minutesAgo,
]));
}

return $result;
}
}
21 changes: 12 additions & 9 deletions app/Filament/Admin/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ class Dashboard extends Page

public function getTitle(): string
{
return trans('strings.dashboard');
return trans('admin/dashboard.title');
}

protected static ?string $slug = '/';
public static function getNavigationLabel(): string
{
return trans('admin/dashboard.title');
}

public string $activeTab = 'nodes';
protected static ?string $slug = '/';

private SoftwareVersionService $softwareVersionService;

Expand All @@ -51,33 +54,33 @@ public function getViewData(): array

'devActions' => [
CreateAction::make()
->label('Bugs & Features')
->label(trans('admin/dashboard.sections.intro-developers.button_issues'))
->icon('tabler-brand-github')
->url('https://github.com/pelican-dev/panel/discussions', true),
->url('https://github.com/pelican-dev/panel/issues', true),
],
'updateActions' => [
CreateAction::make()
->label('Read Documentation')
->label(trans('admin/dashboard.sections.intro-update-available.heading'))
->icon('tabler-clipboard-text')
->url('https://pelican.dev/docs/panel/update', true)
->color('warning'),
],
'nodeActions' => [
CreateAction::make()
->label(trans('dashboard/index.sections.intro-first-node.button_label'))
->label(trans('admin/dashboard.sections.intro-first-node.button_label'))
->icon('tabler-server-2')
->url(CreateNode::getUrl()),
],
'supportActions' => [
CreateAction::make()
->label(trans('dashboard/index.sections.intro-support.button_donate'))
->label(trans('admin/dashboard.sections.intro-support.button_donate'))
->icon('tabler-cash')
->url('https://pelican.dev/donate', true)
->color('success'),
],
'helpActions' => [
CreateAction::make()
->label(trans('dashboard/index.sections.intro-help.button_docs'))
->label(trans('admin/dashboard.sections.intro-help.button_docs'))
->icon('tabler-speedboat')
->url('https://pelican.dev/docs', true),
],
Expand Down
Loading

0 comments on commit f8ad720

Please sign in to comment.