From 2b8eed4bb65adeb2c531390df66efd92562c2646 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 4 May 2015 11:47:08 -0500 Subject: [PATCH] variable: Internationalize most phrases for context typeahead --- include/class.client.php | 3 +- include/class.format.php | 2 ++ include/class.forms.php | 3 ++ include/class.organization.php | 8 ++--- include/class.priority.php | 2 +- include/class.sla.php | 4 +-- include/class.staff.php | 20 +++++++++--- include/class.team.php | 6 ++-- include/class.thread.php | 17 ++++++---- include/class.ticket.php | 33 +++++++++++-------- include/class.topic.php | 10 +++--- include/class.user.php | 58 ++++++++++++++++++++++++++++------ include/class.variable.php | 2 +- 13 files changed, 116 insertions(+), 52 deletions(-) diff --git a/include/class.client.php b/include/class.client.php index 704b046c6..25b03281b 100644 --- a/include/class.client.php +++ b/include/class.client.php @@ -62,8 +62,9 @@ implements EmailContact, ITicketUser, TemplateVariable { static function getVarScope() { return array( + 'email' => __('Email address'), 'name' => array('class' => 'PersonsName', 'desc' => __('Full name')), - 'ticket_link' => __('Link to the ticket'), + 'ticket_link' => __('Auth. token used for auto-login'), ); } diff --git a/include/class.format.php b/include/class.format.php index 59becb5d2..52b2bcff5 100644 --- a/include/class.format.php +++ b/include/class.format.php @@ -828,6 +828,8 @@ implements TemplateVariable { if (method_exists($this, 'get' . ucfirst($what))) return call_user_func(array($this, 'get'.ucfirst($what))); + // TODO: Rebase date format so that locale is discovered HERE. + switch ($what) { case 'short': return Format::date($this->date, $this->fromdb, false, $this->timezone, $this->user); diff --git a/include/class.forms.php b/include/class.forms.php index f0ddc5df0..77744763a 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -2210,6 +2210,8 @@ class FileFieldAttachments { function getVar($tag) { switch ($tag) { + case 'names': + return $this->__toString(); case 'files': throw new OOBContent(OOBContent::FILES, $this->files->all()); } @@ -2217,6 +2219,7 @@ class FileFieldAttachments { static function getVarScope() { return array( + 'names' => __('List of file names'), 'files' => __('Attached files'), ); } diff --git a/include/class.organization.php b/include/class.organization.php index 16ba01293..cc011495f 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -315,10 +315,10 @@ implements TemplateVariable { static function getVarScope() { $base = array( - 'contacts' => array('class' => 'UserList', 'desc' => 'Primary contacts'), - 'manager' => 'Account manager', - 'members' => array('class' => 'UserList', 'desc' => 'Organization members'), - 'name' => 'Organization name', + 'contacts' => array('class' => 'UserList', 'desc' => __('Primary Contacts')), + 'manager' => __('Account Manager'), + 'members' => array('class' => 'UserList', 'desc' => __('Organization Members')), + 'name' => __('Name'), ); $extra = VariableReplacer::compileFormScope(OrganizationForm::getInstance()); return $base + $extra; diff --git a/include/class.priority.php b/include/class.priority.php index 68f1c39d6..8721ad811 100644 --- a/include/class.priority.php +++ b/include/class.priority.php @@ -51,7 +51,7 @@ implements TemplateVariable { function asVar() { return $this->getDesc(); } static function getVarScope() { return array( - 'desc' => 'Priority description', + 'desc' => __('Priority Level'), ); } diff --git a/include/class.sla.php b/include/class.sla.php index f26a399f6..c1b4ead65 100644 --- a/include/class.sla.php +++ b/include/class.sla.php @@ -103,8 +103,8 @@ implements TemplateVariable { static function getVarScope() { return array( - 'name' => 'SLA Name', - 'graceperiod' => 'Grace period (in hours)', + 'name' => __('SLA Plan'), + 'graceperiod' => __("Grace Period (hrs)"), ); } diff --git a/include/class.staff.php b/include/class.staff.php index 47bda2352..9e093d7fc 100644 --- a/include/class.staff.php +++ b/include/class.staff.php @@ -80,18 +80,28 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { static function getVarScope() { return array( - 'dept' => array('class' => 'Dept', 'desc' => 'Department'), - 'email' => 'Email address', + 'dept' => array('class' => 'Dept', 'desc' => __('Department')), + 'email' => __('Email Address'), 'name' => array( - 'class' => 'PersonsName', 'desc' => 'Name of the agent', + 'class' => 'PersonsName', 'desc' => __('Agent name'), ), - 'phone' => 'Phone number', - 'signature' => "Agent's signature", + 'mobile' => __('Mobile Number'), + 'phone' => __('Phone Number'), + 'signature' => __('Signature'), 'timezone' => "Agent's configured timezone", 'username' => 'Access username', ); } + function getVar($tag) { + switch ($tag) { + case 'mobile': + return Format::phone($this->ht['mobile']); + case 'phone': + return Format::phone($this->ht['phone']); + } + } + function getHashtable() { $base = $this->ht; $base['group'] = $base['group_id']; diff --git a/include/class.team.php b/include/class.team.php index 1d4358bfa..04427634a 100644 --- a/include/class.team.php +++ b/include/class.team.php @@ -45,12 +45,12 @@ implements TemplateVariable { static function getVarScope() { return array( - 'name' => 'Team name', + 'name' => __('Team Name'), 'lead' => array( - 'class' => 'Staff', 'desc' => 'Team leader', + 'class' => 'Staff', 'desc' => __('Team Lead'), ), 'members' => array( - 'class' => 'UserList', 'desc' => 'Team members', + 'class' => 'UserList', 'desc' => __('Team Members'), ), ); } diff --git a/include/class.thread.php b/include/class.thread.php index 9a2dde5b9..744e9a3e3 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -857,16 +857,19 @@ implements TemplateVariable { static function getVarScope() { return array( - 'body' => 'Formatted message body', - 'create_date' => 'Date created', - 'ip_address' => 'IP address of remote user, for web submissions', - 'poster' => 'Name of the thread item originator', + 'files' => __('Attached files'), + 'body' => __('Message body'), + 'create_date' => array( + 'class' => 'FormattedDate', 'desc' => __('Date created'), + ), + 'ip_address' => __('IP address of remote user, for web submissions'), + 'poster' => __('Submitter of the thread item'), 'staff' => array( - 'class' => 'Staff', 'desc' => 'Agent posting the note or response', + 'class' => 'Staff', 'desc' => __('Agent posting the note or response'), ), - 'subject' => 'Subject of the message, if any', + 'title' => __('Subject, if any'), 'user' => array( - 'class' => 'User', 'desc' => 'User posting the message', + 'class' => 'User', 'desc' => __('User posting the message'), ), ); } diff --git a/include/class.ticket.php b/include/class.ticket.php index dc2d831e1..d0a766aef 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1834,9 +1834,10 @@ implements RestrictedAccess, Threadable, TemplateVariable { if ($this->isClosed()) return new FormattedDate($this->getCloseDate()); break; + case 'last_update': + return new FormattedDate($upd); case 'user': return $this->getOwner(); - break; default: if (isset($this->_answers[$tag])) // The answer object is retrieved here which will @@ -1850,33 +1851,33 @@ implements RestrictedAccess, Threadable, TemplateVariable { static function getVarScope() { $base = array( - 'assigned' => 'Assigned agent and/or team', + 'assigned' => __('Assigned agent and/or team'), 'close_date' => array( - 'class' => 'FormattedDate', 'desc' => 'Date of ticket closure', + 'class' => 'FormattedDate', 'desc' => __('Date Closed'), ), 'create_date' => array( - 'class' => 'FormattedDate', 'desc' => 'Ticket create date', + 'class' => 'FormattedDate', 'desc' => __('Date created'), ), 'dept' => array( - 'class' => 'Dept', 'desc' => 'Department', + 'class' => 'Dept', 'desc' => __('Department'), ), 'due_date' => array( - 'class' => 'FormattedDate', 'desc' => 'Ticket due date', + 'class' => 'FormattedDate', 'desc' => __('Due Date'), ), - 'email' => 'Default email address of ticket owner', + 'email' => __('Default email address of ticket owner'), 'name' => array( 'class' => 'PersonsName', 'desc' => __('Name of ticket owner'), ), - 'number' => 'Ticket number', - 'phone' => 'Phone number of ticket owner', + 'number' => __('Ticket number'), + 'phone' => __('Phone number of ticket owner'), 'priority' => array( - 'class' => 'Priority', 'desc' => __('Ticket priority'), + 'class' => 'Priority', 'desc' => __('Priority'), ), 'recipients' => array( - 'class' => 'UserList', 'desc' => 'Ticket participant list', + 'class' => 'UserList', 'desc' => __('List of all recipient names'), ), 'status' => array( - 'class' => 'TicketStatus', 'desc' => __('Ticket status'), + 'class' => 'TicketStatus', 'desc' => __('Status'), ), 'staff' => array( 'class' => 'Staff', 'desc' => __('Assigned/closing agent'), @@ -1886,10 +1887,14 @@ implements RestrictedAccess, Threadable, TemplateVariable { 'class' => 'Team', 'desc' => __('Assigned/closing team'), ), 'thread' => array( - 'class' => 'TicketThread', 'desc' => 'Ticket thread', + 'class' => 'TicketThread', 'desc' => __('Ticket Thread'), ), 'topic' => array( - 'class' => 'Topic', 'desc' => 'Help topic', + 'class' => 'Topic', 'desc' => __('Help topic'), + ), + // XXX: Isn't lastreponse and lastmessage more useful + 'last_update' => array( + 'class' => 'FormattedDate', 'desc' => __('Time of last update'), ), 'user' => array( 'class' => 'User', 'desc' => __('Ticket owner'), diff --git a/include/class.topic.php b/include/class.topic.php index c60aa2c9e..776f99e89 100644 --- a/include/class.topic.php +++ b/include/class.topic.php @@ -76,15 +76,15 @@ implements TemplateVariable { static function getVarScope() { return array( 'dept' => array( - 'class' => 'Dept', 'desc' => 'Department', + 'class' => 'Dept', 'desc' => __('Department'), ), - 'fullname' => 'Help topic full path', - 'name' => 'Help topic name', + 'fullname' => __('Help topic full path'), + 'name' => __('Help topic'), 'parent' => array( - 'class' => 'Topic', 'desc' => 'Parent help topic', + 'class' => 'Topic', 'desc' => __('Parent'), ), 'sla' => array( - 'class' => 'SLA', 'desc' => 'Service Level Agreement', + 'class' => 'SLA', 'desc' => __('Service Level Agreement'), ), ); } diff --git a/include/class.user.php b/include/class.user.php index 028832c7d..f4b3c18ed 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -262,7 +262,7 @@ implements TemplateVariable { } function getEmail() { - return $this->default_email->address; + return new EmailAddress($this->default_email->address); } function getFullName() { @@ -344,11 +344,13 @@ implements TemplateVariable { static function getVarScope() { $base = array( - 'email' => 'Default email address', + 'email' => array( + 'class' => 'EmailAddress', 'desc' => __('Default email address') + ), 'name' => array( 'class' => 'PersonsName', 'desc' => 'User name, default format' ), - 'organization' => array('class' => 'Organization', 'desc' => 'Organization'), + 'organization' => array('class' => 'Organization', 'desc' => __('Organization')), ); $extra = VariableReplacer::compileFormScope(UserForm::getInstance()); return $base + $extra; @@ -665,6 +667,47 @@ implements TemplateVariable { } } +class EmailAddress +implements TemplateVariable { + var $address; + + function __construct($address) { + $this->address = $address; + } + + function __toString() { + return $this->address; + } + + function getVar($what) { + require_once PEAR_DIR . 'Mail/RFC822.php'; + require_once PEAR_DIR . 'PEAR.php'; + if (!($mails = Mail_RFC822::parseAddressList($this->address)) || PEAR::isError($mails)) + return ''; + + if (!$list && count($mails) > 1) + return ''; + + $info = $mails[0]; + switch ($what) { + case 'domain': + return $info->host; + case 'personal': + return $info->personal; + case 'mailbox': + return $info->mailbox; + } + } + + static function getVarScope() { + return array( + 'domain' => __('Domain'), + 'mailbox' => __('Mailbox'), + 'personal' => __('Personal name'), + ); + } +} + class PersonsName implements TemplateVariable { var $format; @@ -1266,13 +1309,11 @@ implements TemplateVariable { } function getNames() { - $list = array(); foreach($this->storage as $user) { if (is_object($user)) $list [] = $user->getName(); } - return $list ? implode(', ', $list) : ''; } @@ -1292,15 +1333,14 @@ implements TemplateVariable { if (is_object($user)) $list[] = $user->getEmail(); } - return $list ? implode(', ', $list) : ''; } static function getVarScope() { return array( - 'names' => 'List of names', - 'emails' => 'List of email addresses', - 'full' => 'List of names and email addresses', + 'names' => __('List of names'), + 'emails' => __('List of email addresses'), + 'full' => __('List of names and email addresses'), ); } } diff --git a/include/class.variable.php b/include/class.variable.php index 6401007ae..e47b74d74 100644 --- a/include/class.variable.php +++ b/include/class.variable.php @@ -310,7 +310,7 @@ class PlaceholderList if (count($items) == 1) { return $items[0]; } - return new static($items); + return new static(array_filter($items)); } } -- GitLab