From 34e9d01c189fb54ed0fdc1ff34b9bdc0a61e09b0 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 4 Feb 2023 02:43:47 +0100 Subject: [PATCH] Translate more date / time outputs --- includes/controller/angeltypes_controller.php | 11 ++++++----- includes/controller/rooms_controller.php | 8 ++++---- includes/controller/shifts_controller.php | 4 ++-- includes/helper/shift_helper.php | 6 +++--- includes/mailer/shifts_mailer.php | 14 +++++++------- includes/pages/admin_arrive.php | 6 +++--- includes/pages/admin_shifts.php | 4 ++-- includes/pages/admin_user.php | 2 +- includes/pages/user_myshifts.php | 2 +- includes/pages/user_shifts.php | 8 ++++++-- includes/view/ShiftEntry_view.php | 8 ++++---- includes/view/ShiftsFilterRenderer.php | 7 ++++--- includes/view/Shifts_view.php | 6 +++--- includes/view/User_view.php | 12 ++++++------ resources/lang/de_DE/default.po | 3 +++ src/Controllers/DesignController.php | 5 +++-- 16 files changed, 58 insertions(+), 48 deletions(-) diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 28c82fe1..0c8f15fb 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -220,11 +220,12 @@ function angeltype_controller_shiftsFilterDays(AngelType $angeltype) $days = []; foreach ($all_shifts as $shift) { $day = Carbon::make($shift['start'])->format('Y-m-d'); - if (!in_array($day, $days)) { - $days[] = $day; + $dayFormatted = Carbon::make($shift['start'])->format(__('Y-m-d')); + if (!isset($days[$day])) { + $days[$day] = $dayFormatted; } } - sort($days); + ksort($days); return $days; } @@ -244,8 +245,8 @@ function angeltype_controller_shiftsFilter(AngelType $angeltype, $days) [$angeltype->id] ); $selected_day = date('Y-m-d'); - if (!empty($days) && !in_array($selected_day, $days)) { - $selected_day = $days[0]; + if (!empty($days) && !isset($days[$selected_day])) { + $selected_day = array_key_first($days); } if ($request->input('shifts_filter_day')) { $selected_day = $request->input('shifts_filter_day'); diff --git a/includes/controller/rooms_controller.php b/includes/controller/rooms_controller.php index 429a741e..1a253c30 100644 --- a/includes/controller/rooms_controller.php +++ b/includes/controller/rooms_controller.php @@ -27,8 +27,8 @@ function room_controller(): array $days = []; foreach ($all_shifts as $shift) { $day = $shift->start->format('Y-m-d'); - if (!in_array($day, $days)) { - $days[] = $day; + if (!isset($days[$day])) { + $days[$day] = $shift->start->format(__('Y-m-d')); } } @@ -38,8 +38,8 @@ function room_controller(): array AngelType::query()->get('id')->pluck('id')->toArray() ); $selected_day = date('Y-m-d'); - if (!empty($days) && !in_array($selected_day, $days)) { - $selected_day = $days[0]; + if (!empty($days) && !isset($days[$selected_day])) { + $selected_day = array_key_first($days); } if ($request->input('shifts_filter_day')) { $selected_day = $request->input('shifts_filter_day'); diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index d6d8e167..b865673b 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -273,8 +273,8 @@ function shift_delete_controller() error(sprintf( __('Do you want to delete the shift %s from %s to %s?'), $shift->shiftType->name, - $shift->start->format('Y-m-d H:i'), - $shift->end->format('H:i') + $shift->start->format(__('Y-m-d H:i')), + $shift->end->format(__('H:i')) ), true), form([ form_hidden('delete_shift', $shift->id), diff --git a/includes/helper/shift_helper.php b/includes/helper/shift_helper.php index 1cb8d901..9af7481f 100644 --- a/includes/helper/shift_helper.php +++ b/includes/helper/shift_helper.php @@ -41,13 +41,13 @@ class Shift (($end->timestamp - $start->timestamp) / 60 / 60) * Shifts::getNightShiftMultiplier($start, $end); $workLog->comment = sprintf( - '%s (%s as %s) in %s, %s - %s', + __('%s (%s as %s) in %s, %s - %s'), $name, $title, $type, $room->name, - $start->format('Y-m-d H:i'), - $end->format('Y-m-d H:i') + $start->format(__('Y-m-d H:i')), + $end->format(__('Y-m-d H:i')) ); $workLog->save(); diff --git a/includes/mailer/shifts_mailer.php b/includes/mailer/shifts_mailer.php index c1eee921..ce037e54 100644 --- a/includes/mailer/shifts_mailer.php +++ b/includes/mailer/shifts_mailer.php @@ -36,8 +36,8 @@ function mail_shift_change(Shift $old_shift, Shift $new_shift) if ($old_shift->start->timestamp != $new_shift->start->timestamp) { $message .= sprintf( __('* Shift Start changed from %s to %s'), - $old_shift->start->format('Y-m-d H:i'), - $new_shift->start->format('Y-m-d H:i') + $old_shift->start->format(__('Y-m-d H:i')), + $new_shift->start->format(__('Y-m-d H:i')) ) . "\n"; $noticeable_changes = true; } @@ -45,8 +45,8 @@ function mail_shift_change(Shift $old_shift, Shift $new_shift) if ($old_shift->end->timestamp != $new_shift->end->timestamp) { $message .= sprintf( __('* Shift End changed from %s to %s'), - $old_shift->end->format('Y-m-d H:i'), - $new_shift->end->format('Y-m-d H:i') + $old_shift->end->format(__('Y-m-d H:i')), + $new_shift->end->format(__('Y-m-d H:i')) ) . "\n"; $noticeable_changes = true; } @@ -66,7 +66,7 @@ function mail_shift_change(Shift $old_shift, Shift $new_shift) $message .= $new_shift->shiftType->name . "\n"; $message .= $new_shift->title . "\n"; - $message .= $new_shift->start->format('Y-m-d H:i') . ' - ' . $new_shift->end->format('H:i') . "\n"; + $message .= $new_shift->start->format(__('Y-m-d H:i')) . ' - ' . $new_shift->end->format(__('H:i')) . "\n"; $message .= $new_room->name . "\n\n"; $message .= url('/shifts', ['action' => 'view', 'shift_id' => $new_shift->id]) . "\n"; @@ -94,7 +94,7 @@ function mail_shift_assign(User $user, Shift $shift) $message = __('You have been assigned to a Shift:') . "\n"; $message .= $shift->shiftType->name . "\n"; $message .= $shift->title . "\n"; - $message .= $shift->start->format('Y-m-d H:i') . ' - ' . $shift->end->format('H:i') . "\n"; + $message .= $shift->start->format(__('Y-m-d H:i')) . ' - ' . $shift->end->format(__('H:i')) . "\n"; $message .= $room->name . "\n\n"; $message .= url('/shifts', ['action' => 'view', 'shift_id' => $shift->id]) . "\n"; @@ -112,7 +112,7 @@ function mail_shift_removed(User $user, Shift $shift) $message = __('You have been removed from a Shift:') . "\n"; $message .= $shift->shiftType->name . "\n"; $message .= $shift->title . "\n"; - $message .= $shift->start->format('Y-m-d H:i') . ' - ' . $shift->end->format('H:i') . "\n"; + $message .= $shift->start->format(__('Y-m-d H:i')) . ' - ' . $shift->end->format(__('H:i')) . "\n"; $message .= $room->name . "\n"; engelsystem_email_to_user($user, __('Removed from Shift'), $message, true); diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index 5767d818..a4d79017 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -115,7 +115,7 @@ function admin_arrive() ]); if ($usr->state->arrival_date) { - $day = $usr->state->arrival_date->format('Y-m-d'); + $day = $usr->state->arrival_date->format(__('Y-m-d')); if (!isset($arrival_count_at_day[$day])) { $arrival_count_at_day[$day] = 0; } @@ -123,7 +123,7 @@ function admin_arrive() } if ($usr->personalData->planned_arrival_date) { - $day = $usr->personalData->planned_arrival_date->format('Y-m-d'); + $day = $usr->personalData->planned_arrival_date->format(__('Y-m-d')); if (!isset($planned_arrival_count_at_day[$day])) { $planned_arrival_count_at_day[$day] = 0; } @@ -131,7 +131,7 @@ function admin_arrive() } if ($usr->personalData->planned_departure_date && $usr->state->arrived) { - $day = $usr->personalData->planned_departure_date->format('Y-m-d'); + $day = $usr->personalData->planned_departure_date->format(__('Y-m-d')); if (!isset($planned_departure_count_at_day[$day])) { $planned_departure_count_at_day[$day] = 0; } diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 2e3cd84e..339d76ce 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -304,9 +304,9 @@ function admin_shifts() $shifts_table_entry = [ 'timeslot' => icon('clock-history') . ' ' - . $shift['start']->format('Y-m-d H:i') + . $shift['start']->format(__('Y-m-d H:i')) . ' - ' - . $shift['end']->format('H:i') + . $shift['end']->format(__('H:i')) . '
' . Room_name_render(Room::find($shift['room_id'])), 'title' => diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index a62dce01..b30115e4 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -54,7 +54,7 @@ function admin_user() $html .= '' . "\n"; $html .= ' ' . "\n"; $html .= ' ' . "\n"; if (config('enable_user_name')) { $html .= ' ' . "\n"; diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index e031535a..0dbc8823 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -96,7 +96,7 @@ function user_myshifts() return ShiftEntry_edit_view( $shifts_user, - $shift->start->format('Y-m-d H:i') . ', ' . shift_length($shift), + $shift->start->format(__('Y-m-d H:i')) . ', ' . shift_length($shift), $shift->room->name, $shift->shiftType->name, $shiftEntry->angelType->name, diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index c32c9d75..127f0270 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -262,6 +262,10 @@ function view_user_shifts() info(render_user_arrived_hint()); } + $formattedDays = collect($days)->map(function ($value) { + return Carbon::make($value)->format(__('Y-m-d')); + })->toArray(); + return page([ div('col-md-12', [ msg(), @@ -276,14 +280,14 @@ function view_user_shifts() 'start_select' => html_select_key( 'start_day', 'start_day', - array_combine($days, $days), + array_combine($days, $formattedDays), $start_day ), 'start_time' => $start_time, 'end_select' => html_select_key( 'end_day', 'end_day', - array_combine($days, $days), + array_combine($days, $formattedDays), $end_day ), 'end_time' => $end_time, diff --git a/includes/view/ShiftEntry_view.php b/includes/view/ShiftEntry_view.php index c4d98178..31242b46 100644 --- a/includes/view/ShiftEntry_view.php +++ b/includes/view/ShiftEntry_view.php @@ -21,8 +21,8 @@ function ShiftEntry_delete_view_admin(Shift $shift, AngelType $angeltype, User $ __('Do you want to sign off %s from shift %s from %s to %s as %s?'), User_Nick_render($signoff_user), $shift->shiftType->name, - $shift->start->format('Y-m-d H:i'), - $shift->end->format('Y-m-d H:i'), + $shift->start->format(__('Y-m-d H:i')), + $shift->end->format(__('Y-m-d H:i')), $angeltype->name ), true), form([ @@ -49,8 +49,8 @@ function ShiftEntry_delete_view(Shift $shift, AngelType $angeltype, User $signof info(sprintf( __('Do you want to sign off from your shift %s from %s to %s as %s?'), $shift->shiftType->name, - $shift->start->format('Y-m-d H:i'), - $shift->end->format('Y-m-d H:i'), + $shift->start->format(__('Y-m-d H:i')), + $shift->end->format(__('Y-m-d H:i')), $angeltype->name ), true), diff --git a/includes/view/ShiftsFilterRenderer.php b/includes/view/ShiftsFilterRenderer.php index f8af0b73..53158003 100644 --- a/includes/view/ShiftsFilterRenderer.php +++ b/includes/view/ShiftsFilterRenderer.php @@ -49,12 +49,13 @@ class ShiftsFilterRenderer $toolbar = []; if ($this->daySelectionEnabled && !empty($this->days)) { $selected_day = date('Y-m-d', $this->shiftsFilter->getStartTime()); + $selected_day_formatted = date(__('Y-m-d'), $this->shiftsFilter->getStartTime()); $day_dropdown_items = []; - foreach ($this->days as $day) { - $link = $page_link . '&shifts_filter_day=' . $day; + foreach ($this->days as $value => $day) { + $link = $page_link . '&shifts_filter_day=' . $value; $day_dropdown_items[] = toolbar_item_link($link, '', $day); } - $toolbar[] = toolbar_dropdown($selected_day, $day_dropdown_items, true); + $toolbar[] = toolbar_dropdown($selected_day_formatted, $day_dropdown_items, true); if ($dashboardFilter) { $toolbar[] = sprintf( diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php index 8717b9c1..4da95167 100644 --- a/includes/view/Shifts_view.php +++ b/includes/view/Shifts_view.php @@ -61,14 +61,14 @@ function Shift_editor_info_render(Shift $shift) if (!empty($shift->created_by)) { $info[] = sprintf( icon('plus-lg') . __('created at %s by %s'), - $shift->created_at->format('Y-m-d H:i'), + $shift->created_at->format(__('Y-m-d H:i')), User_Nick_render($shift->createdBy) ); } if (!empty($shift->updated_by)) { $info[] = sprintf( icon('pencil') . __('edited at %s by %s'), - $shift->updated_at->format('Y-m-d H:i'), + $shift->updated_at->format(__('Y-m-d H:i')), User_Nick_render($shift->updatedBy) ); } @@ -164,7 +164,7 @@ function Shift_view(Shift $shift, ShiftType $shifttype, Room $room, $angeltypes_ if (config('signup_advance_hours') && $shift->start->timestamp > time() + config('signup_advance_hours') * 3600) { $content[] = info(sprintf( __('This shift is in the far future and becomes available for signup at %s.'), - date(__('Y-m-d') . ' H:i', $shift->start->timestamp - config('signup_advance_hours') * 3600) + date(__('Y-m-d H:i'), $shift->start->timestamp - config('signup_advance_hours') * 3600) ), true); } diff --git a/includes/view/User_view.php b/includes/view/User_view.php index c327bdd7..64d67b8e 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -305,10 +305,10 @@ function User_view_myshift(Shift $shift, $user_source, $its_me) $myshift = [ 'date' => icon('calendar-event') - . $shift->start->format('Y-m-d') . '
' + . $shift->start->format(__('Y-m-d')) . '
' . icon('clock-history') . $shift->start->format('H:i') . ' - ' - . $shift->end->format('H:i'), + . $shift->end->format(__('H:i')), 'duration' => sprintf('%.2f', ($shift->end->timestamp - $shift->start->timestamp) / 3600) . ' h', 'room' => Room_name_render($shift->room), 'shift_info' => $shift_info, @@ -445,7 +445,7 @@ function User_view_worklog(Worklog $worklog, $admin_user_worklog_privilege) } return [ - 'date' => icon('calendar-event') . date('Y-m-d', $worklog->worked_at->timestamp), + 'date' => icon('calendar-event') . date(__('Y-m-d'), $worklog->worked_at->timestamp), 'duration' => sprintf('%.2f', $worklog->hours) . ' h', 'room' => '', 'shift_info' => __('Work log entry'), @@ -453,7 +453,7 @@ function User_view_worklog(Worklog $worklog, $admin_user_worklog_privilege) . sprintf( __('Added by %s at %s'), User_Nick_render($worklog->creator), - $worklog->created_at->format('Y-m-d H:i') + $worklog->created_at->format(__('Y-m-d H:i')) ), 'actions' => $actions, ]; @@ -711,7 +711,7 @@ function User_view_state_admin($freeloader, $user_source) $state[] = '' . icon('house') . sprintf( __('Arrived at %s'), - $user_source->state->arrival_date ? $user_source->state->arrival_date->format('Y-m-d') : '' + $user_source->state->arrival_date ? $user_source->state->arrival_date->format(__('Y-m-d')) : '' ) . ''; @@ -728,7 +728,7 @@ function User_view_state_admin($freeloader, $user_source) $state[] = '' . ($arrivalDate ? sprintf( __('Not arrived (Planned: %s)'), - $arrivalDate->format('Y-m-d') + $arrivalDate->format(__('Y-m-d')) ) : __('Not arrived')) . ''; } diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 16f1423b..86466259 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -797,6 +797,9 @@ msgid "User %s could not be notified by email due to an error." msgstr "" "Aufgrund eines Fehlers konnte dem User %s keine E-Mail gesendet werden." +msgid "%s (%s as %s) in %s, %s - %s" +msgstr "%s (%s als %s) in %s, %s - %s" + #: includes/mailer/shifts_mailer.php:17 msgid "A Shift you are registered on has changed:" msgstr "Eine deiner Schichten hat sich geƤndert:" diff --git a/src/Controllers/DesignController.php b/src/Controllers/DesignController.php index a9935f73..516d9658 100644 --- a/src/Controllers/DesignController.php +++ b/src/Controllers/DesignController.php @@ -53,8 +53,9 @@ class DesignController extends BaseController $date = CarbonImmutable::now(); for ($i = 1; $i <= 600; $i++) { - $formattedDate = $date->format('Y-m-d'); - $dateSelectOptions[$formattedDate] = $formattedDate; + $dateKey = $date->format("Y-m-d"); + $formattedDisplayDate = $date->format(__("Y-m-d")); + $dateSelectOptions[$dateKey] = $formattedDisplayDate; $date = $date->addDay(); }
' . __('Nickname') . '' . '
' . __('Last login') . '

' - . ($user_source->last_login_at ? $user_source->last_login_at->format('Y-m-d H:i') : '-') + . ($user_source->last_login_at ? $user_source->last_login_at->format(__('Y-m-d H:i')) : '-') . '

' . __('Prename') . '' . '