Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

JHTMLBehavior::_calendartranslation #1567

Closed
wants to merge 1 commit into from

2 participants

@okonomiyaki3000

rewritten for improved readability

@LouisLandry

There's a unit test error that we need to take care of before this can be merged. http://developer.joomla.org/pulls/pulls/1567.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 75 additions and 52 deletions.
  1. +75 −52 libraries/joomla/html/behavior.php
View
127 libraries/joomla/html/behavior.php
@@ -838,60 +838,83 @@ protected static function _calendartranslation()
{
static $jsscript = 0;
- if ($jsscript == 0)
- {
- $return = 'Calendar._DN = new Array ("' . JText::_('SUNDAY', true) . '", "' . JText::_('MONDAY', true) . '", "'
- . JText::_('TUESDAY', true) . '", "' . JText::_('WEDNESDAY', true) . '", "' . JText::_('THURSDAY', true) . '", "'
- . JText::_('FRIDAY', true) . '", "' . JText::_('SATURDAY', true) . '", "' . JText::_('SUNDAY', true) . '");'
- . ' Calendar._SDN = new Array ("' . JText::_('SUN', true) . '", "' . JText::_('MON', true) . '", "' . JText::_('TUE', true) . '", "'
- . JText::_('WED', true) . '", "' . JText::_('THU', true) . '", "' . JText::_('FRI', true) . '", "' . JText::_('SAT', true) . '", "'
- . JText::_('SUN', true) . '");' . ' Calendar._FD = 0;' . ' Calendar._MN = new Array ("' . JText::_('JANUARY', true) . '", "'
- . JText::_('FEBRUARY', true) . '", "' . JText::_('MARCH', true) . '", "' . JText::_('APRIL', true) . '", "' . JText::_('MAY', true)
- . '", "' . JText::_('JUNE', true) . '", "' . JText::_('JULY', true) . '", "' . JText::_('AUGUST', true) . '", "'
- . JText::_('SEPTEMBER', true) . '", "' . JText::_('OCTOBER', true) . '", "' . JText::_('NOVEMBER', true) . '", "'
- . JText::_('DECEMBER', true) . '");' . ' Calendar._SMN = new Array ("' . JText::_('JANUARY_SHORT', true) . '", "'
- . JText::_('FEBRUARY_SHORT', true) . '", "' . JText::_('MARCH_SHORT', true) . '", "' . JText::_('APRIL_SHORT', true) . '", "'
- . JText::_('MAY_SHORT', true) . '", "' . JText::_('JUNE_SHORT', true) . '", "' . JText::_('JULY_SHORT', true) . '", "'
- . JText::_('AUGUST_SHORT', true) . '", "' . JText::_('SEPTEMBER_SHORT', true) . '", "' . JText::_('OCTOBER_SHORT', true) . '", "'
- . JText::_('NOVEMBER_SHORT', true) . '", "' . JText::_('DECEMBER_SHORT', true) . '");'
- . ' Calendar._TT = {};Calendar._TT["INFO"] = "' . JText::_('JLIB_HTML_BEHAVIOR_ABOUT_THE_CALENDAR', true) . '";'
- . ' Calendar._TT["ABOUT"] =
- "DHTML Date/Time Selector\n" +
- "(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n" +
-"For latest version visit: http://www.dynarch.com/projects/calendar/\n" +
-"Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details." +
-"\n\n" +
-"' . JText::_('JLIB_HTML_BEHAVIOR_DATE_SELECTION', false, false) . '" +
-"' . JText::_('JLIB_HTML_BEHAVIOR_YEAR_SELECT', false, false) . '" +
-"' . JText::_('JLIB_HTML_BEHAVIOR_MONTH_SELECT', false, false) . '" +
-"' . JText::_('JLIB_HTML_BEHAVIOR_HOLD_MOUSE', false, false)
- . '";
-Calendar._TT["ABOUT_TIME"] = "\n\n" +
-"Time selection:\n" +
-"- Click on any of the time parts to increase it\n" +
-"- or Shift-click to decrease it\n" +
-"- or click and drag for faster selection.";
-
- Calendar._TT["PREV_YEAR"] = "' . JText::_('JLIB_HTML_BEHAVIOR_PREV_YEAR_HOLD_FOR_MENU', true) . '";' . ' Calendar._TT["PREV_MONTH"] = "'
- . JText::_('JLIB_HTML_BEHAVIOR_PREV_MONTH_HOLD_FOR_MENU', true) . '";' . ' Calendar._TT["GO_TODAY"] = "'
- . JText::_('JLIB_HTML_BEHAVIOR_GO_TODAY', true) . '";' . ' Calendar._TT["NEXT_MONTH"] = "'
- . JText::_('JLIB_HTML_BEHAVIOR_NEXT_MONTH_HOLD_FOR_MENU', true) . '";' . ' Calendar._TT["NEXT_YEAR"] = "'
- . JText::_('JLIB_HTML_BEHAVIOR_NEXT_YEAR_HOLD_FOR_MENU', true) . '";' . ' Calendar._TT["SEL_DATE"] = "'
- . JText::_('JLIB_HTML_BEHAVIOR_SELECT_DATE', true) . '";' . ' Calendar._TT["DRAG_TO_MOVE"] = "'
- . JText::_('JLIB_HTML_BEHAVIOR_DRAG_TO_MOVE', true) . '";' . ' Calendar._TT["PART_TODAY"] = "'
- . JText::_('JLIB_HTML_BEHAVIOR_TODAY', true) . '";' . ' Calendar._TT["DAY_FIRST"] = "'
- . JText::_('JLIB_HTML_BEHAVIOR_DISPLAY_S_FIRST', true) . '";' . ' Calendar._TT["WEEKEND"] = "0,6";' . ' Calendar._TT["CLOSE"] = "'
- . JText::_('JLIB_HTML_BEHAVIOR_CLOSE', true) . '";' . ' Calendar._TT["TODAY"] = "' . JText::_('JLIB_HTML_BEHAVIOR_TODAY', true)
- . '";' . ' Calendar._TT["TIME_PART"] = "' . JText::_('JLIB_HTML_BEHAVIOR_SHIFT_CLICK_OR_DRAG_TO_CHANGE_VALUE', true) . '";'
- . ' Calendar._TT["DEF_DATE_FORMAT"] = "%Y-%m-%d";' . ' Calendar._TT["TT_DATE_FORMAT"] = "'
- . JText::_('JLIB_HTML_BEHAVIOR_TT_DATE_FORMAT', true) . '";' . ' Calendar._TT["WK"] = "' . JText::_('JLIB_HTML_BEHAVIOR_WK', true) . '";'
- . ' Calendar._TT["TIME"] = "' . JText::_('JLIB_HTML_BEHAVIOR_TIME', true) . '";';
- $jsscript = 1;
- return $return;
- }
- else
+ // Guard clause, avoids unnecessary nesting
+ if ($jsscript)
{
return false;
}
+
+ $jsscript = 1;
+
+ // To keep the code simple here, run strings through JText::_() using array_map()
+ $callback = array('JText','_');
+ $weekdays_full = array_map(
+ $callback, array(
+ 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY'
+ )
+ );
+ $weekdays_short = array_map(
+ $callback,
+ array(
+ 'SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'
+ )
+ );
+ $months_long = array_map(
+ $callback, array(
+ 'JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE',
+ 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'
+ )
+ );
+ $months_short = array_map(
+ $callback, array(
+ 'JANUARY_SHORT', 'FEBRUARY_SHORT', 'MARCH_SHORT', 'APRIL_SHORT', 'MAY_SHORT', 'JUNE_SHORT',
+ 'JULY_SHORT', 'AUGUST_SHORT', 'SEPTEMBER_SHORT', 'OCTOBER_SHORT', 'NOVEMBER_SHORT', 'DECEMBER_SHORT'
+ )
+ );
+
+ // This will become an object in Javascript but define it first in PHP for readability
+ $text = array(
+ 'INFO' => JText::_('JLIB_HTML_BEHAVIOR_ABOUT_THE_CALENDAR'),
+
+ 'ABOUT' => "DHTML Date/Time Selector\n"
+ . "(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n"
+ . "For latest version visit: http://www.dynarch.com/projects/calendar/\n"
+ . "Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details."
+ . "\n\n"
+ . JText::_('JLIB_HTML_BEHAVIOR_DATE_SELECTION')
+ . JText::_('JLIB_HTML_BEHAVIOR_YEAR_SELECT')
+ . JText::_('JLIB_HTML_BEHAVIOR_MONTH_SELECT')
+ . JText::_('JLIB_HTML_BEHAVIOR_HOLD_MOUSE'),
+
+ 'ABOUT_TIME' => "\n\n"
+ . "Time selection:\n"
+ . "- Click on any of the time parts to increase it\n"
+ . "- or Shift-click to decrease it\n"
+ . "- or click and drag for faster selection.",
+
+ 'PREV_YEAR' => JText::_('JLIB_HTML_BEHAVIOR_PREV_YEAR_HOLD_FOR_MENU'),
+ 'PREV_MONTH' => JText::_('JLIB_HTML_BEHAVIOR_PREV_MONTH_HOLD_FOR_MENU'),
+ 'GO_TODAY' => JText::_('JLIB_HTML_BEHAVIOR_GO_TODAY'),
+ 'NEXT_MONTH' => JText::_('JLIB_HTML_BEHAVIOR_NEXT_MONTH_HOLD_FOR_MENU'),
+ 'SEL_DATE' => JText::_('JLIB_HTML_BEHAVIOR_SELECT_DATE'),
+ 'DRAG_TO_MOVE' => JText::_('JLIB_HTML_BEHAVIOR_DRAG_TO_MOVE'),
+ 'PART_TODAY' => JText::_('JLIB_HTML_BEHAVIOR_TODAY'),
+ 'DAY_FIRST' => JText::_('JLIB_HTML_BEHAVIOR_DISPLAY_S_FIRST'),
+ 'WEEKEND' => "0,6",
+ 'CLOSE' => JText::_('JLIB_HTML_BEHAVIOR_CLOSE'),
+ 'TODAY' => JText::_('JLIB_HTML_BEHAVIOR_TODAY'),
+ 'TIME_PART' => JText::_('JLIB_HTML_BEHAVIOR_SHIFT_CLICK_OR_DRAG_TO_CHANGE_VALUE'),
+ 'DEF_DATE_FORMAT' => "%Y-%m-%d",
+ 'TT_DATE_FORMAT' => JText::_('JLIB_HTML_BEHAVIOR_TT_DATE_FORMAT'),
+ 'WK' => JText::_('JLIB_HTML_BEHAVIOR_WK'),
+ 'TIME' => JText::_('JLIB_HTML_BEHAVIOR_TIME')
+ );
+
+ return 'Calendar._DN = ' . json_encode($weekdays_full) . ';'
+ . ' Calendar._SDN = ' . json_encode($weekdays_short) . ';'
+ . ' Calendar._FD = 0;'
+ . ' Calendar._MN = ' . json_encode($months_long) . ';'
+ . ' Calendar._SMN = ' . json_encode($months_short) . ';'
+ . ' Calendar._TT = ' . json_encode($text) . ';';
}
}
Something went wrong with that request. Please try again.