@@ -83,8 +83,26 @@ public function __construct($model)
83
83
}
84
84
});
85
85
86
- $ this ->model ->bindEvent ('model.saveInternal ' , function () {
86
+ $ this ->model ->bindEvent ('model.getValidationAttributes ' , function ($ attributes ) {
87
+ if (($ locale = $ this ->translateContext ()) !== $ this ->translatableDefault ) {
88
+ foreach ($ this ->getTranslateDirty ($ locale ) as $ key => $ value ) {
89
+ if (!empty ($ value )) {
90
+ $ attributes [$ key ] = $ value ;
91
+ }
92
+ }
93
+ return $ attributes ;
94
+ }
95
+ }, 1000 );
96
+
97
+ $ this ->model ->bindEvent ('model.saveInternal ' , function () {
87
98
$ this ->syncTranslatableAttributes ();
99
+
100
+ if (method_exists ($ this ->model , 'validate ' )) {
101
+ foreach ($ this ->getDirtyLocales () as $ locale ) {
102
+ $ this ->translateContext ($ locale );
103
+ $ this ->model ->validate ();
104
+ }
105
+ }
88
106
});
89
107
}
90
108
@@ -316,25 +334,24 @@ public function syncTranslatableAttributes()
316
334
}
317
335
318
336
/**
319
- * Changes the active language for this model
320
- * @param string $context
321
- * @return void
337
+ * Change the active language for this model
338
+ * @param string|null $context
339
+ * @return string
322
340
*/
323
- public function translateContext ($ context = null )
341
+ public function translateContext ($ context = null ): string
324
342
{
325
- if ($ context === null ) {
326
- return $ this ->translatableContext ;
343
+ if ($ context ) {
344
+ $ this ->translatableContext = $ context ;
327
345
}
328
-
329
- $ this ->translatableContext = $ context ;
346
+ return $ this ->translatableContext ;
330
347
}
331
348
332
349
/**
333
- * Shorthand for translateContext method, and chainable.
334
- * @param string $context
350
+ * Chainable shorthand for translateContext method
351
+ * @param string|null $context
335
352
* @return self
336
353
*/
337
- public function lang ($ context = null )
354
+ public function lang ($ context = null ): self
338
355
{
339
356
$ this ->translateContext ($ context );
340
357
0 commit comments