Skip to content

Commit e514bda

Browse files
committed
Create datetimepicker.js file
Extracts the datepicker and timepicker translations logic from the javascript/variables template into the new datetimepicker.js file. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 825c45c commit e514bda

5 files changed

Lines changed: 210 additions & 81 deletions

File tree

js/src/datetimepicker.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
function registerDatePickerTranslations () {
2+
'use strict';
3+
4+
if (! $.datepicker) {
5+
return;
6+
}
7+
8+
$.datepicker.regional[''].closeText = Messages.strCalendarClose;
9+
$.datepicker.regional[''].prevText = Messages.strCalendarPrevious;
10+
$.datepicker.regional[''].nextText = Messages.strCalendarNext;
11+
$.datepicker.regional[''].currentText = Messages.strCalendarCurrent;
12+
$.datepicker.regional[''].monthNames = [
13+
Messages.strMonthNameJan,
14+
Messages.strMonthNameFeb,
15+
Messages.strMonthNameMar,
16+
Messages.strMonthNameApr,
17+
Messages.strMonthNameMay,
18+
Messages.strMonthNameJun,
19+
Messages.strMonthNameJul,
20+
Messages.strMonthNameAug,
21+
Messages.strMonthNameSep,
22+
Messages.strMonthNameOct,
23+
Messages.strMonthNameNov,
24+
Messages.strMonthNameDec,
25+
];
26+
$.datepicker.regional[''].monthNamesShort = [
27+
Messages.strMonthNameJanShort,
28+
Messages.strMonthNameFebShort,
29+
Messages.strMonthNameMarShort,
30+
Messages.strMonthNameAprShort,
31+
Messages.strMonthNameMayShort,
32+
Messages.strMonthNameJunShort,
33+
Messages.strMonthNameJulShort,
34+
Messages.strMonthNameAugShort,
35+
Messages.strMonthNameSepShort,
36+
Messages.strMonthNameOctShort,
37+
Messages.strMonthNameNovShort,
38+
Messages.strMonthNameDecShort,
39+
];
40+
$.datepicker.regional[''].dayNames = [
41+
Messages.strDayNameSun,
42+
Messages.strDayNameMon,
43+
Messages.strDayNameTue,
44+
Messages.strDayNameWed,
45+
Messages.strDayNameThu,
46+
Messages.strDayNameFri,
47+
Messages.strDayNameSat,
48+
];
49+
$.datepicker.regional[''].dayNamesShort = [
50+
Messages.strDayNameSunShort,
51+
Messages.strDayNameMonShort,
52+
Messages.strDayNameTueShort,
53+
Messages.strDayNameWedShort,
54+
Messages.strDayNameThuShort,
55+
Messages.strDayNameFriShort,
56+
Messages.strDayNameSatShort,
57+
];
58+
$.datepicker.regional[''].dayNamesMin = [
59+
Messages.strDayNameSunMin,
60+
Messages.strDayNameMonMin,
61+
Messages.strDayNameTueMin,
62+
Messages.strDayNameWedMin,
63+
Messages.strDayNameThuMin,
64+
Messages.strDayNameFriMin,
65+
Messages.strDayNameSatMin,
66+
];
67+
$.datepicker.regional[''].weekHeader = Messages.strWeekHeader;
68+
$.datepicker.regional[''].showMonthAfterYear = Messages.strMonthAfterYear === 'calendar-year-month';
69+
$.datepicker.regional[''].yearSuffix = Messages.strYearSuffix !== 'none' ? Messages.strYearSuffix : '';
70+
71+
// eslint-disable-next-line no-underscore-dangle
72+
$.extend($.datepicker._defaults, $.datepicker.regional['']);
73+
}
74+
75+
function registerTimePickerTranslations () {
76+
'use strict';
77+
78+
if (! $.timepicker) {
79+
return;
80+
}
81+
82+
$.timepicker.regional[''].timeText = Messages.strCalendarTime;
83+
$.timepicker.regional[''].hourText = Messages.strCalendarHour;
84+
$.timepicker.regional[''].minuteText = Messages.strCalendarMinute;
85+
$.timepicker.regional[''].secondText = Messages.strCalendarSecond;
86+
87+
// eslint-disable-next-line no-underscore-dangle
88+
$.extend($.timepicker._defaults, $.timepicker.regional['']);
89+
}
90+
91+
registerDatePickerTranslations();
92+
registerTimePickerTranslations();

