Skip to content

Commit

Permalink
[x] Updated /laravel-form-builder files to reflect translations
Browse files Browse the repository at this point in the history
[x] Fixed hover text, helptext and placeholder not translating after json->php mapping
[x] Added helper function hot_swap() to translate keys from mapped json file
[x] added add_additional to /lang/en/buttons.php
  • Loading branch information
PG-Momik committed Jan 10, 2023
1 parent 061e6a0 commit 19ee1f7
Show file tree
Hide file tree
Showing 35 changed files with 163 additions and 136 deletions.
27 changes: 27 additions & 0 deletions app/Helpers/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -1133,3 +1133,30 @@ function translate_this(string $prefix_key, string $suffix_key = ''): array | st
return trans('requests.' . $prefix_key, ['suffix' => trans('requests.suffix.' . $suffix_key)]);
}
}

if (!function_exists('hot_swap')) {
/**
* @param $elements
*
* @return array|mixed
*/
function hot_swap($elements)
{
$swapable_keys = ['label', 'placeholder', 'hover_text', 'help_text'];
$result = [];
if (is_array($elements)) {
foreach ($elements as $key => $value) {
if (is_string($value) && in_array($key, $swapable_keys)) {
$translated = trans($value);
$result[$key] = $translated;
} else {
$result[$key] = hot_swap($value);
}
}
} else {
$result = $elements;
}

return $result;
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/Activity/ActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function show($id): View | JsonResponse | RedirectResponse
try {
$toast = generateToastData();
$activity = $this->activityService->getActivity($id);
$elements = readElementJsonSchema();
$elements = hot_swap(readElementJsonSchema());
$elementGroups = readElementGroup();
$types = $this->getActivityDetailDataType();
$results = $this->resultService->getActivityResultsWithIndicatorsAndPeriods(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function edit(int $id): View|RedirectResponse
$element = getElementSchema('description');
$activity = $this->descriptionService->getActivityData($id);
$form = $this->descriptionService->formGenerator($id);
$data = ['title' => $element['label'], 'name' => 'description'];

$data = ['title' =>$element['label'], 'name' => 'description'];

return view('admin.activity.description.edit', compact('form', 'activity', 'data'));
} catch (\Exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function show($resultId, $indicatorId): Factory|View|RedirectResponse|App
$resultTitle = $result['result']['title'];
$activity = $result->activity;
$period = $this->periodService->getPeriods($indicatorId)->toArray();
$element = getElementSchema('indicator');
$element = hot_swap(getElementSchema('indicator'));
$types = getIndicatorTypes();
$toast = generateToastData();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/Activity/PeriodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function show($indicatorId, $periodId): Factory|View|RedirectResponse|App
],
];
$period = $this->periodService->getPeriod($periodId);
$element = getElementSchema('period');
$element = hot_swap(getElementSchema('period'));
$types = getPeriodTypes();
$toast = generateToastData();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/Activity/ResultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function show($activityId, $resultId): View|RedirectResponse
$toast = generateToastData();
$activity = $this->activityService->getActivity($activityId);
$result = $this->resultService->getResultWithIndicatorAndPeriod($resultId, $activityId);
$element = getElementSchema('result');
$element = hot_swap(getElementSchema('result'));
$types = getResultTypes();

return view('admin.activity.result.detail', compact('activity', 'result', 'types', 'toast', 'element'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function show($activityId, $transactionId): Factory|View|RedirectResponse
try {
$activity = $this->activityService->getActivity($activityId);
$transaction = $this->transactionService->getTransaction($transactionId);
$element = getElementSchema('transactions');
$element = hot_swap(getElementSchema('transactions'));
$types = getTransactionTypes();
$toast = generateToastData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function show(): View|RedirectResponse
try {
$toast['message'] = Session::has('error') ? Session::get('error') : (Session::get('success') ? Session::get('success') : '');
$toast['type'] = Session::has('error') ? 'error' : 'success';
$elements = json_decode(file_get_contents(app_path('IATI/Data/organizationElementJsonSchema.json')), true, 512, JSON_THROW_ON_ERROR);
$elements = hot_swap(json_decode(file_get_contents(app_path('IATI/Data/organizationElementJsonSchema.json')), true, 512, JSON_THROW_ON_ERROR));
$elementGroups = json_decode(file_get_contents(app_path('Data/Organization/OrganisationElementsGroup.json')), true, 512, JSON_THROW_ON_ERROR);
$types = $this->organizationService->getOrganizationTypes();
$organization = $this->organizationService->getOrganizationData(Auth::user()->organization_id);
Expand Down
Loading

0 comments on commit 19ee1f7

Please sign in to comment.