|
2 | 2 |
|
3 | 3 | use Gettext\TranslatorFunctions as Translator; |
4 | 4 |
|
5 | | -/** |
6 | | - * Returns the translation of a string. |
7 | | - */ |
8 | | -function __(string $original, ...$args): string |
9 | | -{ |
10 | | - $text = Translator::getTranslator()->gettext($original); |
11 | | - return Translator::getFormatter()->format($text, $args); |
| 5 | +if (!function_exists('__')) { |
| 6 | + /** |
| 7 | + * Returns the translation of a string. |
| 8 | + */ |
| 9 | + function __(string $original, ...$args): string |
| 10 | + { |
| 11 | + $text = Translator::getTranslator()->gettext($original); |
| 12 | + return Translator::getFormatter()->format($text, $args); |
| 13 | + } |
12 | 14 | } |
13 | 15 |
|
14 | | -/** |
15 | | - * Noop, marks the string for translation but returns it unchanged. |
16 | | - */ |
17 | | -function noop__(string $original, ...$args): string |
18 | | -{ |
19 | | - $text = Translator::getTranslator()->noop($original); |
20 | | - return Translator::getFormatter()->format($text, $args); |
| 16 | +if (!function_exists('noop__')) { |
| 17 | + /** |
| 18 | + * Noop, marks the string for translation but returns it unchanged. |
| 19 | + */ |
| 20 | + function noop__(string $original, ...$args): string |
| 21 | + { |
| 22 | + $text = Translator::getTranslator()->noop($original); |
| 23 | + return Translator::getFormatter()->format($text, $args); |
| 24 | + } |
21 | 25 | } |
22 | 26 |
|
23 | | -/** |
24 | | - * Returns the singular/plural translation of a string. |
25 | | - */ |
26 | | -function n__(string $original, string $plural, int $value, ...$args): string |
27 | | -{ |
28 | | - $text = Translator::getTranslator()->ngettext($original, $plural, $value); |
29 | | - return Translator::getFormatter()->format($text, $args); |
| 27 | +if (!function_exists('n__')) { |
| 28 | + /** |
| 29 | + * Returns the singular/plural translation of a string. |
| 30 | + */ |
| 31 | + function n__(string $original, string $plural, int $value, ...$args): string |
| 32 | + { |
| 33 | + $text = Translator::getTranslator()->ngettext($original, $plural, $value); |
| 34 | + return Translator::getFormatter()->format($text, $args); |
| 35 | + } |
30 | 36 | } |
31 | 37 |
|
32 | | -/** |
33 | | - * Returns the translation of a string in a specific context. |
34 | | - */ |
35 | | -function p__(string $context, string $original, ...$args): string |
36 | | -{ |
37 | | - $text = Translator::getTranslator()->pgettext($context, $original); |
38 | | - return Translator::getFormatter()->format($text, $args); |
| 38 | +if (!function_exists('p__')) { |
| 39 | + /** |
| 40 | + * Returns the translation of a string in a specific context. |
| 41 | + */ |
| 42 | + function p__(string $context, string $original, ...$args): string |
| 43 | + { |
| 44 | + $text = Translator::getTranslator()->pgettext($context, $original); |
| 45 | + return Translator::getFormatter()->format($text, $args); |
| 46 | + } |
39 | 47 | } |
40 | 48 |
|
41 | | -/** |
42 | | - * Returns the translation of a string in a specific domain. |
43 | | - */ |
44 | | -function d__(string $domain, string $original, ...$args): string |
45 | | -{ |
46 | | - $text = Translator::getTranslator()->dgettext($domain, $original); |
47 | | - return Translator::getFormatter()->format($text, $args); |
| 49 | +if (!function_exists('d__')) { |
| 50 | + /** |
| 51 | + * Returns the translation of a string in a specific domain. |
| 52 | + */ |
| 53 | + function d__(string $domain, string $original, ...$args): string |
| 54 | + { |
| 55 | + $text = Translator::getTranslator()->dgettext($domain, $original); |
| 56 | + return Translator::getFormatter()->format($text, $args); |
| 57 | + } |
48 | 58 | } |
49 | 59 |
|
50 | | -/** |
51 | | - * Returns the translation of a string in a specific domain and context. |
52 | | - */ |
53 | | -function dp__(string $domain, string $context, string $original, ...$args): string |
54 | | -{ |
55 | | - $text = Translator::getTranslator()->dpgettext($domain, $context, $original); |
56 | | - return Translator::getFormatter()->format($text, $args); |
| 60 | +if (!function_exists('dp__')) { |
| 61 | + /** |
| 62 | + * Returns the translation of a string in a specific domain and context. |
| 63 | + */ |
| 64 | + function dp__(string $domain, string $context, string $original, ...$args): string |
| 65 | + { |
| 66 | + $text = Translator::getTranslator()->dpgettext($domain, $context, $original); |
| 67 | + return Translator::getFormatter()->format($text, $args); |
| 68 | + } |
57 | 69 | } |
58 | 70 |
|
59 | | -/** |
60 | | - * Returns the singular/plural translation of a string in a specific domain. |
61 | | - */ |
62 | | -function dn__(string $domain, string $original, string $plural, int $value, ...$args): string |
63 | | -{ |
64 | | - $text = Translator::getTranslator()->dngettext($domain, $original, $plural, $value); |
65 | | - return Translator::getFormatter()->format($text, $args); |
| 71 | +if (!function_exists('dn__')) { |
| 72 | + /** |
| 73 | + * Returns the singular/plural translation of a string in a specific domain. |
| 74 | + */ |
| 75 | + function dn__(string $domain, string $original, string $plural, int $value, ...$args): string |
| 76 | + { |
| 77 | + $text = Translator::getTranslator()->dngettext($domain, $original, $plural, $value); |
| 78 | + return Translator::getFormatter()->format($text, $args); |
| 79 | + } |
66 | 80 | } |
67 | 81 |
|
68 | | -/** |
69 | | - * Returns the singular/plural translation of a string in a specific context. |
70 | | - */ |
71 | | -function np__(string $context, string $original, string $plural, int $value, ...$args): string |
72 | | -{ |
73 | | - $text = Translator::getTranslator()->npgettext($context, $original, $plural, $value); |
74 | | - return Translator::getFormatter()->format($text, $args); |
| 82 | +if (!function_exists('np__')) { |
| 83 | + /** |
| 84 | + * Returns the singular/plural translation of a string in a specific context. |
| 85 | + */ |
| 86 | + function np__(string $context, string $original, string $plural, int $value, ...$args): string |
| 87 | + { |
| 88 | + $text = Translator::getTranslator()->npgettext($context, $original, $plural, $value); |
| 89 | + return Translator::getFormatter()->format($text, $args); |
| 90 | + } |
75 | 91 | } |
76 | 92 |
|
77 | | -/** |
78 | | - * Returns the singular/plural translation of a string in a specific domain and context. |
79 | | - */ |
80 | | -function dnp__(string $domain, string $context, string $original, string $plural, int $value, ...$args): string |
81 | | -{ |
82 | | - $text = Translator::getTranslator()->dnpgettext($domain, $context, $original, $plural, $value); |
83 | | - return Translator::getFormatter()->format($text, $args); |
| 93 | +if (!function_exists('dnp__')) { |
| 94 | + /** |
| 95 | + * Returns the singular/plural translation of a string in a specific domain and context. |
| 96 | + */ |
| 97 | + function dnp__(string $domain, string $context, string $original, string $plural, int $value, ...$args): string |
| 98 | + { |
| 99 | + $text = Translator::getTranslator()->dnpgettext($domain, $context, $original, $plural, $value); |
| 100 | + return Translator::getFormatter()->format($text, $args); |
| 101 | + } |
84 | 102 | } |
0 commit comments