Completed
Push — master ( d70e6c...215c97 )
by Nazar
04:09
created

Prefix::__call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package   CleverStyle Framework
4
 * @author    Nazar Mokrynskyi <[email protected]>
5
 * @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi
6
 * @license   MIT License, see license.txt
7
 */
8
namespace cs\Language;
9
use
10
	cs\Language;
11
/**
12
 * Class for simplified work with translations, when using common prefix
13
 */
14
class Prefix {
15
	/**
16
	 * @var string
17
	 */
18
	protected $prefix;
19
	/**
20
	 * Initialization with some prefix
21
	 *
22
	 * @param string $prefix
23
	 */
24 24
	function __construct ($prefix) {
25 24
		$this->prefix = $prefix;
26 24
	}
27
	/**
28
	 * Get translation
29
	 *
30
	 * @param string       $item
31
	 * @param false|string $language If specified - translation for specified language will be returned, otherwise for current
32
	 *
33
	 * @return string
34
	 */
35
	function get ($item, $language = false) {
36
		return Language::instance()->get($item, $language, $this->prefix);
37
	}
38
	/**
39
	 * Get translation
40
	 *
41
	 * @param string $item
42
	 *
43
	 * @return string
44
	 */
45
	function __get ($item) {
46
		return Language::instance()->get($item, false, $this->prefix);
47
	}
48
	/**
49
	 * Time formatting according to the current language (adding correct endings)
50
	 *
51
	 * @param int    $in   time (number)
52
	 * @param string $type Type of formatting<br>
53
	 *                     s - seconds<br>m - minutes<br>h - hours<br>d - days<br>M - months<br>y - years
54
	 *
55
	 * @return string
56
	 */
57
	function time ($in, $type) {
58
		return Language::instance()->time($in, $type);
59
	}
60
	/**
61
	 * Allows to use formatted strings in translations
62
	 *
63
	 * @see format()
64
	 *
65
	 * @param string $item
66
	 * @param array  $arguments
67
	 *
68
	 * @return string
69
	 */
70
	function __call ($item, $arguments) {
71
		return Language::instance()->format($item, $arguments, false, $this->prefix);
72
	}
73
	/**
74
	 * Allows to use formatted strings in translations
75
	 *
76
	 * @param string       $item
77
	 * @param string[]     $arguments
78
	 * @param false|string $language If specified - translation for specified language will be returned, otherwise for current
79
	 *
80
	 * @return string
81
	 */
82
	function format ($item, $arguments, $language = false) {
83
		return Language::instance()->format($item, $arguments, $language, $this->prefix);
84
	}
85
	/**
86
	 * Formatting data according to language locale (translating months names, days of week, etc.)
87
	 *
88
	 * @param string|string[] $data
89
	 * @param bool            $short_may When in date() or similar functions "M" format option is used, third month "May" have the same short textual
90
	 *                                   representation as full, so, this option allows to specify, which exactly form of representation do you want
91
	 *
92
	 * @return string|string[]
93
	 */
94
	function to_locale ($data, $short_may = false) {
95
		return Language::instance()->to_locale($data, $short_may);
96
	}
97
}
98