|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Staffcloud. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2015 and Onwards, Smartbridge AG <[email protected]>. All rights reserved. |
|
6
|
|
|
* @license Proprietary/Closed Source |
|
7
|
|
|
* @see https://www.staff.cloud |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace LaravelPolyglot\Translation; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Contracts\Translation\Loader; |
|
15
|
|
|
use Illuminate\Translation\Translator as IlluminateTranslationTranslator; |
|
16
|
|
|
use Polyglot\Polyglot; |
|
17
|
|
|
|
|
18
|
|
|
class Translator extends IlluminateTranslationTranslator |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var Polyglot |
|
22
|
|
|
*/ |
|
23
|
|
|
private $polyglot; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Translator constructor. |
|
27
|
|
|
* |
|
28
|
|
|
* @param Polyglot $polyglot |
|
29
|
|
|
* @param Loader $loader |
|
30
|
|
|
* @param $locale |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(Polyglot $polyglot, Loader $loader, $locale) |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct($loader, $locale); |
|
35
|
|
|
|
|
36
|
|
|
$this->polyglot = $polyglot; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritDoc |
|
41
|
|
|
*/ |
|
42
|
|
|
public function get($key, array $replace = [], $locale = null, $fallback = true) |
|
43
|
|
|
{ |
|
44
|
|
|
$locale = $locale ?? $this->locale; |
|
45
|
|
|
$namespace = $replace['namespace'] ?? '*'; |
|
46
|
|
|
$group = $replace['group'] ?? '*'; |
|
47
|
|
|
|
|
48
|
|
|
$this->load($namespace, $group, $locale); |
|
49
|
|
|
|
|
50
|
|
|
$this->polyglot->replace($this->loaded[$namespace][$group][$locale]); |
|
51
|
|
|
$this->polyglot->locale($locale); |
|
52
|
|
|
|
|
53
|
|
|
return $this->polyglot->t($key, $replace); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @inheritDoc |
|
58
|
|
|
*/ |
|
59
|
|
|
public function choice($key, $number, array $replace = [], $locale = null) |
|
60
|
|
|
{ |
|
61
|
|
|
// If the given "number" is actually an array or countable we will simply count the |
|
62
|
|
|
// number of elements in an instance. This allows developers to pass an array of |
|
63
|
|
|
// items without having to count it on their end first which gives bad syntax. |
|
64
|
|
|
if (is_countable($number)) { |
|
65
|
|
|
$number = count($number); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$replace['smart_count'] = $number; |
|
69
|
|
|
|
|
70
|
|
|
return $this->get($key, $replace, $locale); |
|
71
|
|
|
} |
|
72
|
|
|
} |