Skip to content

Commit 2362184

Browse files
committed
Chore(Services): refactor translateLangFiles func
1 parent ef9d435 commit 2362184

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/Services/TranslateService.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,20 @@ private function translateLangFiles(array $content): array
7171
{
7272
$google = $this->setUpGoogleTranslate();
7373

74+
if (!empty($content)) {
75+
return $this->translateRecursive($content, $google);
76+
}
77+
}
78+
79+
private function translateRecursive($content, $google) : array
80+
{
7481
$trans_data = [];
7582

76-
if (!empty($content)) {
77-
foreach ($content as $first_key => $first_value) {
78-
if (is_array($first_value)) {
79-
foreach ($first_value as $second_key => $second_value) {
80-
if (is_array($second_value)) {
81-
foreach ($second_value as $key => $value) {
82-
$trans_data[$first_key][$second_key][$key] = $google->translate($value);
83-
}
84-
} else {
85-
$trans_data[$first_key][$second_key] = $google->translate($second_value);
86-
}
87-
}
88-
} else {
89-
$trans_data[$first_key] = $google->translate($first_value);
90-
}
83+
foreach ($content as $key => $value) {
84+
if (!is_array($value)) {
85+
$trans_data[$key] = $google->translate($value);
86+
} else {
87+
$trans_data[$key] = $this->translateRecursive($value, $google);
9188
}
9289
}
9390

0 commit comments

Comments
 (0)