From 074483b6932828bfbbd300b3f5ccd436abde80f1 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 3 Jun 2015 21:25:51 -0400 Subject: [PATCH] Add i18n support --- auth-cas/cas.php | 16 ++++++++++++++-- auth-cas/config.php | 46 ++++++++++++++++++++++++++++++--------------- auth-cas/plugin.php | 8 ++++---- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/auth-cas/cas.php b/auth-cas/cas.php index c8cf187..774f757 100644 --- a/auth-cas/cas.php +++ b/auth-cas/cas.php @@ -82,7 +82,7 @@ function getProfile() { class CasStaffAuthBackend extends ExternalStaffAuthenticationBackend { static $id = "cas"; - static $name = "CAS"; + static $name = /* trans */ "CAS"; static $service_name = "CAS"; @@ -93,6 +93,12 @@ function __construct($config) { $this->cas = new CasAuth($config); } + function getName() { + $config = $this->config; + list($__, $_N) = $config::translate(); + return $__(static::$name); + } + function signOn() { if (isset($_SESSION[':cas']['user'])) { $staff = new StaffSession($this->cas->getEmail()); @@ -119,7 +125,7 @@ function triggerAuth() { class CasClientAuthBackend extends ExternalUserAuthenticationBackend { static $id = "cas.client"; - static $name = "CAS"; + static $name = /* trans */ "CAS"; static $service_name = "CAS"; @@ -128,6 +134,12 @@ function __construct($config) { $this->cas = new CasAuth($config); } + function getName() { + $config = $this->config; + list($__, $_N) = $config::translate(); + return $__(static::$name); + } + function supportsInteractiveAuthentication() { return false; } diff --git a/auth-cas/config.php b/auth-cas/config.php index edd7311..ec62545 100644 --- a/auth-cas/config.php +++ b/auth-cas/config.php @@ -3,48 +3,64 @@ require_once INCLUDE_DIR . 'class.plugin.php'; class CasPluginConfig extends PluginConfig { + + // Provide compatibility function for versions of osTicket prior to + // translation support (v1.9.4) + function translate() { + if (!method_exists('Plugin', 'translate')) { + return array( + function($x) { return $x; }, + function($x, $y, $n) { return $n != 1 ? $y : $x; }, + ); + } + return Plugin::translate('auth-cas'); + } + function getOptions() { + list($__, $_N) = self::translate(); $modes = new ChoiceField(array( - 'label' => 'Authenticate', + 'label' => $__('Authentication'), + 'default' => "disabled", 'choices' => array( - '0' => 'Disabled', - 'staff' => 'Agents Only', - 'client' => 'Clients Only', - 'all' => 'Agents and Clients', + 'disabled' => $__('Disabled'), + 'staff' => $__('Agents Only'), + 'client' => $__('Clients Only'), + 'all' => $__('Agents and Clients'), ), )); return array( 'cas' => new SectionBreakField(array( - 'label' => 'CAS Authentication', + 'label' => $__('CAS Authentication'), )), 'cas-hostname' => new TextboxField(array( - 'label' => 'CAS Server Hostname', + 'label' => $__('CAS Server Hostname'), 'configuration' => array('size'=>60, 'length'=>100), )), 'cas-port' => new TextboxField(array( - 'label' => 'CAS Server Port', + 'label' => $__('CAS Server Port'), 'configuration' => array('size'=>10, 'length'=>8), )), 'cas-context' => new TextboxField(array( - 'label' => 'CAS Server Context', + 'label' => $__('CAS Server Context'), 'configuration' => array('size'=>60, 'length'=>100), - 'hint' => 'This value is "/cas" for most installs.', + 'hint' => $__('This value is "/cas" for most installs.'), )), 'cas-ca-cert-path' => new TextboxField(array( - 'label' => 'CAS CA Cert Path', + 'label' => $__('CAS CA Cert Path'), 'configuration' => array('size'=>60, 'length'=>100), )), 'cas-at-domain' => new TextboxField(array( - 'label' => 'CAS e-mail suffix', + 'label' => $__('CAS e-mail suffix'), 'configuration' => array('size'=>60, 'length'=>100), - 'hint' => 'Use this field if your CAS server does not report an e-mail attribute. ex: "@domain.tld"', + 'hint' => $__('Use this field if your CAS server does not + report an e-mail attribute. ex: "@domain.tld"'), )), 'cas-name-attribute-key' => new TextboxField(array( - 'label' => 'CAS name attribute key', + 'label' => $__('CAS name attribute key'), 'configuration' => array('size'=>60, 'length'=>100), )), 'cas-email-attribute-key' => new TextboxField(array( - 'label' => 'CAS email attribute key', + 'label' => $__('CAS email attribute key'), 'configuration' => array('size'=>60, 'length'=>100), )), 'cas-enabled' => clone $modes, diff --git a/auth-cas/plugin.php b/auth-cas/plugin.php index ac775f3..a3294d1 100644 --- a/auth-cas/plugin.php +++ b/auth-cas/plugin.php @@ -1,11 +1,11 @@ 'auth:cas', # notrans - 'version' => '0.1', - 'name' => 'JASIG CAS Authentication', + 'version' => '0.2', + 'name' => /* trans */ 'JASIG CAS Authentication', 'author' => 'Kevin O\'Connor', - 'description' => 'Provides a configurable authentication backend - for authenticating staff and clients using anJASIG CAS interface.', + 'description' => /* trans */ 'Provides a configurable authentication + backend for authenticating staff and clients using CAS.', 'url' => 'http://www.osticket.com/plugins/auth/cas', 'plugin' => 'authentication.php:CasAuthPlugin', 'requires' => array(