libraries/classes/Controllers/JavaScriptMessagesController.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,121 @@ private function setMessages(): array
694694
'strHide' => __('Hide'),
695695
'strShow' => __('Show'),
696696
'strStructure' => __('Structure'),
697+
698+
/* DateTime Picker */
699+
// l10n: Month name
700+
'strMonthNameJan' => __('January'),
701+
// l10n: Month name
702+
'strMonthNameFeb' => __('February'),
703+
// l10n: Month name
704+
'strMonthNameMar' => __('March'),
705+
// l10n: Month name
706+
'strMonthNameApr' => __('April'),
707+
// l10n: Month name
708+
'strMonthNameMay' => __('May'),
709+
// l10n: Month name
710+
'strMonthNameJun' => __('June'),
711+
// l10n: Month name
712+
'strMonthNameJul' => __('July'),
713+
// l10n: Month name
714+
'strMonthNameAug' => __('August'),
715+
// l10n: Month name
716+
'strMonthNameSep' => __('September'),
717+
// l10n: Month name
718+
'strMonthNameOct' => __('October'),
719+
// l10n: Month name
720+
'strMonthNameNov' => __('November'),
721+
// l10n: Month name
722+
'strMonthNameDec' => __('December'),
723+
/* l10n: Short month name for January */
724+
'strMonthNameJanShort' => __('Jan'),
725+
/* l10n: Short month name for February */
726+
'strMonthNameFebShort' => __('Feb'),
727+
/* l10n: Short month name for March */
728+
'strMonthNameMarShort' => __('Mar'),
729+
/* l10n: Short month name for April */
730+
'strMonthNameAprShort' => __('Apr'),
731+
/* l10n: Short month name for May */
732+
'strMonthNameMayShort' => __('May'),
733+
/* l10n: Short month name for June */
734+
'strMonthNameJunShort' => __('Jun'),
735+
/* l10n: Short month name for July */
736+
'strMonthNameJulShort' => __('Jul'),
737+
/* l10n: Short month name for August */
738+
'strMonthNameAugShort' => __('Aug'),
739+
/* l10n: Short month name for September */
740+
'strMonthNameSepShort' => __('Sep'),
741+
/* l10n: Short month name for October */
742+
'strMonthNameOctShort' => __('Oct'),
743+
/* l10n: Short month name for November */
744+
'strMonthNameNovShort' => __('Nov'),
745+
/* l10n: Short month name for December */
746+
'strMonthNameDecShort' => __('Dec'),
747+
/* l10n: Week day name */
748+
'strDayNameSun' => __('Sunday'),
749+
/* l10n: Week day name */
750+
'strDayNameMon' => __('Monday'),
751+
/* l10n: Week day name */
752+
'strDayNameTue' => __('Tuesday'),
753+
/* l10n: Week day name */
754+
'strDayNameWed' => __('Wednesday'),
755+
/* l10n: Week day name */
756+
'strDayNameThu' => __('Thursday'),
757+
/* l10n: Week day name */
758+
'strDayNameFri' => __('Friday'),
759+
/* l10n: Week day name */
760+
'strDayNameSat' => __('Saturday'),
761+
/* l10n: Short week day name for Sunday */
762+
'strDayNameSunShort' => __('Sun'),
763+
/* l10n: Short week day name for Monday */
764+
'strDayNameMonShort' => __('Mon'),
765+
/* l10n: Short week day name for Tuesday */
766+
'strDayNameTueShort' => __('Tue'),
767+
/* l10n: Short week day name for Wednesday */
768+
'strDayNameWedShort' => __('Wed'),
769+
/* l10n: Short week day name for Thursday */
770+
'strDayNameThuShort' => __('Thu'),
771+
/* l10n: Short week day name for Friday */
772+
'strDayNameFriShort' => __('Fri'),
773+
/* l10n: Short week day name for Saturday */
774+
'strDayNameSatShort' => __('Sat'),
775+
/* l10n: Minimal week day name for Sunday */
776+
'strDayNameSunMin' => __('Su'),
777+
/* l10n: Minimal week day name for Monday */
778+
'strDayNameMonMin' => __('Mo'),
779+
/* l10n: Minimal week day name for Tuesday */
780+
'strDayNameTueMin' => __('Tu'),
781+
/* l10n: Minimal week day name for Wednesday */
782+
'strDayNameWedMin' => __('We'),
783+
/* l10n: Minimal week day name for Thursday */
784+
'strDayNameThuMin' => __('Th'),
785+
/* l10n: Minimal week day name for Friday */
786+
'strDayNameFriMin' => __('Fr'),
787+
/* l10n: Minimal week day name for Saturday */
788+
'strDayNameSatMin' => __('Sa'),
789+
/* l10n: Column header for week of the year in calendar */
790+
'strWeekHeader' => __('Wk'),
791+
// phpcs:ignore Generic.Files.LineLength.TooLong
792+
/* l10n: The month-year order in a calendar. Do not translate! Use either "calendar-month-year" or "calendar-year-month". */
793+
'strMonthAfterYear' => __('calendar-month-year'),
794+
/* l10n: Year suffix for calendar, "none" is empty. */
795+
'strYearSuffix' => __('none'),
796+
/* l10n: A specific point in the day, as shown on a clock. */
797+
'strCalendarTime' => __('Time'),
798+
/* l10n: Period of time. */
799+
'strCalendarHour' => __('Hour'),
800+
/* l10n: Period of time. */
801+
'strCalendarMinute' => __('Minute'),
802+
/* l10n: Period of time. */
803+
'strCalendarSecond' => __('Second'),
804+
/* l10n: Display text for calendar close link */
805+
'strCalendarClose' => __('Done'),
806+
/* l10n: Previous month. Display text for previous month link in calendar */
807+
'strCalendarPrevious' => __('Prev'),
808+
/* l10n: Next month. Display text for next month link in calendar */
809+
'strCalendarNext' => __('Next'),
810+
/* l10n: Display text for current month link in calendar */
811+
'strCalendarCurrent' => __('Today'),
697812
];
698813
}
699814
}

