Skip to content
Snippets Groups Projects
Commit 14509222 authored by Jared Hancock's avatar Jared Hancock
Browse files

i18n: Implement system language management

parent 66abbc51
Branches
Tags
No related merge requests found
......@@ -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);
......
......@@ -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,
));
}
......
......@@ -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)
......
......@@ -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
......
......@@ -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) {
......
......@@ -54,7 +54,7 @@ if ($acct = $thisclient->getAccount()) {
</td>
<td>
<?php
$langs = Internationalization::availableLanguages(); ?>
$langs = Internationalization::getConfiguredSystemLanguages(); ?>
<select name="lang">
<option value="">&mdash; <?php echo __('Use Browser Preference'); ?> &mdash;</option>
<?php foreach($langs as $l) {
......
......@@ -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.
......@@ -106,7 +106,7 @@ $info['id']=$staff->getId();
</td>
<td>
<?php
$langs = Internationalization::availableLanguages(); ?>
$langs = Internationalization::getConfiguredSystemLanguages(); ?>
<select name="lang">
<option value="">&mdash; <?php echo __('Use Browser Preference'); ?> &mdash;</option>
<?php foreach($langs as $l) {
......
......@@ -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>&nbsp;
<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="">&mdash; <?php echo __('Select a Language'); ?> &mdash;</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">&nbsp;<?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;">
&nbsp;
<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>
&nbsp;
&nbsp;
<a href="#" onclick="javascript:
return false;
"><?php echo __('manage all phrases'); ?></a>
</td></tr>
<?php } ?>
</table>
<i class="icon-plus-sign"></i>&nbsp;
<select name="add_secondary_language">
<option value="">&mdash; <?php echo __('Add a Language'); ?> &mdash;</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">&nbsp;<?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;">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment