@@ -94,26 +94,22 @@ public function getI18nId($locale = null)
94
94
*/
95
95
public function translate ($ locale = null , $ alowRevision = false )
96
96
{
97
- $ translation = null ;
98
- $ translationModel = app ($ this ->translator );
99
-
100
97
if (!is_int ($ locale )) {
101
98
$ locale = $ this ->getI18nId ($ locale );
102
99
}
103
100
101
+ $ translation = null ;
104
102
if (isset ($ this ->id ) && $ locale ) {
105
- $ translation = $ translationModel ::where ($ this ->translatorField , $ this ->id )
106
- ->where ($ this ->localeField , $ locale )->first ();
107
-
108
- if (!$ translation ) {
109
- $ translation = $ translationModel ;
110
- }
103
+ $ localeField = $ this ->getLocaleField ();
104
+ $ translation = $ this ->translations ->filter (function ($ item ) use ($ locale , $ localeField ) {
105
+ return $ item ->{$ localeField } === $ locale ;
106
+ })->first ();
111
107
}
112
108
113
109
if ($ alowRevision == true ) {
114
110
if (isset ($ translation ->show_revision )) {
115
111
if ($ translation ->show_revision == 1 ) {
116
- $ translation = $ translation ->setAttributeNames (unserialize ($ translation ->revision ));
112
+ $ this -> translation = $ translation ->setAttributeNames (unserialize ($ translation ->revision ));
117
113
}
118
114
}
119
115
}
@@ -199,7 +195,7 @@ public function saveTranslations($translatableId)
199
195
$ translatorId = array_get ($ translationValues , $ this ->translatorField );
200
196
$ localeId = array_get ($ translationValues , $ this ->localeField );
201
197
202
- $ translation = $ this ->translator :: where ($ this ->translatorField , $ translatorId )
198
+ $ translation = $ this ->translator -> where ($ this ->translatorField , $ translatorId )
203
199
->where ($ this ->localeField , $ localeId )
204
200
->first ();
205
201
0 commit comments