Total Complexity | 8 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class Translate extends Resource |
||
9 | { |
||
10 | /** |
||
11 | * @param object $data |
||
12 | * @return $this |
||
13 | */ |
||
14 | public function data(object $data): static |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @param ?string $lang |
||
28 | * @return $this |
||
29 | * detect language if not declare in target or const TRANSLATE_DEFAULT |
||
30 | */ |
||
31 | public function target(?string $lang = null): static |
||
32 | { |
||
33 | $this->lang($lang); |
||
34 | $this->dir(); |
||
35 | $this->file(); |
||
36 | $this->setResponse(); |
||
37 | return $this; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param string|null $lang |
||
42 | * @return string |
||
43 | */ |
||
44 | public function lang(?string $lang = null): string |
||
45 | { |
||
46 | $this->setTarget('en'); |
||
47 | if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
||
48 | [$l] = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']); |
||
49 | $this->setTarget($l); |
||
50 | } |
||
51 | if(TRANSLATE_DEFAULT){ |
||
52 | $this->setTarget(TRANSLATE_DEFAULT); |
||
53 | } |
||
54 | if ($lang) { |
||
55 | $this->setTarget($lang); |
||
56 | } |
||
57 | return $this->getTarget(); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return object |
||
62 | */ |
||
63 | public function response(): object |
||
66 | } |
||
67 | |||
68 | } |