1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * For full copyright and license information, please see the LICENSE.txt
8: * Redistributions of files must retain the above copyright notice.
9: *
10: * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11: * @link https://cakephp.org CakePHP(tm) Project
12: * @since 3.0.0
13: * @license https://opensource.org/licenses/mit-license.php MIT License
14: */
15: use Cake\I18n\I18n;
16:
17: if (!function_exists('__')) {
18: /**
19: * Returns a translated string if one is found; Otherwise, the submitted message.
20: *
21: * @param string $singular Text to translate.
22: * @param array ...$args Array with arguments or multiple arguments in function.
23: * @return string|null The translated text, or null if invalid.
24: * @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__
25: */
26: function __($singular, ...$args)
27: {
28: if (!$singular) {
29: return null;
30: }
31: if (isset($args[0]) && is_array($args[0])) {
32: $args = $args[0];
33: }
34:
35: return I18n::getTranslator()->translate($singular, $args);
36: }
37:
38: }
39:
40: if (!function_exists('__n')) {
41: /**
42: * Returns correct plural form of message identified by $singular and $plural for count $count.
43: * Some languages have more than one form for plural messages dependent on the count.
44: *
45: * @param string $singular Singular text to translate.
46: * @param string $plural Plural text.
47: * @param int $count Count.
48: * @param array ...$args Array with arguments or multiple arguments in function.
49: * @return string|null Plural form of translated string, or null if invalid.
50: * @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__n
51: */
52: function __n($singular, $plural, $count, ...$args)
53: {
54: if (!$singular) {
55: return null;
56: }
57: if (isset($args[0]) && is_array($args[0])) {
58: $args = $args[0];
59: }
60:
61: return I18n::getTranslator()->translate(
62: $plural,
63: ['_count' => $count, '_singular' => $singular] + $args
64: );
65: }
66:
67: }
68:
69: if (!function_exists('__d')) {
70: /**
71: * Allows you to override the current domain for a single message lookup.
72: *
73: * @param string $domain Domain.
74: * @param string $msg String to translate.
75: * @param array ...$args Array with arguments or multiple arguments in function.
76: * @return string|null Translated string.
77: * @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__d
78: */
79: function __d($domain, $msg, ...$args)
80: {
81: if (!$msg) {
82: return null;
83: }
84: if (isset($args[0]) && is_array($args[0])) {
85: $args = $args[0];
86: }
87:
88: return I18n::getTranslator($domain)->translate($msg, $args);
89: }
90:
91: }
92:
93: if (!function_exists('__dn')) {
94: /**
95: * Allows you to override the current domain for a single plural message lookup.
96: * Returns correct plural form of message identified by $singular and $plural for count $count
97: * from domain $domain.
98: *
99: * @param string $domain Domain.
100: * @param string $singular Singular string to translate.
101: * @param string $plural Plural.
102: * @param int $count Count.
103: * @param array ...$args Array with arguments or multiple arguments in function.
104: * @return string|null Plural form of translated string.
105: * @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__dn
106: */
107: function __dn($domain, $singular, $plural, $count, ...$args)
108: {
109: if (!$singular) {
110: return null;
111: }
112: if (isset($args[0]) && is_array($args[0])) {
113: $args = $args[0];
114: }
115:
116: return I18n::getTranslator($domain)->translate(
117: $plural,
118: ['_count' => $count, '_singular' => $singular] + $args
119: );
120: }
121:
122: }
123:
124: if (!function_exists('__x')) {
125: /**
126: * Returns a translated string if one is found; Otherwise, the submitted message.
127: * The context is a unique identifier for the translations string that makes it unique
128: * within the same domain.
129: *
130: * @param string $context Context of the text.
131: * @param string $singular Text to translate.
132: * @param array ...$args Array with arguments or multiple arguments in function.
133: * @return string|null Translated string.
134: * @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__x
135: */
136: function __x($context, $singular, ...$args)
137: {
138: if (!$singular) {
139: return null;
140: }
141: if (isset($args[0]) && is_array($args[0])) {
142: $args = $args[0];
143: }
144:
145: return I18n::getTranslator()->translate($singular, ['_context' => $context] + $args);
146: }
147:
148: }
149:
150: if (!function_exists('__xn')) {
151: /**
152: * Returns correct plural form of message identified by $singular and $plural for count $count.
153: * Some languages have more than one form for plural messages dependent on the count.
154: * The context is a unique identifier for the translations string that makes it unique
155: * within the same domain.
156: *
157: * @param string $context Context of the text.
158: * @param string $singular Singular text to translate.
159: * @param string $plural Plural text.
160: * @param int $count Count.
161: * @param array ...$args Array with arguments or multiple arguments in function.
162: * @return string|null Plural form of translated string.
163: * @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__xn
164: */
165: function __xn($context, $singular, $plural, $count, ...$args)
166: {
167: if (!$singular) {
168: return null;
169: }
170: if (isset($args[0]) && is_array($args[0])) {
171: $args = $args[0];
172: }
173:
174: return I18n::getTranslator()->translate(
175: $plural,
176: ['_count' => $count, '_singular' => $singular, '_context' => $context] + $args
177: );
178: }
179:
180: }
181:
182: if (!function_exists('__dx')) {
183: /**
184: * Allows you to override the current domain for a single message lookup.
185: * The context is a unique identifier for the translations string that makes it unique
186: * within the same domain.
187: *
188: * @param string $domain Domain.
189: * @param string $context Context of the text.
190: * @param string $msg String to translate.
191: * @param array ...$args Array with arguments or multiple arguments in function.
192: * @return string|null Translated string.
193: * @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__dx
194: */
195: function __dx($domain, $context, $msg, ...$args)
196: {
197: if (!$msg) {
198: return null;
199: }
200: if (isset($args[0]) && is_array($args[0])) {
201: $args = $args[0];
202: }
203:
204: return I18n::getTranslator($domain)->translate(
205: $msg,
206: ['_context' => $context] + $args
207: );
208: }
209:
210: }
211:
212: if (!function_exists('__dxn')) {
213: /**
214: * Returns correct plural form of message identified by $singular and $plural for count $count.
215: * Allows you to override the current domain for a single message lookup.
216: * The context is a unique identifier for the translations string that makes it unique
217: * within the same domain.
218: *
219: * @param string $domain Domain.
220: * @param string $context Context of the text.
221: * @param string $singular Singular text to translate.
222: * @param string $plural Plural text.
223: * @param int $count Count.
224: * @param array ...$args Array with arguments or multiple arguments in function.
225: * @return string|null Plural form of translated string.
226: * @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__dxn
227: */
228: function __dxn($domain, $context, $singular, $plural, $count, ...$args)
229: {
230: if (!$singular) {
231: return null;
232: }
233: if (isset($args[0]) && is_array($args[0])) {
234: $args = $args[0];
235: }
236:
237: return I18n::getTranslator($domain)->translate(
238: $plural,
239: ['_count' => $count, '_singular' => $singular, '_context' => $context] + $args
240: );
241: }
242:
243: }
244: