Make the texts of the server translatable, with a Dutch file
This commit is contained in:
1 parent
56de8ee76a
commit
a34965d4b7
18 files changed
+198
-27
No files matched your search
@@ -24,7 +24,7 @@ class ProfileController
|
||||
'groups' => method_exists($user, 'managerGroups') ? $user->managerGroups()->pluck('name')->values() : [],
|
||||
'theme' => $themes->keyFor($user),
|
||||
'themes' => config('manager.user_themes')
|
||||
? collect($themes->all())->map(fn (array $theme, string $key) => ['key' => $key, 'label' => $theme['label'], 'colors' => $theme['colors']])->values()
|
||||
? collect($themes->all())->map(fn (array $theme, string $key) => ['key' => $key, 'label' => __($theme['label']), 'colors' => $theme['colors']])->values()
|
||||
: [],
|
||||
]]);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class ProfileController
|
||||
]);
|
||||
|
||||
if (($data['password'] ?? '') !== '' && ! Hash::check((string) ($data['current_password'] ?? ''), $user->getAuthPassword())) {
|
||||
return response()->json(['message' => 'The current password is not right.', 'errors' => ['current_password' => ['The current password is not right.']]], 422);
|
||||
return response()->json(['message' => $wrong = __('The current password is not right.'), 'errors' => ['current_password' => [$wrong]]], 422);
|
||||
}
|
||||
|
||||
$user->name = $data['name'];
|
||||
|
||||
@@ -35,6 +35,7 @@ class ManagerServiceProvider extends ServiceProvider
|
||||
$modules->validate();
|
||||
|
||||
$this->publishes([__DIR__.'/../config/manager.php' => config_path('manager.php')], 'manager-config');
|
||||
$this->loadJsonTranslationsFrom(__DIR__.'/../resources/lang');
|
||||
$this->loadViewsFrom(__DIR__.'/../resources/views', 'manager');
|
||||
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ class AuditController
|
||||
$this->trail->about($ban);
|
||||
}
|
||||
|
||||
return response()->json(['message' => $wholeSite ? "{$ip} is banned from the whole site." : "{$ip} is banned from the manager."], 201);
|
||||
return response()->json(['message' => $wholeSite ? __(':ip is banned from the whole site.', ['ip' => $ip]) : __(':ip is banned from the manager.', ['ip' => $ip])], 201);
|
||||
}
|
||||
|
||||
public function unban(int $ban): JsonResponse
|
||||
@@ -180,7 +180,7 @@ class AuditController
|
||||
$this->trail->about($ipBan);
|
||||
$this->bans->lift($ipBan);
|
||||
|
||||
return response()->json(['message' => "The ban of {$ipBan->ip} is lifted."]);
|
||||
return response()->json(['message' => __('The ban of :ip is lifted.', ['ip' => $ipBan->ip])]);
|
||||
}
|
||||
|
||||
/** Bans every address of a group at once, with the same time, reason and reach. */
|
||||
@@ -258,7 +258,7 @@ class AuditController
|
||||
$note->delete();
|
||||
}
|
||||
|
||||
return response()->json(['message' => "The note about {$ip} is removed."]);
|
||||
return response()->json(['message' => __('The note about :ip is removed.', ['ip' => $ip])]);
|
||||
}
|
||||
|
||||
$note ??= new IpNote(['ip' => $ip]);
|
||||
@@ -267,7 +267,7 @@ class AuditController
|
||||
$note->fill(['note' => $text, 'group_name' => $group !== '' ? $group : null, 'user_id' => $user?->getAuthIdentifier(), 'user_name' => is_string($name) ? $name : null])->save();
|
||||
$this->trail->about($note);
|
||||
|
||||
return response()->json(['message' => "The note about {$ip} is saved."]);
|
||||
return response()->json(['message' => __('The note about :ip is saved.', ['ip' => $ip])]);
|
||||
}
|
||||
|
||||
public function settings(Request $request): JsonResponse
|
||||
@@ -284,12 +284,12 @@ class AuditController
|
||||
|
||||
AuditSetting::current()->forceFill(['id' => 1, ...$rules])->save();
|
||||
|
||||
return response()->json(['message' => 'Rules saved.', 'settings' => AuditSetting::current()->rules()]);
|
||||
return response()->json(['message' => __('Rules saved.'), 'settings' => AuditSetting::current()->rules()]);
|
||||
}
|
||||
|
||||
private function refuse(string $field, string $message): JsonResponse
|
||||
{
|
||||
return response()->json(['message' => $message, 'errors' => [$field => [$message]]], 422);
|
||||
return response()->json(['message' => $message = __($message), 'errors' => [$field => [$message]]], 422);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -115,13 +115,13 @@ class AuditModule extends BaseModule
|
||||
|
||||
Event::listen(Login::class, function (Login $event) use ($model) {
|
||||
if ($event->user instanceof $model) {
|
||||
app(AuditTrail::class)->record(AuditLog::LOGIN, 'Logged in', $event->user);
|
||||
app(AuditTrail::class)->record(AuditLog::LOGIN, __('Logged in'), $event->user);
|
||||
}
|
||||
});
|
||||
|
||||
Event::listen(Logout::class, function (Logout $event) use ($model) {
|
||||
if ($event->user instanceof $model) {
|
||||
app(AuditTrail::class)->record(AuditLog::LOGOUT, 'Logged out', $event->user);
|
||||
app(AuditTrail::class)->record(AuditLog::LOGOUT, __('Logged out'), $event->user);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ final class IpBans
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->trail->record(AuditLog::BAN, 'The address was banned after too many failed logins', subject: $ban, details: ['failures' => $failures]);
|
||||
$this->trail->record(AuditLog::BAN, __('The address was banned after too many failed logins'), subject: $ban, details: ['failures' => $failures]);
|
||||
|
||||
return $ban;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use Illuminate\Support\Str;
|
||||
use IriksIT\Manager\Models\AuditLog;
|
||||
use IriksIT\Manager\Support\AuditTrail;
|
||||
use IriksIT\Manager\Support\ModuleRegistry;
|
||||
use IriksIT\Manager\Support\Names;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
use Throwable;
|
||||
@@ -50,18 +51,18 @@ class RecordActions
|
||||
|
||||
private function write(Request $request, Response $response, Authenticatable $user, ?Model $subject): void
|
||||
{
|
||||
$route = Str::after((string) $request->route()?->getName(), 'manager.');
|
||||
$route = Str::after((string) $request->route()?->getName(), Names::routePrefix());
|
||||
$actions = $this->modules->actions();
|
||||
$views = $this->modules->views();
|
||||
$thrown = property_exists($response, 'exception') && $response->exception instanceof Throwable ? $response->exception : null;
|
||||
$details = $this->details($request, $actions[$route][1] ?? []);
|
||||
$name = $actions[$route][0] ?? ($views[$route] ?? '');
|
||||
$name = $name !== '' ? $name : 'Asked for '.$request->method().' /'.ltrim($request->path(), '/');
|
||||
$name = $name !== '' ? __($name) : __('Asked for :request', ['request' => $request->method().' /'.ltrim($request->path(), '/')]);
|
||||
|
||||
if ($thrown !== null) {
|
||||
// Only a refusal is worth a line; a form with a mistake or a page that is not there is not.
|
||||
if ($thrown instanceof AuthorizationException || ($thrown instanceof HttpExceptionInterface && $thrown->getStatusCode() === 403)) {
|
||||
$this->trail->record(AuditLog::REFUSED, 'Was not allowed: '.Str::lcfirst($name), $user, $subject, $details, $route);
|
||||
$this->trail->record(AuditLog::REFUSED, __('Was not allowed: :what', ['what' => Str::lcfirst($name)]), $user, $subject, $details, $route);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -74,7 +75,7 @@ class RecordActions
|
||||
$changes = ! in_array($request->method(), ['GET', 'HEAD', 'OPTIONS'], true);
|
||||
|
||||
if (! $changes && ! isset($actions[$route])) {
|
||||
$this->viewed($user, $route, $views[$route] ?? '', $subject, $details);
|
||||
$this->viewed($user, $route, __($views[$route] ?? ''), $subject, $details);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ class RefuseBannedAddress
|
||||
/** The page (or JSON) a banned address gets, also for a ban on the whole site. */
|
||||
public static function answer(Request $request, IpBan $ban): Response
|
||||
{
|
||||
$where = $ban->whole_site ? 'this site' : 'the manager';
|
||||
$where = $ban->whole_site ? __('this site') : __('the manager');
|
||||
$message = $ban->expires_at === null
|
||||
? "This address is blocked from {$where}."
|
||||
: "This address is blocked from {$where} until ".$ban->expires_at->format('j F Y, H:i').'.';
|
||||
? __('This address is blocked from :where.', ['where' => $where])
|
||||
: __('This address is blocked from :where until :when.', ['where' => $where, 'when' => $ban->expires_at->format('j F Y, H:i')]);
|
||||
|
||||
// A ban that followed too many attempts is "429 Too Many Requests" and says when to come
|
||||
// back; one that was given by hand is a plain "403 Forbidden".
|
||||
|
||||
@@ -49,7 +49,7 @@ class MediaController
|
||||
$room = $this->library->room();
|
||||
|
||||
if ($file->getSize() > $room['left']) {
|
||||
$message = 'The media library is full: this file does not fit in the room that is left. Remove files that are no longer used, or raise manager.media.max_total_gb.';
|
||||
$message = __('The media library is full: this file does not fit in the room that is left. Remove files that are no longer used, or raise manager.media.max_total_gb.');
|
||||
|
||||
return response()->json(['message' => $message, 'errors' => ['file' => [$message]], 'storage' => $room], 422);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ class MediaController
|
||||
{
|
||||
Log::warning('Media storage failed.', ['error' => $e->getMessage(), 'status' => $e->status]);
|
||||
|
||||
return response()->json(['message' => self::UNAVAILABLE], 502);
|
||||
return response()->json(['message' => __(self::UNAVAILABLE)], 502);
|
||||
}
|
||||
|
||||
/** @return array{max_file_mb: int, extensions: list<string>, storage: array{used: int, limit: int, left: int}} */
|
||||
|
||||
@@ -28,7 +28,7 @@ class LabelController
|
||||
$name = $request->string('name')->trim()->toString();
|
||||
|
||||
if (! $this->labels->create($type, $name)) {
|
||||
return response()->json(['message' => "The {$type} \"{$name}\" already exists.", 'errors' => ['name' => ["The {$type} \"{$name}\" already exists."]]], 422);
|
||||
return response()->json(['message' => $already = __('The :type ":name" already exists.', ['type' => __($type), 'name' => $name]), 'errors' => ['name' => [$already]]], 422);
|
||||
}
|
||||
|
||||
return response()->json(['created' => $name], 201);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace IriksIT\Manager\Modules\Statistics;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use IriksIT\Manager\Support\Names;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Throwable;
|
||||
|
||||
@@ -42,7 +43,7 @@ class CountBots
|
||||
return $request->isMethod('GET')
|
||||
&& $response->getStatusCode() === 200
|
||||
&& is_string($name)
|
||||
&& ! str_starts_with($name, 'manager.')
|
||||
&& ! str_starts_with($name, Names::routePrefix())
|
||||
// The same promise as for visitors: who asks not to be followed is not counted at all.
|
||||
&& $request->header('Sec-GPC') !== '1'
|
||||
&& $request->header('DNT') !== '1';
|
||||
|
||||
@@ -103,7 +103,7 @@ class AccountController
|
||||
app(AuditTrail::class)->about($user);
|
||||
|
||||
if ($user->is($me)) {
|
||||
return response()->json(['message' => 'You cannot delete your own account.'], 422);
|
||||
return response()->json(['message' => __('You cannot delete your own account.')], 422);
|
||||
}
|
||||
|
||||
$user->managerGroups()->detach();
|
||||
@@ -144,7 +144,7 @@ class AccountController
|
||||
$email = $request->string('email')->trim()->lower()->toString();
|
||||
|
||||
if ($this->model()::query()->where('email', $email)->when($user !== null, fn ($query) => $query->whereKeyNot($user->getKey()))->exists()) {
|
||||
throw ValidationException::withMessages(['email' => 'Another account already uses this email address.']);
|
||||
throw ValidationException::withMessages(['email' => __('Another account already uses this email address.')]);
|
||||
}
|
||||
|
||||
return ['name' => $request->string('name')->trim()->toString(), 'email' => $email];
|
||||
@@ -163,7 +163,7 @@ class AccountController
|
||||
$groups = Group::query()->whereKey($ids)->get();
|
||||
|
||||
if ($groups->count() !== count($ids) || $groups->contains(fn (Group $group) => ! $me->managerMayGive($group))) {
|
||||
throw ValidationException::withMessages(['groups' => 'You can only choose groups that allow nothing more than your own account.']);
|
||||
throw ValidationException::withMessages(['groups' => __('You can only choose groups that allow nothing more than your own account.')]);
|
||||
}
|
||||
|
||||
return $ids;
|
||||
|
||||
@@ -120,7 +120,7 @@ final class ModuleRegistry
|
||||
$sections = [];
|
||||
|
||||
foreach ($this->permissions() as $permission) {
|
||||
$sections[$permission->section][] = ['value' => $permission->value, 'label' => $permission->label, 'needs' => $permission->needs];
|
||||
$sections[__($permission->section)][] = ['value' => $permission->value, 'label' => __($permission->label), 'needs' => $permission->needs];
|
||||
}
|
||||
|
||||
$catalogue = [];
|
||||
@@ -137,7 +137,7 @@ final class ModuleRegistry
|
||||
$items = [];
|
||||
|
||||
foreach ($this->active() as $module) {
|
||||
array_push($items, ...$module->navigation());
|
||||
array_push($items, ...array_map(fn (array $item) => [...$item, 'label' => __($item['label'])], $module->navigation()));
|
||||
}
|
||||
|
||||
return $items;
|
||||
|
||||
Reference in new issue
Block a user