From 5e77dce3b1531f092a7a5159b38bf52c6631c224 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 15 Jul 2014 09:21:52 -0500
Subject: [PATCH] i18n: Translate a few drop-down items

  * Paper sizes
  * More prompts on ticket filters
---
 include/class.dynamic_forms.php   | 12 ++++++------
 include/class.export.php          |  8 ++++++++
 include/class.topic.php           |  5 ++++-
 include/staff/profile.inc.php     |  6 +++---
 include/staff/ticket-view.inc.php |  5 ++---
 scp/profile.php                   |  1 +
 scp/tickets.php                   |  2 +-
 7 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php
index 8d0416011..7f62314d2 100644
--- a/include/class.dynamic_forms.php
+++ b/include/class.dynamic_forms.php
@@ -237,16 +237,16 @@ class UserForm extends DynamicForm {
         return static::$instance;
     }
 }
-Filter::addSupportedMatches('User Data', function() {
+Filter::addSupportedMatches(/* trans */ 'User Data', function() {
     $matches = array();
     foreach (UserForm::getInstance()->getFields() as $f) {
         if (!$f->hasData())
             continue;
-        $matches['field.'.$f->get('id')] = 'User / '.$f->getLabel();
+        $matches['field.'.$f->get('id')] = __('User').' / '.$f->getLabel();
         if (($fi = $f->getImpl()) instanceof SelectionField) {
             foreach ($fi->getList()->getProperties() as $p) {
                 $matches['field.'.$f->get('id').'.'.$p->get('id')]
-                    = 'User / '.$f->getLabel().' / '.$p->getLabel();
+                    = __('User').' / '.$f->getLabel().' / '.$p->getLabel();
             }
         }
     }
@@ -327,16 +327,16 @@ class TicketForm extends DynamicForm {
     }
 }
 // Add fields from the standard ticket form to the ticket filterable fields
-Filter::addSupportedMatches('Ticket Data', function() {
+Filter::addSupportedMatches(/* trans */ 'Ticket Data', function() {
     $matches = array();
     foreach (TicketForm::getInstance()->getFields() as $f) {
         if (!$f->hasData())
             continue;
-        $matches['field.'.$f->get('id')] = 'Ticket / '.$f->getLabel();
+        $matches['field.'.$f->get('id')] = __('Ticket').' / '.$f->getLabel();
         if (($fi = $f->getImpl()) instanceof SelectionField) {
             foreach ($fi->getList()->getProperties() as $p) {
                 $matches['field.'.$f->get('id').'.'.$p->get('id')]
-                    = 'Ticket / '.$f->getLabel().' / '.$p->getLabel();
+                    = __('Ticket').' / '.$f->getLabel().' / '.$p->getLabel();
             }
         }
     }
diff --git a/include/class.export.php b/include/class.export.php
index 3860c80f8..78be2d432 100644
--- a/include/class.export.php
+++ b/include/class.export.php
@@ -16,6 +16,14 @@
 
 class Export {
 
+    // XXX: This may need to be moved to a print-specific class
+    static $paper_sizes = array(
+        /* trans */ 'Letter',
+        /* trans */ 'Legal',
+        'A4',
+        'A3',
+    );
+
     static function dumpQuery($sql, $headers, $how='csv', $options=array()) {
         $exporters = array(
             'csv' => CsvResultsExporter,
diff --git a/include/class.topic.php b/include/class.topic.php
index ecaeb53b9..bfc1df37f 100644
--- a/include/class.topic.php
+++ b/include/class.topic.php
@@ -384,6 +384,9 @@ class Topic {
         foreach ($update as $idx=>&$id) {
             $id = sprintf("(%s,%s)", db_input($id), db_input($idx+1));
         }
+        if (!count($update))
+            return;
+
         // Thanks, http://stackoverflow.com/a/3466
         $sql = sprintf('INSERT INTO `%s` (topic_id,`sort`) VALUES %s
             ON DUPLICATE KEY UPDATE `sort`=VALUES(`sort`)',
@@ -393,4 +396,4 @@ class Topic {
 }
 
 // Add fields from the standard ticket form to the ticket filterable fields
-Filter::addSupportedMatches('Help Topic', array('topicId' => 'Topic ID'), 100);
+Filter::addSupportedMatches(/* trans */ 'Help Topic', array('topicId' => 'Topic ID'), 100);
diff --git a/include/staff/profile.inc.php b/include/staff/profile.inc.php
index ff3053bdb..65d66172b 100644
--- a/include/staff/profile.inc.php
+++ b/include/staff/profile.inc.php
@@ -185,10 +185,10 @@ $info['id']=$staff->getId();
                 <select name="default_paper_size">
                   <option value="none" selected="selected">&mdash; <?php echo __('None');?> &mdash;</option>
                   <?php
-                  $options=array('Letter', 'Legal', 'A4', 'A3');
-                  foreach($options as $v) {
+
+                  foreach(Export::$paper_sizes as $v) {
                       echo sprintf('<option value="%s" %s>%s</option>',
-                                $v,($info['default_paper_size']==$v)?'selected="selected"':'',$v);
+                                $v,($info['default_paper_size']==$v)?'selected="selected"':'',__($v));
                   }
                   ?>
                 </select>
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index 3d0cd2a26..eb27fc2ce 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -915,11 +915,10 @@ $tcount+= $ticket->getNumNotes();
             <select id="psize" name="psize">
                 <option value="">&mdash; <?php echo __('Select Print Paper Size');?> &mdash;</option>
                 <?php
-                  $options=array('Letter', 'Legal', 'A4', 'A3');
                   $psize =$_SESSION['PAPER_SIZE']?$_SESSION['PAPER_SIZE']:$thisstaff->getDefaultPaperSize();
-                  foreach($options as $v) {
+                  foreach(Export::$paper_sizes as $v) {
                       echo sprintf('<option value="%s" %s>%s</option>',
-                                $v,($psize==$v)?'selected="selected"':'', $v);
+                                $v,($psize==$v)?'selected="selected"':'', __($v));
                   }
                 ?>
             </select>
diff --git a/scp/profile.php b/scp/profile.php
index 0914c49d8..d25d545d4 100644
--- a/scp/profile.php
+++ b/scp/profile.php
@@ -15,6 +15,7 @@
 **********************************************************************/
 
 require_once('staff.inc.php');
+require_once(INCLUDE_DIR.'class.export.php');       // For paper sizes
 
 $msg='';
 $staff=Staff::lookup($thisstaff->getId());
diff --git a/scp/tickets.php b/scp/tickets.php
index 3664b6a1f..58aadfa3c 100644
--- a/scp/tickets.php
+++ b/scp/tickets.php
@@ -21,6 +21,7 @@ require_once(INCLUDE_DIR.'class.filter.php');
 require_once(INCLUDE_DIR.'class.canned.php');
 require_once(INCLUDE_DIR.'class.json.php');
 require_once(INCLUDE_DIR.'class.dynamic_forms.php');
+require_once(INCLUDE_DIR.'class.export.php');       // For paper sizes
 
 $page='';
 $ticket = $user = null; //clean start.
@@ -616,7 +617,6 @@ if($ticket) {
     if($_REQUEST['a']=='open' && $thisstaff->canCreateTickets())
         $inc = 'ticket-open.inc.php';
     elseif($_REQUEST['a'] == 'export') {
-        require_once(INCLUDE_DIR.'class.export.php');
         $ts = strftime('%Y%m%d');
         if (!($token=$_REQUEST['h']))
             $errors['err'] = __('Query token required');
-- 
GitLab