/
DubasHelper.php
113 lines (96 loc) · 2.7 KB
/
DubasHelper.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace Espo\Modules\DubasTemplateHelper\TemplateHelpers;
use LightnCandy\LightnCandy as LightnCandy;
class DubasHelper
{
public static function dubasTranslate()
{
$args = func_get_args();
$context = $args[count($args) - 1];
$hash = $context['hash'];
$data = $context['data']['root'];
$scope = $hash['scope'] ?? null;
$category = $hash['category'] ?? null;
$label = $hash['label'] ?? null;
$language = $hash['language'] ?? 'en_US';
if
(
!$scope
||
!$category
||
!$label
)
{
$html = null;
}
else
{
$translation = $data['__language'];
$translation->setLanguage($language);
$html = $translation->translate($label, $category, $scope);
}
return new LightnCandy\SafeString($html);
}
public static function dubasTranslateOption()
{
$args = func_get_args();
$context = $args[count($args) - 1];
$hash = $context['hash'];
$data = $context['data']['root'];
$scope = $hash['scope'] ?? null;
$field = $hash['field'] ?? null;
$value = $hash['value'] ?? null;
$language = $hash['language'] ?? 'en_US';
if
(
!$scope
||
!$field
||
!$value
)
{
$html = null;
}
else
{
$translation = $data['__language'];
$translation->setLanguage($language);
$html = $translation->translateOption($value, $field, $scope);
}
return new LightnCandy\SafeString($html);
}
public static function dubasTranslateValue()
{
$args = func_get_args();
$context = $args[count($args) - 1];
$hash = $context['hash'];
$data = $context['data']['root'];
$id = $args[0] ?? null;
$scope = $hash['scope'] ?? null;
$field = $hash['field'] ?? null;
$language = $hash['language'] ?? 'en_US';
$entityManager = $data['__entityManager'];
$entity = $entityManager->getEntity($scope, $id);
$value = $entity->get($field);
if
(
!$scope
||
!$field
||
!$value
)
{
$html = null;
}
else
{
$translation = $data['__language'];
$translation->setLanguage($language);
$html = $translation->translateOption($value, $field, $scope);
}
return new LightnCandy\SafeString($html);
}
}