Localize::getScriptDir()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace LeKoala\FormElements;
4
5
use SilverStripe\i18n\i18n;
6
7
trait Localize
8
{
9
    /**
10
     * Override locale. If empty will default to current locale
11
     *
12
     * @var string
13
     */
14
    protected $locale = null;
15
16
    /**
17
     * Get locale to use for this field
18
     *
19
     * @return string
20
     */
21
    public function getLocale()
22
    {
23
        return $this->locale ?: i18n::get_locale();
24
    }
25
26
    /**
27
     * Determines the presented/processed format based on locale defaults,
28
     * instead of explicitly setting {@link setDateFormat()}.
29
     * Only applicable with {@link setHTML5(false)}.
30
     *
31
     * @param string $locale
32
     * @return $this
33
     */
34
    public function setLocale($locale)
35
    {
36
        $this->locale = $locale;
37
        return $this;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getScriptDir()
44
    {
45
        return i18n::get_script_direction($this->getLocale());
46
    }
47
}
48