Use gettext for translation

This commit is contained in:
Eike Foken
2011-08-11 02:41:38 +02:00
parent 2daa1a6fad
commit 2825923b75
6 changed files with 70 additions and 113 deletions

View File

@@ -6,7 +6,7 @@
* @author Eike Foken <kontakt@eikefoken.de> * @author Eike Foken <kontakt@eikefoken.de>
* *
*/ */
class Users extends MY_Controller { class Users extends CI_Controller {
/** /**
* Constructor. * Constructor.
@@ -32,41 +32,41 @@ class Users extends MY_Controller {
$config = array( $config = array(
array( array(
'field' => 'username', 'field' => 'username',
'label' => 'lang:field_username', 'label' => _('Username'),
'rules' => 'trim|required|min_length[4]|max_length[20]|unique[users.username]', 'rules' => 'trim|required|min_length[4]|max_length[20]|unique[users.username]',
), ),
array( array(
'field' => 'password', 'field' => 'password',
'label' => 'lang:field_password', 'label' => _('Password'),
'rules' => 'required|min_length[6]|matches[password_confirm]', 'rules' => 'required|min_length[6]|matches[password_confirm]',
), ),
array( array(
'field' => 'password_confirm', 'field' => 'password_confirm',
'label' => 'lang:field_password_confirm', 'label' => _('Confirm password'),
), ),
array( array(
'field' => 'firstname', 'field' => 'firstname',
'label' => 'lang:field_firstname', 'label' => _('First name'),
'rules' => 'trim|required|max_length[50]', 'rules' => 'trim|required|max_length[50]',
), ),
array( array(
'field' => 'lastname', 'field' => 'lastname',
'label' => 'lang:field_lastname', 'label' => _('Last name'),
'rules' => 'trim|required|max_length[50]', 'rules' => 'trim|required|max_length[50]',
), ),
array( array(
'field' => 'email', 'field' => 'email',
'label' => 'lang:field_email', 'label' => _('Email address'),
'rules' => 'trim|required|valid_email', 'rules' => 'trim|required|valid_email',
), ),
array( array(
'field' => 'institution', 'field' => 'institution',
'label' => 'lang:field_institution', 'label' => _('Institution'),
'rules' => 'trim|max_length[100]', 'rules' => 'trim|max_length[100]',
), ),
array( array(
'field' => 'phone', 'field' => 'phone',
'label' => 'lang:field_phone', 'label' => _('Phone number'),
'rules' => 'trim|regex_match[/^\+\d{2,4}\s\d{2,4}\s\d{3,10}+$/i]', 'rules' => 'trim|regex_match[/^\+\d{2,4}\s\d{2,4}\s\d{3,10}+$/i]',
) )
); );
@@ -83,7 +83,7 @@ class Users extends MY_Controller {
); );
if ($this->user->register($username, $this->input->post('password'), $this->input->post('email'), $data)) { if ($this->user->register($username, $this->input->post('password'), $this->input->post('email'), $data)) {
$this->messages->add("The user '" . $username . "' was created", 'success'); $this->messages->add(sprintf(_("The user '%s' was created"), $username), 'success');
redirect('users', 201); redirect('users', 201);
} }
} }
@@ -106,27 +106,27 @@ class Users extends MY_Controller {
$config = array( $config = array(
array( array(
'field' => 'firstname', 'field' => 'firstname',
'label' => 'lang:field_firstname', 'label' => _('First name'),
'rules' => 'trim|required|max_length[50]', 'rules' => 'trim|required|max_length[50]',
), ),
array( array(
'field' => 'lastname', 'field' => 'lastname',
'label' => 'lang:field_lastname', 'label' => _('Last name'),
'rules' => 'trim|required|max_length[50]', 'rules' => 'trim|required|max_length[50]',
), ),
array( array(
'field' => 'email', 'field' => 'email',
'label' => 'lang:field_email', 'label' => _('Email address'),
'rules' => 'trim|required|valid_email', 'rules' => 'trim|required|valid_email',
), ),
array( array(
'field' => 'institution', 'field' => 'institution',
'label' => 'lang:field_institution', 'label' => _('Institution'),
'rules' => 'trim|max_length[100]', 'rules' => 'trim|max_length[100]',
), ),
array( array(
'field' => 'phone', 'field' => 'phone',
'label' => 'lang:field_phone', 'label' => _('Phone number'),
'rules' => 'trim|regex_match[/^\+\d{2,4}\s\d{2,4}\s\d{3,10}+$/i]', 'rules' => 'trim|regex_match[/^\+\d{2,4}\s\d{2,4}\s\d{3,10}+$/i]',
) )
); );
@@ -142,7 +142,7 @@ class Users extends MY_Controller {
); );
if ($this->user->update($user['id'], $data)) { if ($this->user->update($user['id'], $data)) {
$this->messages->add("The user '" . $user['username'] . "' was updated", 'success'); $this->messages->add(sprintf(_("The user '%s' was updated"), $user['username']), 'success');
redirect('users', 200); redirect('users', 200);
} }
} }
@@ -162,8 +162,12 @@ class Users extends MY_Controller {
show_404(); show_404();
} else { } else {
$this->user->delete($user['id']); $this->user->delete($user['id']);
$this->messages->add('The selected user was deleted', 'success'); $this->messages->add(_("The selected user was deleted"), 'success');
redirect('users', 200); redirect('users', 200);
} }
} }
} }
/* End of file users.php */
/* Location: ./application/constrollers/users.php */

View File

@@ -52,11 +52,11 @@ class Access {
*/ */
public function changePassword($username, $old, $new) { public function changePassword($username, $old, $new) {
if ($this->ci->user->changePassword($username, $old, $new)) { if ($this->ci->user->changePassword($username, $old, $new)) {
$this->setMessage('password_change_successful'); $this->setMessage(_('Password successfully changed'));
return true; return true;
} }
$this->setError('password_change_unsuccessful'); $this->setError(_('Unable to change password'));
return false; return false;
} }
@@ -86,14 +86,14 @@ class Access {
$this->ci->email->message($message); $this->ci->email->message($message);
if ($this->ci->email->send()) { if ($this->ci->email->send()) {
$this->setMessage('forgot_password_successful'); $this->setMessage(_('Password reset email sent'));
return true; return true;
} else { } else {
$this->setError('forgot_password_unsuccessful'); $this->setError(_('Unable to reset password'));
return false; return false;
} }
} else { } else {
$this->setError('forgot_password_unsuccessful'); $this->setError(_('Unable to reset password'));
return false; return false;
} }
} }
@@ -107,7 +107,7 @@ class Access {
$profile = $this->ci->user->profile($code, true); // pass the code to profile $profile = $this->ci->user->profile($code, true); // pass the code to profile
if (!is_object($profile)) { if (!is_object($profile)) {
$this->setError('password_change_unsuccessful'); $this->setError(_('Unable to change password'));
return false; return false;
} }
@@ -131,35 +131,18 @@ class Access {
$this->ci->email->message($message); $this->ci->email->message($message);
if ($this->ci->email->send()) { if ($this->ci->email->send()) {
$this->setMessage('password_change_successful'); $this->setMessage(_('Password successfully changed'));
return true; return true;
} else { } else {
$this->setError('password_change_unsuccessful'); $this->setError(_('Unable to change password'));
return false; return false;
} }
} }
$this->setError('password_change_unsuccessful'); $this->setError(_('Unable to change password'));
return false; return false;
} }
/**
* Registers a new user.
*
* @return integer|boolean
*/
public function register($username, $password, $email, $additionalData, $groupName = false) {
$id = $this->ci->user->register($username, $password, $email, $additionalData, $groupName);
if ($id !== false) {
$this->setMessage('account_creation_successful');
return $id;
} else {
$this->setError('account_creation_unsuccessful');
return false;
}
}
/** /**
* Logs the user in. * Logs the user in.
* *
@@ -167,10 +150,10 @@ class Access {
*/ */
public function login($username, $password, $remember = false) { public function login($username, $password, $remember = false) {
if ($this->ci->user->login($username, $password, $remember)) { if ($this->ci->user->login($username, $password, $remember)) {
$this->setMessage('login_successful'); $this->setMessage(_('Logged in successfully'));
return true; return true;
} else { } else {
$this->setError('login_unsuccessful'); $this->setError(_('Incorrect username or password'));
return false; return false;
} }
} }
@@ -194,7 +177,7 @@ class Access {
$this->ci->session->sess_destroy(); $this->ci->session->sess_destroy();
$this->setMessage('logout_successful'); $this->setMessage(_('Logged out successfully'));
return true; return true;
} }
@@ -250,36 +233,6 @@ class Access {
return $this->ci->user->profile($this->ci->session->userdata('username')); return $this->ci->user->profile($this->ci->session->userdata('username'));
} }
/**
* Updates a specified user.
*
* @return boolean
*/
public function updateUser($id, $data) {
if ($this->ci->user->update($id, $data)) {
$this->setMessage('update_successful');
return true;
}
$this->setError('update_unsuccessful');
return false;
}
/**
* Deletes a specified user.
*
* @return boolean
*/
public function deleteUser($id) {
if ($this->ci->user->delete($id)) {
$this->setMessage('delete_successful');
return true;
}
$this->setError('delete_unsuccessful');
return false;
}
/** /**
* Sets a message. * Sets a message.
* *
@@ -298,7 +251,7 @@ class Access {
public function messages() { public function messages() {
$output = ''; $output = '';
foreach ($this->messages as $message) { foreach ($this->messages as $message) {
$output .= lang($message) . '<br />'; $output .= $message . '<br />';
} }
return $output; return $output;
@@ -322,7 +275,7 @@ class Access {
public function errors() { public function errors() {
$output = ''; $output = '';
foreach ($this->errors as $error) { foreach ($this->errors as $error) {
$output .= lang($error) . '<br />'; $output .= $error . '<br />';
} }
return $output; return $output;

View File

@@ -225,7 +225,6 @@ class User extends CI_Model {
$this->access->setError('account_creation_duplicate_username'); $this->access->setError('account_creation_duplicate_username');
return false; return false;
} }
print_r($additionalData);
// if a groupID was passed, use it // if a groupID was passed, use it
if (isset($additionalData['group_id'])) { if (isset($additionalData['group_id'])) {

View File

@@ -3,76 +3,76 @@
<div id="content"> <div id="content">
<div class="title"> <div class="title">
<h2><?=lang('create_user');?></h2> <h2><?=_('Create new user');?></h2>
</div> </div>
<div class="box"> <div class="box">
<form name="createUser" method="post" action="<?=site_url('users/create')?>"> <form name="createUser" method="post" action="<?=site_url('users/create')?>">
<h3>Required information</h3> <h3><?=_('Required information');?></h3>
<ul> <ul>
<li> <li>
<?=form_label(lang('field_username'), 'username');?> <?=form_label(_('Username'), 'username');?>
<div> <div>
<input type="text" name="username" id="username" class="short text" value="<?=set_value('username');?>" /> <input type="text" name="username" id="username" class="short text" value="<?=set_value('username');?>" />
<?=form_error('username')?> <?=form_error('username')?>
</div> </div>
<label class="note">Must be between 4 and 20 characters long</label> <label class="note"><?=_('Must be between 4 and 20 characters long');?></label>
</li> </li>
<li> <li>
<?=form_label(lang('field_email'), 'email');?> <?=form_label(_('Email address'), 'email');?>
<div> <div>
<input type="text" name="email" id="email" class="medium text" value="<?=set_value('email');?>" /> <input type="text" name="email" id="email" class="medium text" value="<?=set_value('email');?>" />
<?=form_error('email')?> <?=form_error('email')?>
</div> </div>
</li> </li>
<li> <li>
<?=form_label(lang('field_password'), 'password');?> <?=form_label(_('Password'), 'password');?>
<div> <div>
<input type="password" name="password" id="password" class="short text" /> <input type="password" name="password" id="password" class="short text" />
<?=form_error('password')?> <?=form_error('password')?>
</div> </div>
</li> </li>
<li> <li>
<?=form_label(lang('field_password_confirm'), 'password_confirm');?> <?=form_label(_('Confirm password'), 'password_confirm');?>
<div> <div>
<input type="password" name="password_confirm" id="password_confirm" class="short text" /> <input type="password" name="password_confirm" id="password_confirm" class="short text" />
<?=form_error('password_confirm')?> <?=form_error('password_confirm')?>
</div> </div>
</li> </li>
<li> <li>
<?=form_label(lang('field_firstname'), 'firstname');?> <?=form_label(_('First name'), 'firstname');?>
<div> <div>
<input type="text" name="firstname" id="firstname" class="short text" value="<?=set_value('firstname');?>" /> <input type="text" name="firstname" id="firstname" class="short text" value="<?=set_value('firstname');?>" />
<?=form_error('firstname')?> <?=form_error('firstname')?>
</div> </div>
</li> </li>
<li> <li>
<?=form_label(lang('field_lastname'), 'lastname');?> <?=form_label(_('Last name'), 'lastname');?>
<div> <div>
<input type="text" name="lastname" id="lastname" class="short text" value="<?=set_value('lastname');?>" /> <input type="text" name="lastname" id="lastname" class="short text" value="<?=set_value('lastname');?>" />
<?=form_error('lastname')?> <?=form_error('lastname')?>
</div> </div>
</li> </li>
</ul> </ul>
<h3>Optional information</h3> <h3><?=_('Optional information');?></h3>
<ul> <ul>
<li> <li>
<?=form_label(lang('field_institution'), 'institution');?> <?=form_label(_('Institution'), 'institution');?>
<div> <div>
<input type="text" name="institution" id="institution" class="medium text" value="<?=set_value('institution');?>" /> <input type="text" name="institution" id="institution" class="medium text" value="<?=set_value('institution');?>" />
<?=form_error('institution')?> <?=form_error('institution')?>
</div> </div>
</li> </li>
<li> <li>
<?=form_label(lang('field_phone'), 'phone');?> <?=form_label(_('Phone number'), 'phone');?>
<div> <div>
<input type="text" name="phone" id="phone" class="short text" value="<?=set_value('phone');?>" /> <input type="text" name="phone" id="phone" class="short text" value="<?=set_value('phone');?>" />
<?=form_error('phone')?> <?=form_error('phone')?>
</div> </div>
<label class="note">Example: +49 123 456789</label> <label class="note"><?=('Example');?>: +49 123 456789</label>
</li> </li>
<li> <li>
<?=form_label("Language", 'language');?> <?=form_label(_('Language'), 'language');?>
<div> <div>
<?=form_dropdown('language', array('English'), null, 'id="language" class="drop"');?> <?=form_dropdown('language', array('English'), null, 'id="language" class="drop"');?>
<?=form_error('language')?> <?=form_error('language')?>
@@ -80,7 +80,7 @@
</li> </li>
</ul> </ul>
<p> <p>
<a class="button save" href="javascript:void(0);" onclick="$('form[name=createUser]').submit();">Speichern</a> <a class="button save" href="javascript:void(0);" onclick="$('form[name=createUser]').submit();"><?=_('Save');?></a>
</p> </p>
</form> </form>
</div> </div>

View File

@@ -3,54 +3,54 @@
<div id="content"> <div id="content">
<div class="title"> <div class="title">
<h2><?=lang('edit_user');?> '<?=$user['username'];?>'</h2> <h2><?php printf(_("Edit user '%s'"), $user['username']);?></h2>
</div> </div>
<div class="box"> <div class="box">
<form name="createUser" method="post" action="<?=site_url('users/edit/' . $user['id'])?>"> <form name="createUser" method="post" action="<?=site_url('users/edit/' . $user['id'])?>">
<h3>Required information</h3> <h3><?=_('Required information');?></h3>
<ul> <ul>
<li> <li>
<?=form_label(lang('field_email'), 'email');?> <?=form_label(_('Email address'), 'email');?>
<div> <div>
<input type="text" name="email" id="email" class="medium text" value="<?=set_value('email', $user['email']);?>" /> <input type="text" name="email" id="email" class="medium text" value="<?=set_value('email', $user['email']);?>" />
<?=form_error('email')?> <?=form_error('email')?>
</div> </div>
</li> </li>
<li> <li>
<?=form_label(lang('field_firstname'), 'firstname');?> <?=form_label(_('First name'), 'firstname');?>
<div> <div>
<input type="text" name="firstname" id="firstname" class="short text" value="<?=set_value('firstname', $user['firstname']);?>" /> <input type="text" name="firstname" id="firstname" class="short text" value="<?=set_value('firstname', $user['firstname']);?>" />
<?=form_error('firstname')?> <?=form_error('firstname')?>
</div> </div>
</li> </li>
<li> <li>
<?=form_label(lang('field_lastname'), 'lastname');?> <?=form_label(_('Last name'), 'lastname');?>
<div> <div>
<input type="text" name="lastname" id="lastname" class="short text" value="<?=set_value('lastname', $user['lastname']);?>" /> <input type="text" name="lastname" id="lastname" class="short text" value="<?=set_value('lastname', $user['lastname']);?>" />
<?=form_error('lastname')?> <?=form_error('lastname')?>
</div> </div>
</li> </li>
</ul> </ul>
<h3>Optional information</h3> <h3><?=_('Optional information');?></h3>
<ul> <ul>
<li> <li>
<?=form_label(lang('field_institution'), 'institution');?> <?=form_label(_('Institution'), 'institution');?>
<div> <div>
<input type="text" name="institution" id="institution" class="medium text" value="<?=set_value('institution', $user['institution']);?>" /> <input type="text" name="institution" id="institution" class="medium text" value="<?=set_value('institution', $user['institution']);?>" />
<?=form_error('institution')?> <?=form_error('institution')?>
</div> </div>
</li> </li>
<li> <li>
<?=form_label(lang('field_phone'), 'phone');?> <?=form_label(_('Phone number'), 'phone');?>
<div> <div>
<input type="text" name="phone" id="phone" class="short text" value="<?=set_value('phone', $user['phone']);?>" /> <input type="text" name="phone" id="phone" class="short text" value="<?=set_value('phone', $user['phone']);?>" />
<?=form_error('phone')?> <?=form_error('phone')?>
</div> </div>
<label class="note">Example: +49 123 456789</label> <label class="note"><?=_('Example');?>: +49 123 456789</label>
</li> </li>
<li> <li>
<?=form_label("Language", 'language');?> <?=form_label(_('Language'), 'language');?>
<div> <div>
<?=form_dropdown('language', array('English'), null, 'id="language" class="drop"');?> <?=form_dropdown('language', array('English'), null, 'id="language" class="drop"');?>
<?=form_error('language')?> <?=form_error('language')?>
@@ -58,7 +58,8 @@
</li> </li>
</ul> </ul>
<p> <p>
<a class="button save" href="javascript:void(0);" onclick="$('form[name=createUser]').submit();">Speichern</a> <a class="button save" href="javascript:void(0);" onclick="$('form[name=createUser]').submit();"><?=_('Save');?></a>
<a class="button cancel" href="<?=site_url('users');?>"><?=_('Cancel');?></a>
</p> </p>
</form> </form>
</div> </div>

View File

@@ -3,17 +3,17 @@
<div id="content"> <div id="content">
<div class="title"> <div class="title">
<h2><?=_('users');?></h2> <h2><?=_('Users');?></h2>
</div> </div>
<div class="box"> <div class="box">
<h3><?=lang('available_users');?></h3> <h3><?=_('Available users');?></h3>
<table class="tableList paginated"> <table class="tableList paginated">
<thead> <thead>
<tr> <tr>
<th scope="col"><?=lang('username');?></th> <th scope="col"><?=_('Username');?></th>
<th scope="col"><?=lang('realname');?></th> <th scope="col"><?=_('Full name');?></th>
<th scope="col"><?=lang('options');?></th> <th scope="col"><?=_('Actions');?></th>
</tr> </tr>
</thead> </thead>
<?php <?php
@@ -22,7 +22,7 @@
<tr> <tr>
<td><?=$user['username'];?></td> <td><?=$user['username'];?></td>
<td><?=$user['firstname'];?> <?=$user['lastname'];?></td> <td><?=$user['firstname'];?> <?=$user['lastname'];?></td>
<td><?=anchor('users/edit/' . $user['id'], lang('user_edit'));?> | <a href="javascript:deleteConfirm('<?=site_url('users/delete/' . $user['id']);?>');"><?=lang('user_delete');?></a></td> <td><?=anchor('users/edit/' . $user['id'], _('Edit'));?> | <a href="javascript:deleteConfirm('<?=site_url('users/delete/' . $user['id']);?>');"><?=_('Delete');?></a></td>
</tr> </tr>
<?php <?php
endforeach; endforeach;
@@ -31,7 +31,7 @@
</tbody> </tbody>
</table> </table>
<p><a class="button add" href="<?=site_url('users/create')?>"><?=lang('user_create');?></a> <p><a class="button add" href="<?=site_url('users/create')?>"><?=_('Create new user')?></a>
</div> </div>
</div> </div>