Completed
Push — master ( 5d9aac...542b3f )
by Oscar
03:07
created

translator_functions.php ➔ dn__()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 4
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
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 is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args);
23
}
24
25
/**
26
 * Noop, marks the string for translation but returns it unchanged.
27
 *
28
 * @param string $original
29
 *
30
 * @return string
31
 */
32
function noop__($original)
33
{
34
    return $original;
35
}
36
37
/**
38
 * Returns the singular/plural translation of a string.
39
 *
40
 * @param string $original
41
 * @param string $plural
42
 * @param string $value
43
 *
44
 * @return string
45
 */
46 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...
47
{
48
    $text = BaseTranslator::$current->ngettext($original, $plural, $value);
49
50
    if (func_num_args() === 3) {
51
        return $text;
52
    }
53
54
    $args = array_slice(func_get_args(), 3);
55
56
    return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args);
57
}
58
59
/**
60
 * Returns the translation of a string in a specific context.
61
 *
62
 * @param string $context
63
 * @param string $original
64
 *
65
 * @return string
66
 */
67 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...
68
{
69
    $text = BaseTranslator::$current->pgettext($context, $original);
70
71
    if (func_num_args() === 2) {
72
        return $text;
73
    }
74
75
    $args = array_slice(func_get_args(), 2);
76
77
    return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args);
78
}
79
80
/**
81
 * Returns the translation of a string in a specific domain.
82
 *
83
 * @param string $domain
84
 * @param string $original
85
 *
86
 * @return string
87
 */
88 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...
89
{
90
    $text = BaseTranslator::$current->dgettext($domain, $original);
91
92
    if (func_num_args() === 2) {
93
        return $text;
94
    }
95
96
    $args = array_slice(func_get_args(), 2);
97
98
    return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args);
99
}
100
101
/**
102
 * Returns the translation of a string in a specific domain and context.
103
 *
104
 * @param string $domain
105
 * @param string $context
106
 * @param string $original
107
 *
108
 * @return string
109
 */
110 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...
111
{
112
    $text = BaseTranslator::$current->dpgettext($domain, $context, $original);
113
114
    if (func_num_args() === 3) {
115
        return $text;
116
    }
117
118
    $args = array_slice(func_get_args(), 3);
119
120
    return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args);
121
}
122
123
/**
124
 * Returns the translation of a string in a specific domain and context.
125
 *
126
 * @param string $domain
127
 * @param string $original
128
 * @param string $plural
129
 * @param string $value
130
 *
131
 * @return string
132
 */
133 View Code Duplication
function dn__($domain, $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...
134
{
135
    $text = BaseTranslator::$current->dngettext($domain, $original, $plural, $value);
136
137
    if (func_num_args() === 4) {
138
        return $text;
139
    }
140
141
    $args = array_slice(func_get_args(), 4);
142
143
    return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args);
144
}
145
146
/**
147
 * Returns the singular/plural translation of a string in a specific context.
148
 *
149
 * @param string $context
150
 * @param string $original
151
 * @param string $plural
152
 * @param string $value
153
 *
154
 * @return string
155
 */
156 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...
157
{
158
    $text = BaseTranslator::$current->npgettext($context, $original, $plural, $value);
159
160
    if (func_num_args() === 4) {
161
        return $text;
162
    }
163
164
    $args = array_slice(func_get_args(), 4);
165
166
    return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args);
167
}
168
169
/**
170
 * Returns the singular/plural translation of a string in a specific domain and context.
171
 *
172
 * @param string $domain
173
 * @param string $context
174
 * @param string $original
175
 * @param string $plural
176
 * @param string $value
177
 *
178
 * @return string
179
 */
180 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...
181
{
182
    $text = BaseTranslator::$current->dnpgettext($domain, $context, $original, $plural, $value);
183
184
    if (func_num_args() === 5) {
185
        return $text;
186
    }
187
188
    $args = array_slice(func_get_args(), 5);
189
190
    return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args);
191
}
192