PageRenderTime 75ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/cakephp/cakephp/src/I18n/functions.php

https://gitlab.com/alexandresgv/siteentec
PHP | 226 lines | 97 code | 23 blank | 106 comment | 16 complexity | 7e2b5b78bea5959e557afd68dc7a36aa MD5 | raw file
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. use Cake\I18n\I18n;
  16. if (!function_exists('__')) {
  17. /**
  18. * Returns a translated string if one is found; Otherwise, the submitted message.
  19. *
  20. * @param string $singular Text to translate.
  21. * @param mixed $args Array with arguments or multiple arguments in function.
  22. * @return mixed Translated string.
  23. * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__
  24. */
  25. function __($singular, $args = null)
  26. {
  27. if (!$singular) {
  28. return;
  29. }
  30. $arguments = func_num_args() === 2 ? (array)$args : array_slice(func_get_args(), 1);
  31. return I18n::translator()->translate($singular, $arguments);
  32. }
  33. }
  34. if (!function_exists('__n')) {
  35. /**
  36. * Returns correct plural form of message identified by $singular and $plural for count $count.
  37. * Some languages have more than one form for plural messages dependent on the count.
  38. *
  39. * @param string $singular Singular text to translate.
  40. * @param string $plural Plural text.
  41. * @param int $count Count.
  42. * @param mixed $args Array with arguments or multiple arguments in function.
  43. * @return mixed Plural form of translated string.
  44. * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__n
  45. */
  46. function __n($singular, $plural, $count, $args = null)
  47. {
  48. if (!$singular) {
  49. return;
  50. }
  51. $arguments = func_num_args() === 4 ? (array)$args : array_slice(func_get_args(), 3);
  52. return I18n::translator()->translate(
  53. $plural,
  54. ['_count' => $count, '_singular' => $singular] + $arguments
  55. );
  56. }
  57. }
  58. if (!function_exists('__d')) {
  59. /**
  60. * Allows you to override the current domain for a single message lookup.
  61. *
  62. * @param string $domain Domain.
  63. * @param string $msg String to translate.
  64. * @param mixed $args Array with arguments or multiple arguments in function.
  65. * @return string|null Translated string.
  66. * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__d
  67. */
  68. function __d($domain, $msg, $args = null)
  69. {
  70. if (!$msg) {
  71. return null;
  72. }
  73. $arguments = func_num_args() === 3 ? (array)$args : array_slice(func_get_args(), 2);
  74. return I18n::translator($domain)->translate($msg, $arguments);
  75. }
  76. }
  77. if (!function_exists('__dn')) {
  78. /**
  79. * Allows you to override the current domain for a single plural message lookup.
  80. * Returns correct plural form of message identified by $singular and $plural for count $count
  81. * from domain $domain.
  82. *
  83. * @param string $domain Domain.
  84. * @param string $singular Singular string to translate.
  85. * @param string $plural Plural.
  86. * @param int $count Count.
  87. * @param mixed $args Array with arguments or multiple arguments in function.
  88. * @return string|null Plural form of translated string.
  89. * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__dn
  90. */
  91. function __dn($domain, $singular, $plural, $count, $args = null)
  92. {
  93. if (!$singular) {
  94. return null;
  95. }
  96. $arguments = func_num_args() === 5 ? (array)$args : array_slice(func_get_args(), 4);
  97. return I18n::translator($domain)->translate(
  98. $plural,
  99. ['_count' => $count, '_singular' => $singular] + $arguments
  100. );
  101. }
  102. }
  103. if (!function_exists('__x')) {
  104. /**
  105. * Returns a translated string if one is found; Otherwise, the submitted message.
  106. * The context is a unique identifier for the translations string that makes it unique
  107. * within the same domain.
  108. *
  109. * @param string $context Context of the text.
  110. * @param string $singular Text to translate.
  111. * @param mixed $args Array with arguments or multiple arguments in function.
  112. * @return string|null Translated string.
  113. * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__
  114. */
  115. function __x($context, $singular, $args = null)
  116. {
  117. if (!$singular) {
  118. return null;
  119. }
  120. $arguments = func_num_args() === 3 ? (array)$args : array_slice(func_get_args(), 2);
  121. return I18n::translator()->translate($singular, ['_context' => $context] + $arguments);
  122. }
  123. }
  124. if (!function_exists('__xn')) {
  125. /**
  126. * Returns correct plural form of message identified by $singular and $plural for count $count.
  127. * Some languages have more than one form for plural messages dependent on the count.
  128. * The context is a unique identifier for the translations string that makes it unique
  129. * within the same domain.
  130. *
  131. * @param string $context Context of the text.
  132. * @param string $singular Singular text to translate.
  133. * @param string $plural Plural text.
  134. * @param int $count Count.
  135. * @param mixed $args Array with arguments or multiple arguments in function.
  136. * @return string|null Plural form of translated string.
  137. * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__xn
  138. */
  139. function __xn($context, $singular, $plural, $count, $args = null)
  140. {
  141. if (!$singular) {
  142. return null;
  143. }
  144. $arguments = func_num_args() === 5 ? (array)$args : array_slice(func_get_args(), 2);
  145. return I18n::translator()->translate(
  146. $singular,
  147. ['_count' => $count, '_singular' => $singular, '_context' => $context] + $arguments
  148. );
  149. }
  150. }
  151. if (!function_exists('__dx')) {
  152. /**
  153. * Allows you to override the current domain for a single message lookup.
  154. * The context is a unique identifier for the translations string that makes it unique
  155. * within the same domain.
  156. *
  157. * @param string $domain Domain.
  158. * @param string $context Context of the text.
  159. * @param string $msg String to translate.
  160. * @param mixed $args Array with arguments or multiple arguments in function.
  161. * @return string|null Translated string.
  162. * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__dx
  163. */
  164. function __dx($domain, $context, $msg, $args = null)
  165. {
  166. if (!$msg) {
  167. return null;
  168. }
  169. $arguments = func_num_args() === 4 ? (array)$args : array_slice(func_get_args(), 2);
  170. return I18n::translator($domain)->translate(
  171. $msg,
  172. ['_context' => $context] + $arguments
  173. );
  174. }
  175. }
  176. if (!function_exists('__dxn')) {
  177. /**
  178. * Returns correct plural form of message identified by $singular and $plural for count $count.
  179. * Allows you to override the current domain for a single message lookup.
  180. * The context is a unique identifier for the translations string that makes it unique
  181. * within the same domain.
  182. *
  183. * @param string $domain Domain.
  184. * @param string $context Context of the text.
  185. * @param string $singular Singular text to translate.
  186. * @param string $plural Plural text.
  187. * @param int $count Count.
  188. * @param mixed $args Array with arguments or multiple arguments in function.
  189. * @return string|null Plural form of translated string.
  190. * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__dxn
  191. */
  192. function __dxn($domain, $context, $singular, $plural, $count, $args = null)
  193. {
  194. if (!$singular) {
  195. return null;
  196. }
  197. $arguments = func_num_args() === 6 ? (array)$args : array_slice(func_get_args(), 2);
  198. return I18n::translator($domain)->translate(
  199. $singular,
  200. ['_count' => $count, '_singular' => $singular, '_context' => $context] + $arguments
  201. );
  202. }
  203. }