Skip to content

Commit dfbb81c

Browse files
committed
Localizing "labels" for Model / Columns/ Fields / Actions / Sections / Notifications with resource/lang for en and de
1 parent b427218 commit dfbb81c

File tree

4 files changed

+148
-9
lines changed

4 files changed

+148
-9
lines changed

resources/lang/de/api-service.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
// translations for Rupadana/ApiService
4+
return [
5+
6+
/*
7+
|--------------------------------------------------------------------------
8+
| Model
9+
|--------------------------------------------------------------------------
10+
*/
11+
12+
'model' => 'Token',
13+
'models' => 'Tokens',
14+
15+
/*
16+
|--------------------------------------------------------------------------
17+
| Table Columns
18+
|--------------------------------------------------------------------------
19+
*/
20+
21+
'column.name' => 'Name',
22+
'column.user' => 'Benutzer',
23+
'column.abilities' => 'Fähigkeiten',
24+
'column.created_at' => 'Erstellt am',
25+
26+
/*
27+
|--------------------------------------------------------------------------
28+
| Form Fields
29+
|--------------------------------------------------------------------------
30+
*/
31+
32+
'field.name' => 'Name',
33+
'field.user' => 'Benutzer',
34+
'field.ability' => 'Fähigkeit',
35+
36+
/*
37+
|--------------------------------------------------------------------------
38+
| Form Actions
39+
|--------------------------------------------------------------------------
40+
*/
41+
42+
'action.select_all' => 'Alle auswählen',
43+
'action.unselect_all' => 'Alle abwählen',
44+
'action.close' => 'Schließen',
45+
46+
/*
47+
|--------------------------------------------------------------------------
48+
| Section & Tabs
49+
|--------------------------------------------------------------------------
50+
*/
51+
52+
'section.general' => 'Allgemein:',
53+
'section.abilities' => 'Fähigkeiten:',
54+
'section.abilities.description' => 'Wählen Sie die Fähigkeiten des Tokens aus',
55+
56+
/*
57+
|--------------------------------------------------------------------------
58+
| Notifications
59+
|--------------------------------------------------------------------------
60+
*/
61+
62+
'notification.token.created' => 'Token erstellt, speichern Sie ihn!',
63+
64+
];

resources/lang/en/api-service.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,62 @@
33
// translations for Rupadana/ApiService
44
return [
55

6+
/*
7+
|--------------------------------------------------------------------------
8+
| Model
9+
|--------------------------------------------------------------------------
10+
*/
11+
12+
'model' => 'Token',
13+
'models' => 'Tokens',
14+
15+
/*
16+
|--------------------------------------------------------------------------
17+
| Table Columns
18+
|--------------------------------------------------------------------------
19+
*/
20+
21+
'column.name' => 'Name',
22+
'column.user' => 'User',
23+
'column.abilities' => 'Abilities',
24+
'column.created_at' => 'Created at',
25+
26+
/*
27+
|--------------------------------------------------------------------------
28+
| Form Fields
29+
|--------------------------------------------------------------------------
30+
*/
31+
32+
'field.name' => 'Name',
33+
'field.user' => 'User',
34+
'field.ability' => 'Ability',
35+
36+
/*
37+
|--------------------------------------------------------------------------
38+
| Form Actions
39+
|--------------------------------------------------------------------------
40+
*/
41+
42+
'action.select_all' => 'Select all',
43+
'action.unselect_all' => 'Unselect all',
44+
'action.close' => 'Close',
45+
46+
/*
47+
|--------------------------------------------------------------------------
48+
| Section & Tabs
49+
|--------------------------------------------------------------------------
50+
*/
51+
52+
'section.general' => 'General:',
53+
'section.abilities' => 'Abilities:',
54+
'section.abilities.description' => 'Select abilities of the token',
55+
56+
/*
57+
|--------------------------------------------------------------------------
58+
| Notifications
59+
|--------------------------------------------------------------------------
60+
*/
61+
62+
'notification.token.created' => 'Token created, save it!',
63+
664
];

src/Resources/TokenResource.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ public static function form(Form $form): Form
3232
{
3333
return $form
3434
->schema([
35-
Section::make('General')
35+
Section::make( __('api-service::api-service.section.general'))
3636
->schema([
3737
TextInput::make('name')
38+
->label(__('api-service::api-service.field.name'))
3839
->required(),
3940
Select::make('tokenable_id')
4041
->options(User::all()->pluck('name', 'id'))
41-
->label('User')
42+
->label(__('api-service::api-service.field.user'))
4243
->hidden(function () {
4344
$user = auth()->user();
4445

@@ -53,8 +54,8 @@ public static function form(Form $form): Form
5354
->required(),
5455
]),
5556

56-
Section::make('Abilities')
57-
->description('Select abilities of the token')
57+
Section::make(__('api-service::api-service.section.abilities'))
58+
->description(__('api-service::api-service.section.abilities.description'))
5859
->schema(static::getAbilitiesSchema()),
5960
]);
6061
}
@@ -72,13 +73,15 @@ public static function getAbilitiesSchema(): array
7273
$extractedAbilities[$a] = __($a);
7374
}
7475
}
76+
7577
$schema[] = Section::make(str($resource)->beforeLast('Resource')->explode('\\')->last())
7678
->description($resource)
7779
->schema([
7880
CheckboxList::make('ability')
81+
->label(__('api-service::api-service.field.ability'))
7982
->options($extractedAbilities)
80-
->selectAllAction(fn (Action $action) => $action->label('Select all'))
81-
->deselectAllAction(fn (Action $action) => $action->label('Unselect All'))
83+
->selectAllAction(fn (Action $action) => $action->label( __('api-service::api-service.action.select_all')))
84+
->deselectAllAction(fn (Action $action) => $action->label( __('api-service::api-service.action.unselect_all')))
8285
->bulkToggleable(),
8386
])
8487
->collapsible();
@@ -91,13 +94,16 @@ public static function table(Table $table): Table
9194
{
9295
return $table
9396
->columns([
94-
TextColumn::make('name'),
97+
TextColumn::make('name')
98+
->label(__('api-service::api-service.column.name')),
9599
TextColumn::make('tokenable.name')
96-
->label('User'),
100+
->label(__('api-service::api-service.column.user')),
97101
TextColumn::make('abilities')
102+
->label(__('api-service::api-service.column.abilities'))
98103
->badge()
99104
->words(1),
100105
TextColumn::make('created_at')
106+
->label(__('api-service::api-service.column.created_at'))
101107
->toggleable(isToggledHiddenByDefault: true),
102108
])
103109
->filters([
@@ -156,4 +162,14 @@ public static function getNavigationIcon(): ?string
156162
{
157163
return config('api-service.navigation.token.icon', 'heroicon-o-key');
158164
}
165+
166+
public static function getModelLabel(): string
167+
{
168+
return __('api-service::api-service.model');
169+
}
170+
171+
public static function getPluralLabel(): string
172+
{
173+
return __('api-service::api-service.models');
174+
}
159175
}

src/Resources/TokenResource/Pages/CreateToken.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ protected function handleRecordCreation(array $data): Model
3030
protected function getCreatedNotification(): ?Notification
3131
{
3232
return Notification::make()
33-
->title('Token created, save it!')
33+
->title(__('api-service::api-service.notification.token.created'))
3434
->body($this->newToken->plainTextToken)
3535
->persistent()
3636
->actions([
3737
Action::make('close')
38+
->label(__('api-service::api-service.action.close'))
3839
->close(),
3940
])
4041
->success();

0 commit comments

Comments
 (0)