/
StringTranslatingTrait.php
47 lines (43 loc) · 1.08 KB
/
StringTranslatingTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Dhii\I18n;
/**
* Methods for classes which can translate.
*
* @since [*next-version*]
*/
trait StringTranslatingTrait
{
/**
* Translates a string, and replaces placeholders.
*
* @since [*next-version*]
* @see sprintf()
* @see _translate()
*
* @param string $string The format string to translate.
* @param array $args Placeholder values to replace in the string.
* @param mixed $context The context for translation.
*
* @return string The translated string.
*/
protected function __($string, $args = array(), $context = null)
{
$string = $this->_translate($string, $context);
array_unshift($args, $string);
$result = call_user_func_array('sprintf', $args);
return $result;
}
/**
* Translates a string.
*
* @since [*next-version*]
*
* @param string $string The string to translate.
*
* @return string The translated string.
*/
protected function _translate($string, $context = null)
{
return $string;
}
}