Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Translation;
4
 
5
use Stringable;
6
 
7
class PotentiallyTranslatedString implements Stringable
8
{
9
    /**
10
     * The string that may be translated.
11
     *
12
     * @var string
13
     */
14
    protected $string;
15
 
16
    /**
17
     * The translated string.
18
     *
19
     * @var string|null
20
     */
21
    protected $translation;
22
 
23
    /**
24
     * The validator that may perform the translation.
25
     *
26
     * @var \Illuminate\Contracts\Translation\Translator
27
     */
28
    protected $translator;
29
 
30
    /**
31
     * Create a new potentially translated string.
32
     *
33
     * @param  string  $string
34
     * @param  \Illuminate\Contracts\Translation\Translator  $translator
35
     */
36
    public function __construct($string, $translator)
37
    {
38
        $this->string = $string;
39
 
40
        $this->translator = $translator;
41
    }
42
 
43
    /**
44
     * Translate the string.
45
     *
46
     * @param  array  $replace
47
     * @param  string|null  $locale
48
     * @return $this
49
     */
50
    public function translate($replace = [], $locale = null)
51
    {
52
        $this->translation = $this->translator->get($this->string, $replace, $locale);
53
 
54
        return $this;
55
    }
56
 
57
    /**
58
     * Translates the string based on a count.
59
     *
60
     * @param  \Countable|int|array  $number
61
     * @param  array  $replace
62
     * @param  string|null  $locale
63
     * @return $this
64
     */
65
    public function translateChoice($number, array $replace = [], $locale = null)
66
    {
67
        $this->translation = $this->translator->choice($this->string, $number, $replace, $locale);
68
 
69
        return $this;
70
    }
71
 
72
    /**
73
     * Get the original string.
74
     *
75
     * @return string
76
     */
77
    public function original()
78
    {
79
        return $this->string;
80
    }
81
 
82
    /**
83
     * Get the potentially translated string.
84
     *
85
     * @return string
86
     */
87
    public function __toString()
88
    {
89
        return $this->translation ?? $this->string;
90
    }
91
 
92
    /**
93
     * Get the potentially translated string.
94
     *
95
     * @return string
96
     */
97
    public function toString()
98
    {
99
        return (string) $this;
100
    }
101
}