Completed
Push — 3.x ( 0db171...cd3be6 )
by Oscar
19:33 queued 08:32
created

translator_functions.php ➔ dnp__()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 2
nop 5
dl 12
loc 12
rs 9.4285
1
<?php
2
3
use Gettext\BaseTranslator;
4
5
/**
6
 * Returns the translation of a string.
7
 *
8
 * @param string $original
9
 *
10
 * @return string
11
 */
12
function __($original)
13
{
14
    $text = BaseTranslator::$current->gettext($original);
15
16
    if (func_num_args() === 1) {
17
        return $text;
18
    }
19
20
    $args = array_slice(func_get_args(), 1);
21
22
    return vsprintf($text, is_array($args[0]) ? $args[0] : $args);
23
}
24
25
/**
26
 * Returns the singular/plural translation of a string.
27
 *
28
 * @param string $original
29
 * @param string $plural
30
 * @param string $value
31
 *
32
 * @return string
33
 */
34 View Code Duplication
function n__($original, $plural, $value)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
{
36
    $text = BaseTranslator::$current->ngettext($original, $plural, $value);
37
38
    if (func_num_args() === 3) {
39
        return $text;
40
    }
41
42
    $args = array_slice(func_get_args(), 3);
43
44
    return vsprintf($text, is_array($args[0]) ? $args[0] : $args);
45
}
46
47
/**
48
 * Returns the translation of a string in a specific context.
49
 *
50
 * @param string $context
51
 * @param string $original
52
 *
53
 * @return string
54
 */
55 View Code Duplication
function p__($context, $original)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
{
57
    $text = BaseTranslator::$current->pgettext($context, $original);
58
59
    if (func_num_args() === 2) {
60
        return $text;
61
    }
62
63
    $args = array_slice(func_get_args(), 2);
64
65
    return vsprintf($text, is_array($args[0]) ? $args[0] : $args);
66
}
67
68
/**
69
 * Returns the translation of a string in a specific domain.
70
 *
71
 * @param string $domain
72
 * @param string $original
73
 *
74
 * @return string
75
 */
76 View Code Duplication
function d__($domain, $original)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
{
78
    $text = BaseTranslator::$current->dgettext($domain, $original);
79
80
    if (func_num_args() === 2) {
81
        return $text;
82
    }
83
84
    $args = array_slice(func_get_args(), 2);
85
86
    return vsprintf($text, is_array($args[0]) ? $args[0] : $args);
87
}
88
89
/**
90
 * Returns the translation of a string in a specific domain and context.
91
 *
92
 * @param string $domain
93
 * @param string $context
94
 * @param string $original
95
 *
96
 * @return string
97
 */
98 View Code Duplication
function dp__($domain, $context, $original)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
{
100
    $text = BaseTranslator::$current->dpgettext($domain, $context, $original);
101
102
    if (func_num_args() === 3) {
103
        return $text;
104
    }
105
106
    $args = array_slice(func_get_args(), 3);
107
108
    return vsprintf($text, is_array($args[0]) ? $args[0] : $args);
109
}
110
111
/**
112
 * Returns the singular/plural translation of a string in a specific context.
113
 *
114
 * @param string $context
115
 * @param string $original
116
 * @param string $plural
117
 * @param string $value
118
 *
119
 * @return string
120
 */
121 View Code Duplication
function np__($context, $original, $plural, $value)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
122
{
123
    $text = BaseTranslator::$current->npgettext($context, $original, $plural, $value);
124
125
    if (func_num_args() === 4) {
126
        return $text;
127
    }
128
129
    $args = array_slice(func_get_args(), 4);
130
131
    return vsprintf($text, is_array($args[0]) ? $args[0] : $args);
132
}
133
134
/**
135
 * Returns the singular/plural translation of a string in a specific domain and context.
136
 *
137
 * @param string $domain
138
 * @param string $context
139
 * @param string $original
140
 * @param string $plural
141
 * @param string $value
142
 *
143
 * @return string
144
 */
145 View Code Duplication
function dnp__($domain, $context, $original, $plural, $value)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
146
{
147
    $text = BaseTranslator::$current->dnpgettext($domain, $context, $original, $plural, $value);
148
149
    if (func_num_args() === 5) {
150
        return $text;
151
    }
152
153
    $args = array_slice(func_get_args(), 5);
154
155
    return vsprintf($text, is_array($args[0]) ? $args[0] : $args);
156
}
157
158
/**
159
 * Prints function result.
160
 *
161
 * @see __
162
 */
163
function __e()
164
{
165
    echo call_user_func_array('__', func_get_args());
166
}
167
168
/**
169
 * Prints function result.
170
 *
171
 * @see n__
172
 */
173
function n__e()
174
{
175
    echo call_user_func_array('n__', func_get_args());
176
}
177
178
/**
179
 * Prints function result.
180
 *
181
 * @see p__
182
 */
183
function p__e()
184
{
185
    echo call_user_func_array('p__', func_get_args());
186
}
187
188
/**
189
 * Prints function result.
190
 *
191
 * @see d__
192
 */
193
function d__e()
194
{
195
    echo call_user_func_array('d__', func_get_args());
196
}
197
198
/**
199
 * Prints function result.
200
 *
201
 * @see dp__
202
 */
203
function dp__e()
204
{
205
    echo call_user_func_array('dp__', func_get_args());
206
}
207
208
/**
209
 * Prints function result.
210
 *
211
 * @see dnp__
212
 */
213
function dnp__e()
214
{
215
    echo call_user_func_array('dnp__', func_get_args());
216
}
217