Completed
Push — master ( 5a826a...3b609b )
by Mike
06:09
created

Translatable::normalizeLocale()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 3
1
<?php
2
3
namespace MikeZange\LaravelDatabaseTranslation;
4
5
use Spatie\Translatable\HasTranslations;
6
7
trait Translatable
8
{
9
    use HasTranslations;
10
11
    /**
12
     * @param string $key
13
     *
14
     * @param string $locale
15
     * @param bool $useFallbackLocale
16
     *
17
     * @return mixed|string
18
     */
19
20
21
    protected function normalizeLocale(string $key, string $locale, bool $useFallbackLocale) : string
22
    {
23
        if (in_array($locale, $this->getTranslatedLocales($key))) {
24
            return $locale;
25
        }
26
27
        if (!$useFallbackLocale) {
28
            return $locale;
29
        }
30
31
        if (!is_null($fallbackLocale = config('app.fallback_locale'))) {
32
            return $fallbackLocale;
33
        }
34
35
        return $locale;
36
    }
37
}
38