Andrew преди 2 месеца
родител
ревизия
64169cbddd
променени са 1 файла, в които са добавени 16 реда и са изтрити 4 реда
  1. 16
    4
      app/Service/DeepLService.php

+ 16
- 4
app/Service/DeepLService.php Целия файл

@@ -46,16 +46,28 @@ class DeepLService {
46 46
         return Action::make("translate{$actionName}")
47 47
             ->label("翻譯")
48 48
             ->visible(fn ($arguments) => $arguments['locale'] != 'zh_TW')
49
-            ->action(function ($set, $get, $arguments) use ($fieldNames) {
49
+            ->action(function ($set, $get, $arguments, $component) use ($fieldNames) {
50
+
50 51
                 $locale = $arguments['locale'] ?? null;
51 52
                 if (!$locale) {
52 53
                     return;
53 54
                 }
54
-                foreach($fieldNames as $fieldName){
55
-                    $translateText = $this->translateWordings($get("{$fieldName}.zh_TW"), $locale);
56
-                    $set("{$fieldName}.{$locale}", $translateText);
55
+
56
+                // Get the current repeater item’s state path (e.g., "spaceInfos.1")
57
+                $itemPath = $component->getContainer()->getStatePath();
58
+
59
+                foreach ($fieldNames as $fieldName) {
60
+
61
+                    // Get value inside the specific repeater item
62
+                    $source = $get("{$itemPath}.{$fieldName}.zh_TW");
63
+
64
+                    $translated = $this->translateWordings($source, $locale);
65
+
66
+                    // Set translated value back into this repeater item
67
+                    $set("{$itemPath}.{$fieldName}.{$locale}", $translated);
57 68
                 }
58 69
             });
70
+
59 71
     }
60 72
 
61 73
     public function buildGlossary($glossaryName, $glossaryLocaleFrom, $glossaryLocaleTo, $glossaryItems){