libraries/classes/Header.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ public function getDisplay(): string
400400
$console = $this->console->getDisplay();
401401
$messages = $this->getMessage();
402402

403+
$this->scripts->addFile('datetimepicker.js');
404+
403405
return $this->template->render('header', [
404406
'lang' => $GLOBALS['lang'],
405407
'allow_third_party_framing' => $GLOBALS['cfg']['AllowThirdPartyFraming'],

templates/javascript/variables.twig

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -4,87 +4,6 @@ var themeImagePath = '{{ image() }}';
44
var mysqlDocTemplate = '{{ get_mysql_docu_url('%s') }}';
55
var maxInputVars = {{ max_input_vars }};
66

7-
{% set show_month_after_year -%}
8-
{% trans %}calendar-month-year{% notes %}Month-year order for calendar, use either "calendar-month-year" or "calendar-year-month".{% endtrans %}
9-
{%- endset -%}
10-
{% set year_suffix -%}
11-
{% trans %}none{% notes %}Year suffix for calendar, "none" is empty.{% endtrans %}
12-
{%- endset -%}
13-
14-
if ($.datepicker) {
15-
$.datepicker.regional[''].closeText = '{% apply escape('js') %}{% trans %}Done{% notes %}Display text for calendar close link{% endtrans %}{% endapply %}';
16-
$.datepicker.regional[''].prevText = '{% apply escape('js') %}{% trans %}Prev{% notes %}Previous month. Display text for previous month link in calendar{% endtrans %}{% endapply %}';
17-
$.datepicker.regional[''].nextText = '{% apply escape('js') %}{% trans %}Next{% notes %}Next month. Display text for next month link in calendar{% endtrans %}{% endapply %}';
18-
$.datepicker.regional[''].currentText = '{% apply escape('js') %}{% trans %}Today{% notes %}Display text for current month link in calendar{% endtrans %}{% endapply %}';
19-
$.datepicker.regional[''].monthNames = [
20-
'{{ 'January'|trans }}',
21-
'{{ 'February'|trans }}',
22-
'{{ 'March'|trans }}',
23-
'{{ 'April'|trans }}',
24-
'{{ 'May'|trans }}',
25-
'{{ 'June'|trans }}',
26-
'{{ 'July'|trans }}',
27-
'{{ 'August'|trans }}',
28-
'{{ 'September'|trans }}',
29-
'{{ 'October'|trans }}',
30-
'{{ 'November'|trans }}',
31-
'{{ 'December'|trans }}',
32-
];
33-
$.datepicker.regional[''].monthNamesShort = [
34-
'{% apply escape('js') %}{% trans %}Jan{% notes %}Short month name for January{% endtrans %}{% endapply %}',
35-
'{% apply escape('js') %}{% trans %}Feb{% notes %}Short month name for February{% endtrans %}{% endapply %}',
36-
'{% apply escape('js') %}{% trans %}Mar{% notes %}Short month name for March{% endtrans %}{% endapply %}',
37-
'{% apply escape('js') %}{% trans %}Apr{% notes %}Short month name for April{% endtrans %}{% endapply %}',
38-
'{% apply escape('js') %}{% trans %}May{% notes %}Short month name for May{% endtrans %}{% endapply %}',
39-
'{% apply escape('js') %}{% trans %}Jun{% notes %}Short month name for June{% endtrans %}{% endapply %}',
40-
'{% apply escape('js') %}{% trans %}Jul{% notes %}Short month name for July{% endtrans %}{% endapply %}',
41-
'{% apply escape('js') %}{% trans %}Aug{% notes %}Short month name for August{% endtrans %}{% endapply %}',
42-
'{% apply escape('js') %}{% trans %}Sep{% notes %}Short month name for September{% endtrans %}{% endapply %}',
43-
'{% apply escape('js') %}{% trans %}Oct{% notes %}Short month name for October{% endtrans %}{% endapply %}',
44-
'{% apply escape('js') %}{% trans %}Nov{% notes %}Short month name for November{% endtrans %}{% endapply %}',
45-
'{% apply escape('js') %}{% trans %}Dec{% notes %}Short month name for December{% endtrans %}{% endapply %}',
46-
];
47-
$.datepicker.regional[''].dayNames = [
48-
'{{ 'Sunday'|trans }}',
49-
'{{ 'Monday'|trans }}',
50-
'{{ 'Tuesday'|trans }}',
51-
'{{ 'Wednesday'|trans }}',
52-
'{{ 'Thursday'|trans }}',
53-
'{{ 'Friday'|trans }}',
54-
'{{ 'Saturday'|trans }}',
55-
];
56-
$.datepicker.regional[''].dayNamesShort = [
57-
'{% apply escape('js') %}{% trans %}Sun{% notes %}Short week day name for Sunday{% endtrans %}{% endapply %}',
58-
'{% apply escape('js') %}{% trans %}Mon{% notes %}Short week day name for Monday{% endtrans %}{% endapply %}',
59-
'{% apply escape('js') %}{% trans %}Tue{% notes %}Short week day name for Tuesday{% endtrans %}{% endapply %}',
60-
'{% apply escape('js') %}{% trans %}Wed{% notes %}Short week day name for Wednesday{% endtrans %}{% endapply %}',
61-
'{% apply escape('js') %}{% trans %}Thu{% notes %}Short week day name for Thursday{% endtrans %}{% endapply %}',
62-
'{% apply escape('js') %}{% trans %}Fri{% notes %}Short week day name for Friday{% endtrans %}{% endapply %}',
63-
'{% apply escape('js') %}{% trans %}Sat{% notes %}Short week day name for Saturday{% endtrans %}{% endapply %}',
64-
];
65-
$.datepicker.regional[''].dayNamesMin = [
66-
'{% apply escape('js') %}{% trans %}Su{% notes %}Minimal week day name for Sunday{% endtrans %}{% endapply %}',
67-
'{% apply escape('js') %}{% trans %}Mo{% notes %}Minimal week day name for Monday{% endtrans %}{% endapply %}',
68-
'{% apply escape('js') %}{% trans %}Tu{% notes %}Minimal week day name for Tuesday{% endtrans %}{% endapply %}',
69-
'{% apply escape('js') %}{% trans %}We{% notes %}Minimal week day name for Wednesday{% endtrans %}{% endapply %}',
70-
'{% apply escape('js') %}{% trans %}Th{% notes %}Minimal week day name for Thursday{% endtrans %}{% endapply %}',
71-
'{% apply escape('js') %}{% trans %}Fr{% notes %}Minimal week day name for Friday{% endtrans %}{% endapply %}',
72-
'{% apply escape('js') %}{% trans %}Sa{% notes %}Minimal week day name for Saturday{% endtrans %}{% endapply %}',
73-
];
74-
$.datepicker.regional[''].weekHeader = '{% apply escape('js') %}{% trans %}Wk{% notes %}Column header for week of the year in calendar{% endtrans %}{% endapply %}';
75-
$.datepicker.regional[''].showMonthAfterYear = {{ show_month_after_year == 'calendar-year-month' ? 'true' : 'false' }};
76-
$.datepicker.regional[''].yearSuffix = '{{ year_suffix != 'none' ? year_suffix|e('js') }}';
77-
$.extend($.datepicker._defaults, $.datepicker.regional['']);
78-
}
79-
80-
if ($.timepicker) {
81-
$.timepicker.regional[''].timeText = '{{ 'Time'|trans }}';
82-
$.timepicker.regional[''].hourText = '{{ 'Hour'|trans }}';
83-
$.timepicker.regional[''].minuteText = '{{ 'Minute'|trans }}';
84-
$.timepicker.regional[''].secondText = '{{ 'Second'|trans }}';
85-
$.extend($.timepicker._defaults, $.timepicker.regional['']);
86-
}
87-
887
function extendingValidatorMessages () {
898
$.extend($.validator.messages, {
909
required: '{{ 'This field is required'|trans }}',

webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = [
1818
'config': './js/src/config.js',
1919
'console': './js/src/console.js',
2020
'cross_framing_protection': './js/src/cross_framing_protection.js',
21+
'datetimepicker': './js/src/datetimepicker.js',
2122
'database/central_columns': './js/src/database/central_columns.js',
2223
'database/events': './js/src/database/events.js',
2324
'database/multi_table_query': './js/src/database/multi_table_query.js',

0 commit comments

Comments
 (0)