Skip to content

Commit d69184c

Browse files
authored
Merge pull request #6 from litstack/feat/translate-meta
Translate Meta
2 parents 87d5f62 + 70131c1 commit d69184c

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

src/FormModelTranslator.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Litstack\Deeplable;
44

5-
use AwStudio\Deeplable\Facades\Translator;
6-
use AwStudio\Deeplable\Translators\BaseTranslator;
75
use Closure;
6+
use Ignite\Crud\Models\Media;
87
use Ignite\Crud\Models\Repeatable;
9-
use Illuminate\Database\Eloquent\Collection;
108
use Illuminate\Database\Eloquent\Model;
9+
use AwStudio\Deeplable\Facades\Translator;
10+
use Illuminate\Database\Eloquent\Collection;
11+
use AwStudio\Deeplable\Translators\BaseTranslator;
12+
use Litstack\Meta\Models\Meta;
1113

1214
class FormModelTranslator extends BaseTranslator
1315
{
@@ -86,6 +88,7 @@ public function translateAttributes(Model $model, $attributes, string $targetLan
8688
$this->translateRepeatablesInCollection($collection, $targetLang, $force);
8789
continue;
8890
}
91+
8992
$translation = $this->api->translate(
9093
(string) $model->getAttribute($attribute),
9194
$targetLang,
@@ -94,6 +97,8 @@ public function translateAttributes(Model $model, $attributes, string $targetLan
9497

9598
$this->translateAttribute($model, $attribute, $targetLang, $translation, $force);
9699
}
100+
101+
$this->translateMeta($model, $targetLang, $force);
97102
}
98103

99104

@@ -110,7 +115,32 @@ public function translateRepeatablesInCollection(Collection $collection, string
110115
foreach ($collection as $item) {
111116
if ($item instanceof Repeatable) {
112117
Translator::for($item)
113-
->translate($item, $locale, config('translatable.fallback_locale'), $force);
118+
->translate($item, $locale, config('translatable.fallback_locale'), $force);
119+
}
120+
if($item instanceof Media){
121+
Translator::for($item)
122+
->translate($item, $locale, config('translatable.fallback_locale'), $force);
123+
}
124+
}
125+
}
126+
127+
/**
128+
* Translate meta.
129+
*
130+
* @param Model $model
131+
* @param string $targetLang
132+
* @param boolean $force
133+
* @return void
134+
*/
135+
public function translateMeta(Model $model, string $targetLang, bool $force = true)
136+
{
137+
// check if model has meta
138+
if (method_exists($model, 'meta')) {
139+
$item = $model->meta()->first();
140+
141+
if ($item instanceof Meta) {
142+
Translator::for($item)
143+
->translate($item, $targetLang, config('translatable.fallback_locale'), $force);
114144
}
115145
}
116146
}

0 commit comments

Comments
 (0)