Skip to content

Commit c22b614

Browse files
author
Papoteur
committed
Use translated strings in autocompletion fields
Mark the auto create question as string to translate
1 parent 4ec4fdf commit c22b614

File tree

1 file changed

+63
-24
lines changed

1 file changed

+63
-24
lines changed

routes/web.php

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,34 @@
9595
$term = $request->term;
9696
$results = App\EventName::select('name as value', 'code as key')
9797
->where([
98-
['name', 'like', "$term%"],
9998
['is_task', $is_task],
10099
]);
101100
if ($request->filled('category')) {
102101
$results->whereRaw('ifnull(category, ?) = ?', [$request->category, $request->category]);
103102
}
104-
105-
return $results->take(10)->get();
103+
$match_list = Array();
104+
foreach($results->get() as $item) {
105+
if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){
106+
$match_item = ["key" => $item["key"], "value" => __($item["value"])];
107+
array_push($match_list, $match_item);
108+
}
109+
}
110+
return $match_list;
106111
});
107112

108113
Route::get('classifier-type/autocomplete/{main_display}', function (Request $request, $main_display) {
109114
$term = $request->input('term');
110115
$results = App\ClassifierType::select('type as value', 'code as key')
111-
->where('type', 'like', "$term%")
112116
->where('main_display', $main_display)
113117
->orderBy('type');
114-
115-
return $results->take(10)->get();
118+
$match_list = Array();
119+
foreach($results->get() as $item) {
120+
if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){
121+
$match_item = ["key" => $item["key"], "value" => __($item["value"])];
122+
array_push($match_list, $match_item);
123+
}
124+
}
125+
return $match_list;
116126
});
117127

118128
Route::get('user/autocomplete', function (Request $request) {
@@ -131,7 +141,7 @@
131141
->orWhere('display_name', 'like', "$term")
132142
->take(10)->get();
133143
if ($list->count() < 5 && $create_option) {
134-
$list->push(['label' => "Create $term?", 'key' => 'create', 'value' => $term]);
144+
$list->push(['label' => __("Create $term?"), 'key' => 'create', 'value' => $term]);
135145
}
136146

137147
return $list;
@@ -140,42 +150,71 @@
140150
Route::get('role/autocomplete', function (Request $request) {
141151
$term = $request->input('term');
142152

143-
return App\Role::select('name as value', 'code as key', 'shareable')
144-
->where('name', 'like', "$term%")
145-
->orWhere('code', 'like', "$term%")->get();
153+
$full_list = App\Role::select('name as value', 'code as key', 'shareable')->get();
154+
$match_list = Array();
155+
foreach($full_list as $item) {
156+
if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){
157+
$match_item = ["key" => $item["key"], "shareable" => $item["shareable"], "value" => __($item["value"])];
158+
array_push($match_list, $match_item);
159+
}
160+
}
161+
return $match_list;
146162
});
147163

148164
Route::get('dbrole/autocomplete', function (Request $request) {
149165
$term = $request->input('term');
150166

151-
return App\Role::select('name as value', 'code as key')
152-
->where('name', 'like', "$term%")
167+
$full_list = App\Role::select('name as value', 'code as key')
153168
->whereIn('code', ['CLI', 'DBA', 'DBRW', 'DBRO'])->get();
169+
$match_list = Array();
170+
foreach($full_list as $item) {
171+
if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){
172+
$match_item = ["key" => $item["key"], "value" => __($item["value"])];
173+
array_push($match_list, $match_item);
174+
}
175+
}
176+
return $match_list;
154177
});
155178

156179
Route::get('country/autocomplete', function (Request $request) {
157180
$term = $request->input('term');
158-
$list = App\Country::select('name as value', 'iso as key')
159-
->where('name', 'like', "$term%")
160-
->orWhere('iso', 'like', "$term%")->get();
161-
162-
return $list;
181+
$full_list = App\Country::select('name as value', 'iso as key')->get();
182+
$match_list = Array();
183+
foreach($full_list as $item) {
184+
if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){
185+
$match_item = ["key" => $item["key"], "value" => __($item["value"])];
186+
array_push($match_list, $match_item);
187+
}
188+
}
189+
return $match_list;
163190
});
164191

165192
Route::get('category/autocomplete', function (Request $request) {
166193
$term = $request->input('term');
167194

168-
return App\Category::select('category as value', 'code as key', 'ref_prefix as prefix')
169-
->where('category', 'like', "$term%")
170-
->orWhere('code', 'like', "$term%")->get();
195+
$full_list = App\Category::select('category as value', 'code as key', 'ref_prefix as prefix')->get();
196+
$match_list = Array();
197+
foreach($full_list as $item) {
198+
if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){
199+
$match_item = ["key" => $item["key"], "prefix" => $item["prefix"], "value" => __($item["value"])];
200+
array_push($match_list, $match_item);
201+
}
202+
}
203+
return $match_list;
171204
});
172205

173206
Route::get('type/autocomplete', function (Request $request) {
174207
$term = $request->input('term');
175208

176-
return App\Type::select('type as value', 'code as key')
177-
->where('type', 'like', "$term%")
178-
->orWhere('code', 'like', "$term%")->get();
209+
$full_list = App\Type::select('type as value', 'code as key')->get();
210+
$match_list = Array();
211+
foreach($full_list as $item) {
212+
if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){
213+
$match_item = ["key" => $item["key"], "value" => __($item["value"])];
214+
array_push($match_list, $match_item);
215+
}
216+
}
217+
return $match_list;
179218
});
180219

181220
Route::get('classifier/{classifier}/img', fn (App\Classifier $classifier) => response($classifier->img)
@@ -186,7 +225,7 @@
186225
$list = App\TemplateMember::select('category as value', 'category as key')
187226
->where('category', 'like', "$term%")->distinct()->get();
188227
if ($list->count() == 0) {
189-
$list->push(['label' => "Create $term", 'key' => $term, 'value' => $term]);
228+
$list->push(['label' => __("Create $term"), 'key' => $term, 'value' => $term]);
190229
}
191230

192231
return $list;

0 commit comments

Comments
 (0)