2
2
3
3
namespace Litstack \Deeplable ;
4
4
5
- use AwStudio \Deeplable \Facades \Translator ;
6
- use AwStudio \Deeplable \Translators \BaseTranslator ;
7
5
use Closure ;
6
+ use Ignite \Crud \Models \Media ;
8
7
use Ignite \Crud \Models \Repeatable ;
9
- use Illuminate \Database \Eloquent \Collection ;
10
8
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 ;
11
13
12
14
class FormModelTranslator extends BaseTranslator
13
15
{
@@ -86,6 +88,7 @@ public function translateAttributes(Model $model, $attributes, string $targetLan
86
88
$ this ->translateRepeatablesInCollection ($ collection , $ targetLang , $ force );
87
89
continue ;
88
90
}
91
+
89
92
$ translation = $ this ->api ->translate (
90
93
(string ) $ model ->getAttribute ($ attribute ),
91
94
$ targetLang ,
@@ -94,6 +97,8 @@ public function translateAttributes(Model $model, $attributes, string $targetLan
94
97
95
98
$ this ->translateAttribute ($ model , $ attribute , $ targetLang , $ translation , $ force );
96
99
}
100
+
101
+ $ this ->translateMeta ($ model , $ targetLang , $ force );
97
102
}
98
103
99
104
@@ -110,7 +115,32 @@ public function translateRepeatablesInCollection(Collection $collection, string
110
115
foreach ($ collection as $ item ) {
111
116
if ($ item instanceof Repeatable) {
112
117
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 );
114
144
}
115
145
}
116
146
}
0 commit comments