1 | <?php |
||
9 | class AutoTranslate |
||
10 | { |
||
11 | protected $manager; |
||
12 | public $translator; |
||
13 | |||
14 | 21 | public function __construct(Langman $manager, TranslatorInterface $translator) |
|
20 | |||
21 | 12 | public function getSourceTranslations() |
|
25 | |||
26 | 15 | public function getTranslations(string $lang) |
|
44 | |||
45 | 9 | public function getMissingTranslations(string $lang) |
|
57 | |||
58 | 3 | public function translate(string $targetLanguage, $data, $callbackAfterEachTranslation = null) |
|
59 | { |
||
60 | 3 | $this->translator->setTarget($targetLanguage); |
|
61 | |||
62 | 3 | $dottedSource = Arr::dot($data); |
|
63 | |||
64 | 3 | foreach ($dottedSource as $key => $value) { |
|
65 | 3 | $variables = $this->findVariables($value); |
|
66 | |||
67 | 3 | $dottedSource[$key] = is_string($value) ? $this->translator->translate($value) : $value; |
|
68 | |||
69 | 3 | $dottedSource[$key] = $this->replaceTranslatedVariablesWithOld($variables, $dottedSource[$key]); |
|
70 | |||
71 | 3 | if ($callbackAfterEachTranslation) { |
|
72 | $callbackAfterEachTranslation(); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | 3 | return $this->array_undot($dottedSource); |
|
77 | } |
||
78 | |||
79 | 3 | public function findVariables($string) |
|
89 | |||
90 | 3 | public function replaceTranslatedVariablesWithOld($variables, $string) |
|
100 | |||
101 | 3 | public function fillLanguageFiles(string $language, array $data) |
|
113 | |||
114 | 6 | public function array_undot(array $dottedArray, array $initialArray = []) : array |
|
122 | } |
||
123 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.