| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Aitor24\Laralang; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Aitor24\Laralang\Builder\ApertiumTrans; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Aitor24\Laralang\Builder\MymemoryTrans; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Aitor24\Laralang\Models\DB_Translation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class Builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      * Get the trnaslation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * @param string $string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @return object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     public static function trans($string) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $translator = config('laralang.default.translator'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         if (!in_array(config('laralang.default.translator'), ['apertium', 'mymemory'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             return "<font style='color:red;'>Laralang doesn't support $translator translator. Check config</font>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             if (config('laralang.default.translator') == 'mymemory') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |                 return new MymemoryTrans($string); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             } elseif (config('laralang.default.translator') == 'apertium') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                 return new ApertiumTrans($string); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * Get the languages that translations has been translated. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 37 |  | View Code Duplication |     public static function toLanguages() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $locales = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $translations = DB_Translation::distinct()->select('to_lang')->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         foreach ($translations as $object) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             array_push($locales, $object->to_lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         return $locales; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * Get the languages from translations has been translated. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 53 |  | View Code Duplication |     public static function fromLanguages() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $locales = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $translations = DB_Translation::distinct()->select('from_lang')->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         foreach ($translations as $object) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             array_push($locales, $object->from_lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         return $locales; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * Get all the available languages. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |     public static function allLanguages() | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |         return ['English' => 'en', 'Spanish' => 'es', 'Catalan' => 'ca', 'Portuguese' => 'pt', 'Chinese' => 'zh', 'Japanese' => 'ja', 'German' => 'de', 'French' => 'fr']; | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 73 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.