| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Omatech\Mage\Core\Providers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Translation\Translator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Contracts\Translation\Loader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Contracts\Translation\Translator as TranslatorContract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Omatech\Mage\Core\Domains\Translations\Translation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Omatech\Mage\Core\Repositories\Translations\FindTranslation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Spatie\TranslationLoader\TranslationServiceProvider as SpatieTranslatorServiceProvider; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | class TranslatorServiceProvider extends SpatieTranslatorServiceProvider | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |      * Register any other events for your application. | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 19 | 82 |  |     public function register() | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 21 | 82 |  |         parent::register(); | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         $this->app->singleton('translator', function ($app) { | 
            
                                                                        
                            
            
                                    
            
            
                | 24 | 4 |  |             $loader = $app['translation.loader']; | 
            
                                                                        
                            
            
                                    
            
            
                | 25 | 4 |  |             $locale = $app['config']['app.locale']; | 
            
                                                                        
                            
            
                                    
            
            
                | 26 | 4 |  |             $localeFallback = $app['config']['app.fallback_locale']; | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |             $translator = (new class($loader, $locale) extends Translator implements TranslatorContract { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 4 |  |                 public function __construct(Loader $loader, string $locale) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 4 |  |                     parent::__construct($loader, $locale); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 32 | 4 |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 3 |  |                 public function get($key, array $replace = [], $locale = null, $fallback = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                 { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 3 |  |                     $trans = Translation::find(new FindTranslation, ['key' => $key]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 3 |  |                     if (!$trans->getId()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 1 |  |                         $trans->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 3 |  |                     return parent::get($key, $replace, $locale, $fallback); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 43 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 3 |  |                 public function insertKeyValue($value, $key = null, $params = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 3 |  |                     if ($key == null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 1 |  |                         return $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 2 |  |                     $trans = Translation::find(new FindTranslation, ['key' => $key]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 2 |  |                     if (!$trans->getId()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 2 |  |                         $trans->setTranslation(app()->getLocale(), $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 2 |  |                         $trans->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 2 |  |                     return $this->get($key, $params); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 59 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             $translator->setFallback($localeFallback); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             return $translator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         }); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 67 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |  |