Skip to content

Commit

Permalink
fix: bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kargnas committed Aug 2, 2024
1 parent 1adec22 commit 3566fd1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Console/TranslateCrowdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use CrowdinApiClient\Model\StringTranslation;
use CrowdinApiClient\Model\StringTranslationApproval;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Kargnas\LaravelAiTranslator\AI\AIProvider;

class TranslateCrowdin extends Command
Expand Down Expand Up @@ -314,7 +315,7 @@ public function translate() {
$this->line(" Retrieving approvals...");
$approvals = $this->getApprovals($this->selectedProject['id'], $file['id'], $targetLanguage['id']);

$referenceApprovals = collect($this->referenceLanguages)->reject($this->selectedProject['sourceLanguage']['id'])->mapWithKeys(function ($refLocale) use ($allStrings, $file) {
$referenceApprovals = collect($this->referenceLanguages)->mapWithKeys(function ($refLocale) use ($allStrings, $file) {
$this->line(" Retrieving approvals for reference language...: {$refLocale}");
$approvals = $this->getApprovals($this->selectedProject['id'], $file['id'], $refLocale);

Expand Down Expand Up @@ -371,15 +372,19 @@ public function translate() {
$context = null;
}

/** @var Collection $references */
$references = $referenceApprovals->map(function ($items) use ($string) {
return $items[$string['identifier']] ?? "";
})->filter(function ($value) {
return strlen($value) > 0;
});

return [
$string['identifier'] => [
'text' => $string['text'],
// source text 를 그대로 쓰면 안되고 Translation 에서 따로 가져와서 써야한다.
'text' => $references->only($this->selectedProject['sourceLanguage']['id'])->first() ?? $string['text'],
'context' => $context,
'references' => $referenceApprovals->map(function ($items) use ($string) {
return $items[$string['identifier']] ?? "";
})->filter(function ($value) {
return strlen($value) > 0;
}),
'references' => $references->except($this->selectedProject['sourceLanguage']['id'])->toArray(),
],
];
})->toArray(),
Expand Down

0 comments on commit 3566fd1

Please sign in to comment.