fix: fixed i18n string representation in Controllers

Fixed i18n string representation (flash and exception messages) in
controllers:
* OrganisationController
* RolesController
* TaxonomiesController
pull/4351/head
4ekin 2019-03-21 17:38:40 +03:00
parent 60ebb6ebe8
commit 0e8621f6ff
3 changed files with 52 additions and 52 deletions

View File

@ -25,7 +25,7 @@ class OrganisationsController extends AppController
public function index()
{
if (!$this->Auth->user('Role')['perm_sharing_group'] && Configure::read('Security.hide_organisation_index_from_users')) {
throw new MethodNotAllowedException('This feature is disabled on this instance for normal users.');
throw new MethodNotAllowedException(__('This feature is disabled on this instance for normal users.'));
}
$conditions = array();
// We can either index all of the organisations existing on this instance (default)
@ -130,14 +130,14 @@ class OrganisationsController extends AppController
));
return $this->RestResponse->viewData($org, $this->response->type());
} else {
$this->Flash->success('The organisation has been successfully added.');
$this->Flash->success(__('The organisation has been successfully added.'));
$this->redirect(array('admin' => false, 'action' => 'index'));
}
} else {
if ($this->_isRest()) {
return $this->RestResponse->saveFailResponse('Organisations', 'admin_add', false, $this->Organisation->validationErrors, $this->response->type());
} else {
$this->Flash->error('The organisation could not be added.');
$this->Flash->error(__('The organisation could not be added.'));
}
}
} else {
@ -152,7 +152,7 @@ class OrganisationsController extends AppController
{
$this->Organisation->id = $id;
if (!$this->Organisation->exists()) {
throw new NotFoundException('Invalid organisation');
throw new NotFoundException(__('Invalid organisation'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->_isRest()) {
@ -191,7 +191,7 @@ class OrganisationsController extends AppController
));
return $this->RestResponse->viewData($org, $this->response->type());
} else {
$this->Flash->success('Organisation updated.');
$this->Flash->success(__('Organisation updated.'));
$this->redirect(array('admin' => false, 'action' => 'view', $this->Organisation->id));
}
} else {
@ -206,7 +206,7 @@ class OrganisationsController extends AppController
));
$this->set('duplicate_org', $duplicate_org['Organisation']['id']);
}
$this->Flash->error('The organisation could not be updated.');
$this->Flash->error(__('The organisation could not be updated.'));
}
}
} else {
@ -227,11 +227,11 @@ class OrganisationsController extends AppController
public function admin_delete($id)
{
if (!$this->request->is('post')) {
throw new MethodNotAllowedException('Action not allowed, post request expected.');
throw new MethodNotAllowedException(__('Action not allowed, post request expected.'));
}
$this->Organisation->id = $id;
if (!$this->Organisation->exists()) {
throw new NotFoundException('Invalid organisation');
throw new NotFoundException(__('Invalid organisation'));
}
$org = $this->Organisation->find('first', array(
@ -272,19 +272,19 @@ class OrganisationsController extends AppController
if (Validation::uuid($id)) {
$temp = $this->Organisation->find('first', array('recursive' => -1, 'fields' => array('Organisation.id'), 'conditions' => array('Organisation.uuid' => $id)));
if (empty($temp)) {
throw new NotFoundException('Invalid organisation.');
throw new NotFoundException(__('Invalid organisation.'));
}
$id = $temp['Organisation']['id'];
} elseif (!is_numeric($id)) {
$temp = $this->Organisation->find('first', array('recursive' => -1, 'fields' => array('Organisation.id'), 'conditions' => array('Organisation.name' => urldecode($id))));
if (empty($temp)) {
throw new NotFoundException('Invalid organisation.');
throw new NotFoundException(__('Invalid organisation.'));
}
$id = $temp['Organisation']['id'];
}
$this->Organisation->id = $id;
if (!$this->Organisation->exists()) {
throw new NotFoundException('Invalid organisation');
throw new NotFoundException(__('Invalid organisation'));
}
$fullAccess = false;
$fields = array('id', 'name', 'date_created', 'date_modified', 'type', 'nationality', 'sector', 'contacts', 'description', 'local', 'uuid', 'restricted_to_domain');
@ -311,7 +311,7 @@ class OrganisationsController extends AppController
'conditions' => array('ShadowAttribute.org_id' => $org['Organisation']['id'])
));
if (empty($proposal)) {
throw new NotFoundException('Invalid organisation');
throw new NotFoundException(__('Invalid organisation'));
}
}
}
@ -344,12 +344,12 @@ class OrganisationsController extends AppController
{
$this->Organisation->id = $id;
if (!$this->Organisation->exists()) {
throw new NotFoundException('Invalid organisation');
throw new NotFoundException(__('Invalid organisation'));
}
$org = $this->Organisation->find('first', array('conditions' => array('id' => $id), 'fields' => array('landingpage', 'name')));
$landingpage = $org['Organisation']['landingpage'];
if (empty($landingpage)) {
$landingpage = "No landing page has been created for this organisation.";
$landingpage = __('No landing page has been created for this organisation.');
}
$this->set('landingPage', $landingpage);
$this->set('org', $org['Organisation']['name']);
@ -398,7 +398,7 @@ class OrganisationsController extends AppController
public function getUUIDs()
{
if (!$this->Auth->user('Role')['perm_sync']) {
throw new MethodNotAllowedException('This action is restricted to sync users');
throw new MethodNotAllowedException(__('This action is restricted to sync users'));
}
$temp = $this->Organisation->find('all', array(
'recursive' => -1,
@ -415,15 +415,15 @@ class OrganisationsController extends AppController
public function admin_merge($id, $target_id = false)
{
if (!$this->_isSiteAdmin()) {
throw new MethodNotAllowedException('You are not authorised to do that.');
throw new MethodNotAllowedException(__('You are not authorised to do that.'));
}
if ($this->request->is('Post')) {
$result = $this->Organisation->orgMerge($id, $this->request->data, $this->Auth->user());
if ($result) {
$this->Flash->success('The organisation has been successfully merged.');
$this->Flash->success(__('The organisation has been successfully merged.'));
$this->redirect(array('admin' => false, 'action' => 'view', $result));
} else {
$this->Flash->error('There was an error while merging the organisations. To find out more about what went wrong, refer to the audit logs. If you would like to revert the changes, you can find a .sql file ');
$this->Flash->error(__('There was an error while merging the organisations. To find out more about what went wrong, refer to the audit logs. If you would like to revert the changes, you can find a .sql file'));
}
$this->redirect(array('admin' => false, 'action' => 'index'));
} else {

View File

@ -56,7 +56,7 @@ class RolesController extends AppController
));
return $this->RestResponse->viewData($role, $this->response->type());
} else {
$this->Flash->success('The Role has been saved');
$this->Flash->success(__('The Role has been saved'));
$this->redirect(array('action' => 'index'));
}
} else {
@ -82,7 +82,7 @@ class RolesController extends AppController
}
$this->Role->id = $id;
if (!$this->Role->exists() && !$this->request->is('get')) {
throw new NotFoundException('Invalid Role');
throw new NotFoundException(__('Invalid Role'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if (!isset($this->request->data['Role'])) {
@ -97,7 +97,7 @@ class RolesController extends AppController
));
return $this->RestResponse->viewData($role, $this->response->type());
} else {
$this->Flash->success('The Role has been saved');
$this->Flash->success(__('The Role has been saved'));
$this->redirect(array('action' => 'index'));
}
} else {
@ -148,7 +148,7 @@ class RolesController extends AppController
}
$this->Role->id = $id;
if (!$this->Role->exists()) {
throw new NotFoundException('Invalid Role');
throw new NotFoundException(__('Invalid Role'));
}
if ($this->Role->delete()) {
if ($this->_isRest()) {
@ -161,7 +161,7 @@ class RolesController extends AppController
if ($this->_isRest()) {
return $this->RestResponse->saveFailResponse('Roles', 'admin_delete', $id, $this->Role->validationErrors, $this->response->type());
} else {
$this->Flash->error('Role could not be deleted');
$this->Flash->error(__('Role could not be deleted'));
$this->redirect(array('action' => 'index'));
}
}
@ -197,7 +197,7 @@ class RolesController extends AppController
$this->loadModel('AdminSetting');
$result = $this->AdminSetting->changeSetting('default_role', $role_id);
if ($result === true) {
$message = $role_id ? 'Default role set.' : 'Default role unset.';
$message = $role_id ? __('Default role set.') : __('Default role unset.');
if ($this->_isRest()) {
return $this->RestResponse->saveSuccessResponse('Roles', 'admin_set_default', $role_id, $this->response->type(), $message);
} else {

View File

@ -54,7 +54,7 @@ class TaxonomiesController extends AppController
$filter = isset($this->passedArgs['filter']) ? $this->passedArgs['filter'] : false;
$taxonomy = $this->Taxonomy->getTaxonomy($id, array('full' => true, 'filter' => $filter));
if (empty($taxonomy)) {
throw new NotFoundException('Taxonomy not found.');
throw new NotFoundException(__('Taxonomy not found.'));
}
$this->loadModel('EventTag');
$this->loadModel('AttributeTag');
@ -96,7 +96,7 @@ class TaxonomiesController extends AppController
public function enable($id)
{
if (!$this->_isSiteAdmin() || !$this->request->is('Post')) {
throw new MethodNotAllowedException('You don\'t have permission to do that.');
throw new MethodNotAllowedException(__('You don\'t have permission to do that.'));
}
$taxonomy = $this->Taxonomy->find('first', array(
'recursive' => -1,
@ -119,7 +119,7 @@ class TaxonomiesController extends AppController
if ($this->_isRest()) {
return $this->RestResponse->saveSuccessResponse('Taxonomy', 'enable', $id, $this->response->type());
} else {
$this->Flash->success('Taxonomy enabled.');
$this->Flash->success(__('Taxonomy enabled.'));
$this->redirect($this->referer());
}
}
@ -127,7 +127,7 @@ class TaxonomiesController extends AppController
public function disable($id)
{
if (!$this->_isSiteAdmin() || !$this->request->is('Post')) {
throw new MethodNotAllowedException('You don\'t have permission to do that.');
throw new MethodNotAllowedException(__('You don\'t have permission to do that.'));
}
$taxonomy = $this->Taxonomy->find('first', array(
'recursive' => -1,
@ -151,7 +151,7 @@ class TaxonomiesController extends AppController
if ($this->_isRest()) {
return $this->RestResponse->saveSuccessResponse('Taxonomy', 'disable', $id, $this->response->type());
} else {
$this->Flash->success('Taxonomy disabled.');
$this->Flash->success(__('Taxonomy disabled.'));
$this->redirect($this->referer());
}
}
@ -159,7 +159,7 @@ class TaxonomiesController extends AppController
public function update()
{
if (!$this->_isSiteAdmin()) {
throw new MethodNotAllowedException('You don\'t have permission to do that.');
throw new MethodNotAllowedException(__('You don\'t have permission to do that.'));
}
$result = $this->Taxonomy->update();
$this->Log = ClassRegistry::init('Log');
@ -219,15 +219,15 @@ class TaxonomiesController extends AppController
$message = '';
if ($successes == 0 && $fails == 0) {
$flashType = 'info';
$message = 'All taxonomy libraries are up to date already.';
$message = __('All taxonomy libraries are up to date already.');
} elseif ($successes == 0) {
$flashType = 'error';
$message = 'Could not update any of the taxonomy libraries';
$message = __('Could not update any of the taxonomy libraries');
} else {
$flashType = 'success';
$message = 'Successfully updated ' . $successes . ' taxonomy libraries.';
$message = __('Successfully updated ') . $successes . __(' taxonomy libraries.');
if ($fails != 0) {
$message .= ' However, could not update ' . $fails . ' taxonomy libraries.';
$message .= __(' However, could not update ') . $fails . __(' taxonomy libraries.');
}
}
if ($this->_isRest()) {
@ -241,7 +241,7 @@ class TaxonomiesController extends AppController
public function addTag($taxonomy_id = false)
{
if ((!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) || !$this->request->is('post')) {
throw new NotFoundException('You don\'t have permission to do that.');
throw new NotFoundException(__('You don\'t have permission to do that.'));
}
if ($taxonomy_id) {
$result = $this->Taxonomy->addTags($taxonomy_id);
@ -261,9 +261,9 @@ class TaxonomiesController extends AppController
$result = $this->Taxonomy->addTags($this->request->data['Tag']['taxonomy_id'], $this->request->data['Tag']['nameList']);
}
if ($result) {
$this->Flash->success('The tag(s) has been saved.');
$this->Flash->success(__('The tag(s) has been saved.'));
} else {
$this->Flash->error('The tag(s) could not be saved. Please, try again.');
$this->Flash->error(__('The tag(s) could not be saved. Please, try again.'));
}
$this->redirect($this->referer());
}
@ -271,7 +271,7 @@ class TaxonomiesController extends AppController
public function hideTag($taxonomy_id = false)
{
if ((!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) || !$this->request->is('post')) {
throw new NotFoundException('You don\'t have permission to do that.');
throw new NotFoundException(__('You don\'t have permission to do that.'));
}
if ($taxonomy_id) {
$result = $this->Taxonomy->hideTags($taxonomy_id);
@ -291,9 +291,9 @@ class TaxonomiesController extends AppController
$result = $this->Taxonomy->hideTags($this->request->data['Tag']['taxonomy_id'], $this->request->data['Tag']['nameList']);
}
if ($result) {
$this->Flash->success('The tag(s) has been saved.');
$this->Flash->success(__('The tag(s) has been saved.'));
} else {
$this->Flash->error('The tag(s) could not be saved. Please, try again.');
$this->Flash->error(__('The tag(s) could not be saved. Please, try again.'));
}
$this->redirect($this->referer());
}
@ -301,7 +301,7 @@ class TaxonomiesController extends AppController
public function unhideTag($taxonomy_id = false)
{
if ((!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) || !$this->request->is('post')) {
throw new NotFoundException('You don\'t have permission to do that.');
throw new NotFoundException(__('You don\'t have permission to do that.'));
}
if ($taxonomy_id) {
$result = $this->Taxonomy->unhideTags($taxonomy_id);
@ -321,9 +321,9 @@ class TaxonomiesController extends AppController
$result = $this->Taxonomy->unhideTags($this->request->data['Tag']['taxonomy_id'], $this->request->data['Tag']['nameList']);
}
if ($result) {
$this->Flash->success('The tag(s) has been saved.');
$this->Flash->success(__('The tag(s) has been saved.'));
} else {
$this->Flash->error('The tag(s) could not be saved. Please, try again.');
$this->Flash->error(__('The tag(s) could not be saved. Please, try again.'));
}
$this->redirect($this->referer());
}
@ -331,7 +331,7 @@ class TaxonomiesController extends AppController
public function disableTag($taxonomy_id = false)
{
if ((!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) || !$this->request->is('post')) {
throw new NotFoundException('You don\'t have permission to do that.');
throw new NotFoundException(__('You don\'t have permission to do that.'));
}
if ($taxonomy_id) {
$result = $this->Taxonomy->disableTags($taxonomy_id);
@ -351,9 +351,9 @@ class TaxonomiesController extends AppController
$result = $this->Taxonomy->disableTags($this->request->data['Tag']['taxonomy_id'], $this->request->data['Tag']['nameList']);
}
if ($result) {
$this->Flash->success('The tag(s) has been hidden.');
$this->Flash->success(__('The tag(s) has been hidden.'));
} else {
$this->Flash->error('The tag(s) could not be hidden. Please, try again.');
$this->Flash->error(__('The tag(s) could not be hidden. Please, try again.'));
}
$this->redirect($this->referer());
}
@ -361,7 +361,7 @@ class TaxonomiesController extends AppController
public function taxonomyMassConfirmation($id)
{
if (!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) {
throw new NotFoundException('You don\'t have permission to do that.');
throw new NotFoundException(__('You don\'t have permission to do that.'));
}
$this->set('id', $id);
$this->render('ajax/taxonomy_mass_confirmation');
@ -370,7 +370,7 @@ class TaxonomiesController extends AppController
public function taxonomyMassHide($id)
{
if (!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) {
throw new NotFoundException('You don\'t have permission to do that.');
throw new NotFoundException(__('You don\'t have permission to do that.'));
}
$this->set('id', $id);
$this->render('ajax/taxonomy_mass_hide');
@ -379,7 +379,7 @@ class TaxonomiesController extends AppController
public function taxonomyMassUnhide($id)
{
if (!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) {
throw new NotFoundException('You don\'t have permission to do that.');
throw new NotFoundException(__('You don\'t have permission to do that.'));
}
$this->set('id', $id);
$this->render('ajax/taxonomy_mass_unhide');
@ -390,10 +390,10 @@ class TaxonomiesController extends AppController
if ($this->request->is('post')) {
$result = $this->Taxonomy->delete($id, true);
if ($result) {
$this->Flash->success('Taxonomy successfuly deleted.');
$this->Flash->success(__('Taxonomy successfuly deleted.'));
$this->redirect(array('controller' => 'taxonomies', 'action' => 'index'));
} else {
$this->Flash->error('Taxonomy could not be deleted.');
$this->Flash->error(__('Taxonomy could not be deleted.'));
$this->redirect(array('controller' => 'taxonomies', 'action' => 'index'));
}
} else {
@ -401,7 +401,7 @@ class TaxonomiesController extends AppController
$this->set('id', $id);
$this->render('ajax/taxonomy_delete_confirmation');
} else {
throw new MethodNotAllowedException('This function can only be reached via AJAX.');
throw new MethodNotAllowedException(__('This function can only be reached via AJAX.'));
}
}
}