From 74dcfcb0eeb29c73326b31f403b634bcbf0c465f Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Sun, 2 Feb 2014 18:05:39 -0600 Subject: [PATCH] i18n: Add localization to the jQuery datepicker --- include/ajax.i18n.php | 5 +++-- include/class.forms.php | 4 ++-- include/client/footer.inc.php | 2 +- include/staff/footer.inc.php | 2 +- include/staff/ticket-open.inc.php | 3 +++ setup/cli/modules/i18n.php | 22 +++++++++++++++++++++- 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/include/ajax.i18n.php b/include/ajax.i18n.php index 95fbc5dbc..099004d8b 100644 --- a/include/ajax.i18n.php +++ b/include/ajax.i18n.php @@ -23,8 +23,9 @@ class i18nAjaxAPI extends AjaxController { $i18n = new Internationalization($lang); switch ($key) { - case 'redactor': - $data = $i18n->getTemplate('redactor.js')->getRawData(); + case 'js': + $data = $i18n->getTemplate('js/redactor.js')->getRawData(); + $data .= $i18n->getTemplate('js/jquery.ui.datepicker.js')->getRawData(); header('Content-Type: text/javascript; charset=UTF-8'); break; default: diff --git a/include/class.forms.php b/include/class.forms.php index 126aaaf74..c5cc4b7a4 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -1155,7 +1155,7 @@ class DatetimePickerWidget extends Widget { $_SESSION['TZ_OFFSET']+($_SESSION['TZ_DST']?date('I',$this->value):0); list($hr, $min) = explode(':', date('H:i', $this->value)); - $this->value = date($cfg->getDateFormat(), $this->value); + $this->value = Format::date($cfg->getDateFormat(), $this->value); } ?> <input type="text" name="<?php echo $this->name; ?>" @@ -1176,7 +1176,7 @@ class DatetimePickerWidget extends Widget { showButtonPanel: true, buttonImage: './images/cal.png', showOn:'both', - dateFormat: $.translate_format('<?php echo $cfg->getDateFormat(); ?>'), + dateFormat: $.translate_format('<?php echo $cfg->getDateFormat(); ?>') }); }); </script> diff --git a/include/client/footer.inc.php b/include/client/footer.inc.php index 44acf45cf..25efea2f6 100644 --- a/include/client/footer.inc.php +++ b/include/client/footer.inc.php @@ -16,7 +16,7 @@ elseif ($cfg && $cfg->getSystemLanguage()) $lang = $cfg->getSystemLanguage(); if ($lang && $lang != 'en_US') { ?> <script type="text/javascript" src="ajax.php/i18n/<?php - echo $thisclient->getLanguage(); ?>/redactor"></script> + echo $lang; ?>/js"></script> <?php } ?> </body> </html> diff --git a/include/staff/footer.inc.php b/include/staff/footer.inc.php index 90e79a29e..68779e589 100644 --- a/include/staff/footer.inc.php +++ b/include/staff/footer.inc.php @@ -35,7 +35,7 @@ if ($.support.pjax) { <?php if ($thisstaff && $thisstaff->getLanguage() != 'en_US') { ?> <script type="text/javascript" src="ajax.php/i18n/<?php - echo $thisstaff->getLanguage(); ?>/redactor"></script> + echo $thisstaff->getLanguage(); ?>/js"></script> <?php } ?> </body> </html> diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php index 72a29371b..be63e4452 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -15,6 +15,9 @@ if ($info['topicId'] && ($topic=Topic::lookup($info['topicId']))) { } } +if ($_POST) + $info['duedate'] = Format::date($cfg->getDateFormat(), + strtotime($info['duedate'])); ?> <form action="tickets.php?a=open" method="post" id="save" enctype="multipart/form-data"> <?php csrf_token(); ?> diff --git a/setup/cli/modules/i18n.php b/setup/cli/modules/i18n.php index 044e07e33..d090db54b 100644 --- a/setup/cli/modules/i18n.php +++ b/setup/cli/modules/i18n.php @@ -130,10 +130,30 @@ class i18n_Compiler extends Module { 'http://imperavi.com/webdownload/redactor/lang/?lang=' .strtolower($lang)); if ($code == 200) - $phar->addFromString('redactor.js', $js); + $phar->addFromString('js/redactor.js', $js); else $this->stderr->write("Unable to fetch Redactor language file\n"); + // JQuery UI Datepicker + // http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-de.js + $langs = array($lang); + if (strpos($lang, '_') !== false) { + @list($short) = explode('_', $lang); + $langs[] = $short; + } + foreach ($langs as $l) { + list($code, $js) = $this->_http_get( + 'http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-' + .str_replace('_','-',$l).'.js'); + if ($code == 200) + break; + } + if ($code == 200) + $phar->addFromString('js/jquery.ui.datepicker.js', $js); + else + $this->stderr->write(str_replace('_','-',$lang) + .": Unable to fetch jQuery UI Datepicker locale file\n"); + // TODO: Sign files // Use a very small stub -- GitLab