1 | <?php |
||
19 | abstract class lang |
||
20 | { |
||
21 | /** |
||
22 | * @var string default language code |
||
23 | */ |
||
24 | const DEFAULT_LANGUAGE = "en"; |
||
25 | |||
26 | /** |
||
27 | * Use this property to set an error callback - you can use this for error reporting in test-suites. |
||
28 | * |
||
29 | * @var callable function ($message) : void |
||
30 | */ |
||
31 | public static $on_error; |
||
32 | |||
33 | /** |
||
34 | * @var string active language code |
||
35 | */ |
||
36 | protected static $code = self::DEFAULT_LANGUAGE; |
||
37 | |||
38 | /** |
||
39 | * @var (string|callable)[][] map where "{domain}/{code}" => translation strings or callables |
||
40 | */ |
||
41 | protected static $lang = []; |
||
42 | |||
43 | /** |
||
44 | * @var string[] map where "{domain}" or "{domain}/{code}" => absolute path to language file |
||
45 | */ |
||
46 | protected static $paths = []; |
||
47 | |||
48 | /** |
||
49 | * Change the current active language code. |
||
50 | * |
||
51 | * @param string $code two-letter ISO-639-1 language code (such as "en", "da", "es", etc.) |
||
52 | * |
||
53 | * @link https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes |
||
54 | */ |
||
55 | 1 | public static function set($code) |
|
59 | |||
60 | /** |
||
61 | * Get the current active language code. |
||
62 | * |
||
63 | * @see set() |
||
64 | */ |
||
65 | 1 | public static function get() |
|
66 | { |
||
67 | 1 | return self::$code; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * Register the physical base path of language files for a given translation domain name. |
||
72 | * |
||
73 | * @param string $domain translation domain name |
||
74 | * @param string $path absolute path to language directory (or base filename, without ".php") |
||
75 | */ |
||
76 | 1 | public static function register($domain, $path) |
|
80 | |||
81 | /** |
||
82 | * Translate the given text in the given domain and substitute the given tokens. |
||
83 | * |
||
84 | * @param string $domain translation domain name |
||
85 | * @param string $text english text |
||
86 | * @param array|null $tokens map where token name => replacement string |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | 1 | public static function text($domain, $text, array $tokens = null) |
|
94 | |||
95 | /** |
||
96 | * Obtain a translation callback for a given domain, optionally for a specific language. |
||
97 | * |
||
98 | * The returned function has the following signature: |
||
99 | * |
||
100 | * function (string $text, array $tokens) : string |
||
101 | * |
||
102 | * This may be useful in a view/template, for example, so you don't have to repeat the |
||
103 | * domain name for every call. It may also be useful to inject this function as a dependency. |
||
104 | * |
||
105 | * @param string $domain translation domain name |
||
106 | * @param string|null $code optional language code (defaults to the current language) |
||
107 | * |
||
108 | * @return callable function ($text, array $tokens) : string |
||
109 | */ |
||
110 | 1 | public static function domain($domain, $code = null) |
|
116 | |||
117 | /** |
||
118 | * This is the lowest-level function, which requires every parameter to be given explicitly. |
||
119 | * |
||
120 | * @param string $code two-letter ISO-639-1 language code |
||
121 | * @param string $domain translation domain name |
||
122 | * @param string $text english text |
||
123 | * @param array $tokens map where token name => replacement string |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | 1 | public static function translate($code, $domain, $text, array $tokens = null) |
|
184 | |||
185 | /** |
||
186 | * Reset the internal state of the language registry. |
||
187 | * |
||
188 | * This may be useful for unit-testing or other special situations. |
||
189 | */ |
||
190 | 1 | public static function reset() |
|
196 | |||
197 | /** |
||
198 | * Internally find and load a given language file. |
||
199 | * |
||
200 | * @param string $name full language file base name, e.g. "{domain}/{code}" |
||
201 | */ |
||
202 | 1 | protected static function load($name) |
|
243 | } |
||
244 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: