Completed
Push — master ( bbcdae...68da2d )
by Aitor Riba
02:02
created

Builder::checkAsset()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Aitor24\Laralang;
4
5
use Aitor24\Laralang\Builder\ApertiumTrans;
6
use Aitor24\Laralang\Builder\GoogleTrans;
7
use Aitor24\Laralang\Builder\MymemoryTrans;
8
use Aitor24\Laralang\Models\DB_Translation;
9
use URL;
10
11
class Builder
12
{
13
    /**
14
     * Get the trnaslation.
15
     *
16
     * @param string $string
17
     *
18
     * @return object
19
     */
20
    public static function trans($string)
21
    {
22
        $translator = config('laralang.default.translator');
23
        if (!in_array(config('laralang.default.translator'), ['apertium', 'mymemory', 'google'])) {
24
            return "<font style='color:red;'>Laralang doesn't support $translator translator. Check config</font>";
25
        } else {
26
            if (config('laralang.default.translator') == 'mymemory') {
27
                return new MymemoryTrans($string);
28
            } elseif (config('laralang.default.translator') == 'apertium') {
29
                return new ApertiumTrans($string);
30
            } elseif (config('laralang.default.translator') == 'google') {
31
                return new GoogleTrans($string);
32
            }
33
        }
34
    }
35
36
    /**
37
     * Get the languages that translations has been translated.
38
     *
39
     * @return array
40
     */
41 View Code Duplication
    public static function toLanguages()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
42
    {
43
        $locales = [];
44
        $translations = DB_Translation::distinct()->select('to_lang')->get();
45
        foreach ($translations as $object) {
46
            array_push($locales, $object->to_lang);
47
        }
48
49
        return $locales;
50
    }
51
52
    /**
53
     * Get the languages from translations has been translated.
54
     *
55
     * @return array
56
     */
57 View Code Duplication
    public static function fromLanguages()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
58
    {
59
        $locales = [];
60
        $translations = DB_Translation::distinct()->select('from_lang')->get();
61
        foreach ($translations as $object) {
62
            array_push($locales, $object->from_lang);
63
        }
64
65
        return $locales;
66
    }
67
68
    /**
69
     * Get all the available languages.
70
     *
71
     * @return array
72
     */
73
    public static function allLanguages()
74
    {
75
        return [
76
            'en' => 'English',
77
            'es' => 'Spanish',
78
            'ca' => 'Catalan',
79
            'pt' => 'Portuguese',
80
            'zh' => 'Chinese',
81
            'ja' => 'Japanese',
82
            'de' => 'German',
83
            'fr' => 'French',
84
            'eu' => 'Basque',
85
            'ru' => 'Russian',
86
        ];
87
    }
88
}
89