diff --git a/include/ajax.i18n.php b/include/ajax.i18n.php index 2f5ef9ebe7cbc319b3099f5538e16c120fa3eb51..fdb5196d11109bf366b4575c86ba0fc012b99440 100644 --- a/include/ajax.i18n.php +++ b/include/ajax.i18n.php @@ -104,7 +104,7 @@ class i18nAjaxAPI extends AjaxController { global $cfg; $langs = array(); - foreach (array('de', 'ja', 'zh_CN') as $l) { + foreach ($cfg->getSecondaryLanguages() as $l) { $langs[$l] = Internationalization::getLanguageDescription($l); } $json = JsonDataEncoder::encode($langs); diff --git a/include/class.config.php b/include/class.config.php index 9685fb55d40ae45e8006920d2683841605469deb..32d4c6b1d4353491fb9a34473b6727406c2ca2c4 100644 --- a/include/class.config.php +++ b/include/class.config.php @@ -802,7 +802,12 @@ class OsticketConfig extends Config { } function getSecondaryLanguages() { - return array('de', 'ja', 'zh_CN'); + static $langs = null; + if (!isset($langs)) { + $langs = $this->get('secondary_langs'); + $langs = (is_string($langs)) ? explode(',', $langs) : array(); + } + return $langs; } /* Needed by upgrader on 1.6 and older releases upgrade - not not remove */ @@ -867,10 +872,19 @@ class OsticketConfig extends Config { $f['datetime_format']=array('type'=>'string', 'required'=>1, 'error'=>__('Datetime format is required')); $f['daydatetime_format']=array('type'=>'string', 'required'=>1, 'error'=>__('Day, Datetime format is required')); $f['default_timezone_id']=array('type'=>'int', 'required'=>1, 'error'=>__('Default Timezone is required')); + $f['system_language']=array('type'=>'string', 'required'=>1, 'error'=>__('A primary system language is required')); if(!Validator::process($f, $vars, $errors) || $errors) return false; + // Manage secondard languages + $vars['secondary_langs'][] = $vars['add_secondary_language']; + foreach ($vars['secondary_langs'] as $i=>$lang) { + if (!$lang || !Internationalization::isLanguageInstalled($lang)) + unset($vars['secondary_langs'][$i]); + } + $secondary_langs = implode(',', $vars['secondary_langs']); + return $this->updateAll(array( 'isonline'=>$vars['isonline'], 'helpdesk_title'=>$vars['helpdesk_title'], @@ -886,6 +900,8 @@ class OsticketConfig extends Config { 'daydatetime_format'=>$vars['daydatetime_format'], 'default_timezone_id'=>$vars['default_timezone_id'], 'enable_daylight_saving'=>isset($vars['enable_daylight_saving'])?1:0, + 'system_language'=>$vars['system_language'], + 'secondary_langs'=>$secondary_langs, )); } diff --git a/include/class.i18n.php b/include/class.i18n.php index 8db307de912384cc1874f3487b71755c2aeccac8..d141439d1606f1aa38d81f1d4fff12fbb407af58 100644 --- a/include/class.i18n.php +++ b/include/class.i18n.php @@ -245,6 +245,26 @@ class Internationalization { return $cache = $installed; } + static function isLanguageInstalled($code) { + $langs = self::availableLanguages(); + return isset($langs[strtolower($code)]); + } + + static function getConfiguredSystemLanguages() { + global $cfg; + + $langs = array(); + // Honor sorting preference of ::availableLanguages() + foreach (self::availableLanguages() as $k=>$l) { + if ($cfg->getPrimaryLanguage() == $l['code'] + || in_array($l['code'], $cfg->getSecondaryLanguages()) + ) { + $langs[$k] = $l; + } + } + return $langs; + } + // TODO: Move this to the REQUEST class or some middleware when that // exists. // Algorithm borrowed from Drupal 7 (locale.inc) diff --git a/include/class.translation.php b/include/class.translation.php index c4e606fdb0250039eacb3b89a15ea75b2416ce8b..84570ff53faedb2e47577385aebdcba525ecc1a9 100644 --- a/include/class.translation.php +++ b/include/class.translation.php @@ -905,17 +905,11 @@ class CustomDataTranslation extends VerySimpleModel { static function translate($msgid, $locale=false, $cache=true, $type='phrase') { global $thisstaff, $thisclient; - if (!$locale - && ($user = $thisstaff ?: $thisclient) - && method_exists($user, 'getLanguage')) - $locale = $user->getLanguage(); - // Support sending a User as the locale - elseif (is_object($locale) && method_exists($locale, 'getLanguage')) + if (is_object($locale) && method_exists($locale, 'getLanguage')) $locale = $locale->getLanguage(); - - else - $locale = Internationalization::getDefaultLanguage(); + elseif (!$locale) + $locale = Internationalization::getCurrentLanguage(); // Perhaps a slight optimization would be to check if the selected // locale is also the system primary. If so, short-circuit diff --git a/include/client/header.inc.php b/include/client/header.inc.php index 92e9dfe13bdda7cc9ad08fc6cedb9b6f7c0d0b7b..ac28febfb7bc83b706cf1e5b4c7bacbea2b3d44b 100644 --- a/include/client/header.inc.php +++ b/include/client/header.inc.php @@ -82,7 +82,7 @@ if (($lang = Internationalization::getCurrentLanguage()) </p> <p> <?php -if (($all_langs = Internationalization::availableLanguages()) +if (($all_langs = Internationalization::getConfiguredSystemLanguages()) && (count($all_langs) > 1) ) { foreach ($all_langs as $code=>$info) { diff --git a/include/client/profile.inc.php b/include/client/profile.inc.php index 89fa70a095d56c8f68c54d2ae9beb0d23648e299..bcc5aa439b8bcb27cc1563ff46c1d7ab65b9c6fd 100644 --- a/include/client/profile.inc.php +++ b/include/client/profile.inc.php @@ -54,7 +54,7 @@ if ($acct = $thisclient->getAccount()) { </td> <td> <?php - $langs = Internationalization::availableLanguages(); ?> + $langs = Internationalization::getConfiguredSystemLanguages(); ?> <select name="lang"> <option value="">— <?php echo __('Use Browser Preference'); ?> —</option> <?php foreach($langs as $l) { diff --git a/include/i18n/en_US/help/tips/settings.system.yaml b/include/i18n/en_US/help/tips/settings.system.yaml index fd89cbaea2e01ad4c824537b56e47d4d92caaff9..138b6cdb85012ccdc3bf88aa19c6ec25ae595d86 100644 --- a/include/i18n/en_US/help/tips/settings.system.yaml +++ b/include/i18n/en_US/help/tips/settings.system.yaml @@ -88,3 +88,28 @@ date_time_options: links: - title: See the PHP Date Formatting Table href: http://www.php.net/manual/en/function.date.php + +languages: + title: System Languages + content: > + Choose a system primary language and optionally secondary languages + to make your interface feel localized for your agents and end-users. + +primary_language: + title: System Primary Language + content: > + Content of this language is displayed to agents and end-users if + their respective language preference is not currently available. + This includes the content of the interface, as well as, custom + content such as thank-you pages and email messages. + <br/><br/> + This is the language in which the untranslated versions of your + content should be written. + +secondary_language: + title: Secondary Languages + content: > + Select language preference options for your agents and end-users. + The interface will be available in these languages, and custom + content, such as thank-you pages and help topic names, will be + translatable to these languages. diff --git a/include/staff/profile.inc.php b/include/staff/profile.inc.php index a5daad3c52557183cc6d24a88fdf328cdb753b14..e47784fc4eee6a13949e89a5b28979e0aeb53584 100644 --- a/include/staff/profile.inc.php +++ b/include/staff/profile.inc.php @@ -106,7 +106,7 @@ $info['id']=$staff->getId(); </td> <td> <?php - $langs = Internationalization::availableLanguages(); ?> + $langs = Internationalization::getConfiguredSystemLanguages(); ?> <select name="lang"> <option value="">— <?php echo __('Use Browser Preference'); ?> —</option> <?php foreach($langs as $l) { diff --git a/include/staff/settings-system.inc.php b/include/staff/settings-system.inc.php index 30efbb4c5d084cbd44c5f4a48b915bf39e6afb11..748041692575e2111d3cd38ee4ad462edd5be777 100644 --- a/include/staff/settings-system.inc.php +++ b/include/staff/settings-system.inc.php @@ -174,6 +174,71 @@ $gmtime = Misc::gmtime(); <input type="checkbox" name="enable_daylight_saving" <?php echo $config['enable_daylight_saving'] ? 'checked="checked"': ''; ?>><?php echo __('Observe daylight savings');?> </td> </tr> + + <tr> + <th colspan="2"> + <em><b><?php echo __('System Languages'); ?></b> + <i class="help-tip icon-question-sign" href="#languages"></i> + </em> + </th> + </tr> + <tr><td><?php echo __('Primary Language'); ?>:</td> + <td> + <?php + $langs = Internationalization::availableLanguages(); ?> + <select name="system_language"> + <option value="">— <?php echo __('Select a Language'); ?> —</option> +<?php foreach($langs as $l) { + $selected = ($config['system_language'] == $l['code']) ? 'selected="selected"' : ''; ?> + <option value="<?php echo $l['code']; ?>" <?php echo $selected; + ?>><?php echo Internationalization::getLanguageDescription($l['code']); ?></option> +<?php } ?> + </select> + <span class="error"> <?php echo $errors['system_language']; ?></span> + <i class="help-tip icon-question-sign" href="#primary_language"></i> + </td> + </tr> + <tr> + <td style="vertical-align:top;padding-top:4px;"><?php echo __('Secondary Languages'); ?>:</td> + <td><table><?php + foreach ($cfg->getSecondaryLanguages() as $lang) { ?> + <tr><td style="border:none;"> + <?php echo Internationalization::getLanguageDescription($lang); ?> + <input type="hidden" name="secondary_langs[]" value="<?php echo $lang; ?>"/> + </td><td style="border:none;"> + + <a href="#<?php echo $lang; ?>" onclick="javascript: + if (confirm(__('You sure?'))) { + $(this).closest('form').find('input[name=\'secondary_langs[]\'][value=' + + $(this).attr('href').substr(1) + ']').val(''); + $(this).closest('tr').remove(); + } + return false; + "><i class="icon-trash"></i></a> + + + <a href="#" onclick="javascript: + return false; + "><?php echo __('manage all phrases'); ?></a> + </td></tr> +<?php } ?> + </table> + <i class="icon-plus-sign"></i> + <select name="add_secondary_language"> + <option value="">— <?php echo __('Add a Language'); ?> —</option> +<?php foreach($langs as $l) { + $selected = ($config['add_secondary_language'] == $l['code']) ? 'selected="selected"' : ''; + if (!$selected && $l['code'] == $cfg->getPrimaryLanguage()) + continue; + if (!$selected && in_array($l['code'], $cfg->getSecondaryLanguages())) + continue; ?> + <option value="<?php echo $l['code']; ?>" <?php echo $selected; + ?>><?php echo Internationalization::getLanguageDescription($l['code']); ?></option> +<?php } ?> + </select> + <span class="error"> <?php echo $errors['add_secondary_langyage']; ?></span> + <i class="help-tip icon-question-sign" href="#secondary_language"></i> + </td></tr> </tbody> </table> <p style="padding-left:250px;">