1 | <?php |
||||
2 | |||||
3 | use Illuminate\Support\Facades\App; |
||||
4 | use Illuminate\Support\Facades\Config; |
||||
5 | |||||
6 | if (Config::get('translation.shorthand_enabled')) { |
||||
7 | if (!function_exists('_t')) { |
||||
8 | /** |
||||
9 | * Shorthand function for translating text. |
||||
10 | * |
||||
11 | * @param string $text |
||||
12 | * @param array $replacements |
||||
13 | * @param string $toLocale |
||||
14 | * |
||||
15 | * @return string |
||||
16 | */ |
||||
17 | function _t($text, $replacements = [], $toLocale = '') |
||||
18 | { |
||||
19 | return App::make('translation')->translate($text, $replacements, $toLocale); |
||||
20 | } |
||||
21 | } |
||||
22 | } |
||||
23 | |||||
24 | if (!function_exists('is_field_translatable')) { |
||||
25 | /** |
||||
26 | * Check if a Field is translatable. |
||||
27 | * |
||||
28 | * @param Illuminate\Database\Eloquent\Model $model |
||||
29 | * @param Illuminate\Database\Eloquent\Collection $row |
||||
30 | */ |
||||
31 | function is_field_translatable($model, $row) |
||||
32 | { |
||||
33 | if (!is_bread_translatable($model)) { |
||||
34 | return; |
||||
35 | } |
||||
36 | |||||
37 | return $model->translatable() |
||||
38 | && method_exists($model, 'getTranslatableAttributes') |
||||
39 | && in_array($row->field, $model->getTranslatableAttributes()); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
40 | } |
||||
41 | } |
||||
42 | |||||
43 | if (!function_exists('get_field_translations')) { |
||||
44 | /** |
||||
45 | * Return all field translations. |
||||
46 | * |
||||
47 | * @param Illuminate\Database\Eloquent\Model $model |
||||
48 | * @param string $field |
||||
49 | * @param string $rowType |
||||
50 | * @param bool $stripHtmlTags |
||||
51 | */ |
||||
52 | function get_field_translations($model, $field, $rowType = '', $stripHtmlTags = false) |
||||
53 | { |
||||
54 | $_out = $model->getTranslationsOf($field); |
||||
55 | |||||
56 | if ($stripHtmlTags && $rowType == 'rich_text_box') { |
||||
57 | foreach ($_out as $language => $value) { |
||||
58 | $_out[$language] = strip_tags($_out[$language]); |
||||
59 | } |
||||
60 | } |
||||
61 | |||||
62 | return json_encode($_out); |
||||
63 | } |
||||
64 | } |
||||
65 | |||||
66 | if (!function_exists('is_bread_translatable')) { |
||||
67 | /** |
||||
68 | * Check if BREAD is translatable. |
||||
69 | * |
||||
70 | * @param Illuminate\Database\Eloquent\Model $model |
||||
71 | */ |
||||
72 | function is_bread_translatable($model) |
||||
73 | { |
||||
74 | return \Illuminate\Support\Facades\Config::get('site.multilingual.enabled', true) |
||||
75 | && isset($model) |
||||
76 | && method_exists($model, 'translatable') |
||||
77 | && $model->translatable(); |
||||
78 | } |
||||
79 | } |
||||
80 | |||||
81 | if (!function_exists('__')) { |
||||
82 | function __($key, array $par = []) |
||||
83 | { |
||||
84 | return trans($key, $par); |
||||
0 ignored issues
–
show
The function
trans was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
85 | } |
||||
86 | } |
||||
87 | if (!function_exists('lang')) { |
||||
88 | function lang($key, array $par = []) |
||||
89 | { |
||||
90 | return trans($key, $par); |
||||
0 ignored issues
–
show
The function
trans was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
91 | } |
||||
92 | } |
||||
93 |