瀏覽代碼

translate fix

Andrew 2 月之前
父節點
當前提交
7db939ea66
共有 2 個文件被更改,包括 35 次插入26 次删除
  1. 25
    25
      app/Filament/Resources/EsgHistoryResource.php
  2. 10
    1
      app/Filament/Resources/UploadFileResource.php

+ 25
- 25
app/Filament/Resources/EsgHistoryResource.php 查看文件

@@ -47,21 +47,21 @@ class EsgHistoryResource extends Resource
47 47
 
48 48
                         return $years;
49 49
                     })->columnSpan(1),
50
-                    Select::make("selected_month")->label("月份")->options(function (){
50
+                    Select::make("selected_month")->label("月份")->options(function () {
51 51
                         $months = [];
52
-                        for($i=1;$i<=12 ;$i++){
52
+                        for ($i = 1; $i <= 12; $i++) {
53 53
                             $months[$i] = strval($i) . "月";
54 54
                         }
55 55
                         return $months;
56 56
                     })->default(now()->month)->columnSpan(1),
57
-                    Translate::make()->schema(fn (string $locale) => [
57
+                    Translate::make()->schema(fn(string $locale) => [
58 58
                         TextInput::make('title')->required($locale == 'zh_TW')->label("標題"),
59 59
                         Textarea::make('description')->required($locale == 'zh_TW')->label("內文"),
60 60
                     ])
61
-                    ->locales(["zh_TW", "en"])
62
-                    ->actions([
63
-                        app(DeepLService::class)->createTranslationAction("Main", ["title", 'description'])
64
-                    ])->columnSpanFull(),
61
+                        ->locales(["zh_TW", "en"])
62
+                        ->actions([
63
+                            app(DeepLService::class)->createTranslationAction("Main", ["title", 'description'])
64
+                        ])->columnSpanFull(),
65 65
                     Radio::make("visible")->label("顯示/不顯示")->options([1 => "顯示", 0 => "不顯示"])->inline()->default(1)->columnSpan(2)
66 66
                 ])->columns(3)
67 67
             ]);
@@ -77,26 +77,26 @@ class EsgHistoryResource extends Resource
77 77
             ])
78 78
             ->filters([
79 79
                 SelectFilter::make('selected_year')->label("年份")
80
-                ->options(function () {
81
-                    $currentYear = now()->year;
82
-                    $years = [];
83
-                    // 從 10 年前到 5 年後
84
-                    for ($i = $currentYear - 10; $i <= $currentYear + 10; $i++) {
85
-                        $years[$i] = strval($i) . '年';
86
-                    }
80
+                    ->options(function () {
81
+                        $currentYear = now()->year;
82
+                        $years = [];
83
+                        // 從 10 年前到 5 年後
84
+                        for ($i = $currentYear - 10; $i <= $currentYear + 10; $i++) {
85
+                            $years[$i] = strval($i) . '年';
86
+                        }
87 87
 
88
-                    return $years;
89
-                })
90
-                ->attribute('selected_year'),
88
+                        return $years;
89
+                    })
90
+                    ->attribute('selected_year'),
91 91
                 SelectFilter::make('selected_month')->label("月份")
92
-                ->options(function () {
93
-                    $months = [];
94
-                    for($i=1;$i<=12 ;$i++){
95
-                        $months[$i] = strval($i) . "月";
96
-                    }
97
-                    return $months;
98
-                })
99
-                ->attribute('selected_month'),
92
+                    ->options(function () {
93
+                        $months = [];
94
+                        for ($i = 1; $i <= 12; $i++) {
95
+                            $months[$i] = strval($i) . "月";
96
+                        }
97
+                        return $months;
98
+                    })
99
+                    ->attribute('selected_month'),
100 100
             ])
101 101
             ->actions([
102 102
                 Tables\Actions\EditAction::make(),

+ 10
- 1
app/Filament/Resources/UploadFileResource.php 查看文件

@@ -4,17 +4,20 @@ namespace App\Filament\Resources;
4 4
 
5 5
 use App\Filament\Resources\UploadFileResource\Pages;
6 6
 use App\Models\UploadFile;
7
+use App\Service\DeepLService;
7 8
 use Filament\Forms\Components\DatePicker;
8 9
 use Filament\Forms\Components\FileUpload;
9 10
 use Filament\Forms\Components\Group;
10 11
 use Filament\Forms\Components\Radio;
11 12
 use Filament\Forms\Components\Section;
13
+use Filament\Forms\Components\Textarea;
12 14
 use Filament\Forms\Components\TextInput;
13 15
 use Filament\Forms\Form;
14 16
 use Filament\Resources\Resource;
15 17
 use Filament\Tables;
16 18
 use Filament\Tables\Columns\TextColumn;
17 19
 use Filament\Tables\Table;
20
+use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
18 21
 
19 22
 class UploadFileResource extends Resource
20 23
 {
@@ -35,7 +38,13 @@ class UploadFileResource extends Resource
35 38
                 //
36 39
                 Section::make('')->schema([
37 40
                     Group::make()->schema([
38
-                        TextInput::make('title')->required()->label('標題'),
41
+                        Translate::make()->schema(fn(string $locale) => [
42
+                            TextInput::make('title')->required($locale == 'zh_TW')->label("標題"),
43
+                        ])
44
+                            ->locales(["zh_TW", "en"])
45
+                            ->actions([
46
+                                app(DeepLService::class)->createTranslationAction("Main", ["title"])
47
+                            ])->columnSpanFull(),
39 48
                         Radio::make('type')->label('類型')->options([1 => '社會公益'])->default(1),
40 49
                         Group::make()->schema([
41 50
                             FileUpload::make('upload_link')->label('上傳檔案')->directory('uploadFiles')->columnSpan(1),