Browse Source

translate fix

Andrew 2 months ago
parent
commit
cf6bf8f61e
1 changed files with 4 additions and 26 deletions
  1. 4
    26
      app/Service/DeepLService.php

+ 4
- 26
app/Service/DeepLService.php View File

@@ -45,37 +45,15 @@ class DeepLService {
45 45
     {
46 46
         return Action::make("translate{$actionName}")
47 47
             ->label("翻譯")
48
-            ->visible(fn ($arguments) => ($arguments['locale'] ?? '') != 'zh_TW')
49
-            ->action(function ($set, $arguments, Action $action) use ($fieldNames) {
48
+            ->visible(fn ($arguments) => $arguments['locale'] != 'zh_TW')
49
+            ->action(function ($set, $get, $arguments) use ($fieldNames) {
50 50
                 $locale = $arguments['locale'] ?? null;
51 51
                 if (!$locale) {
52 52
                     return;
53 53
                 }
54
-
55
-                // 1. Get the component (Translate wrapper) the action is attached to
56
-                $component = $action->getComponent();
57
-
58
-                // 2. Get the container (The Repeater Item) to find the unique path (e.g., spaceInfos.uuid-123)
59
-                $container = $component->getContainer();
60
-                $containerPath = $container->getStatePath();
61
-
62
-                // 3. Get the raw data for this specific row
63
-                $itemData = $container->getState();
64
-
65 54
                 foreach($fieldNames as $fieldName){
66
-                    // Safely retrieve the source text from the current item's data
67
-                    // We look for: fieldName -> zh_TW
68
-                    $sourceText = data_get($itemData, "{$fieldName}.zh_TW");
69
-
70
-                    if (empty($sourceText)) {
71
-                        continue;
72
-                    }
73
-
74
-                    $translateText = $this->translateWordings($sourceText, $locale);
75
-
76
-                    // 4. Set the new value using the Absolute Path
77
-                    // This ensures we update ONLY this specific row
78
-                    $set("{$containerPath}.{$fieldName}.{$locale}", $translateText);
55
+                    $translateText = $this->translateWordings($get("{$fieldName}.zh_TW"), $locale);
56
+                    $set("{$fieldName}.{$locale}", $translateText);
79 57
                 }
80 58
             });
81 59
     }