diff --git a/src/application/config/autoload.php b/src/application/config/autoload.php index 521ab1c7..20541f46 100644 --- a/src/application/config/autoload.php +++ b/src/application/config/autoload.php @@ -96,7 +96,7 @@ $autoload['config'] = array(); | */ -$autoload['language'] = array('translations'); +$autoload['language'] = array(); /* diff --git a/src/application/config/config.php b/src/application/config/config.php index 33e50075..a68a8dad 100644 --- a/src/application/config/config.php +++ b/src/application/config/config.php @@ -86,7 +86,8 @@ $config['url_suffix'] = ''; | than english. | */ -$config['language'] = 'greek';//'english'; +$config['language'] = 'english'; // default language +$config['available_languages'] = array('english', 'german', 'greek'); /* |-------------------------------------------------------------------------- diff --git a/src/application/controllers/appointments.php b/src/application/controllers/appointments.php index 133fb6fb..564a96e7 100644 --- a/src/application/controllers/appointments.php +++ b/src/application/controllers/appointments.php @@ -1,6 +1,18 @@ load->library('session'); + // Set user's selected language. + if ($this->session->userdata('language')) { + $this->config->set_item('language', $this->session->userdata('language')); + $this->lang->load('translations', $this->session->userdata('language')); + } else { + $this->lang->load('translations', $this->config->item('language')); // default + } + } + /** * Default callback method of the application. * diff --git a/src/application/controllers/backend.php b/src/application/controllers/backend.php index 407bf919..038e82a3 100644 --- a/src/application/controllers/backend.php +++ b/src/application/controllers/backend.php @@ -4,6 +4,14 @@ class Backend extends CI_Controller { public function __construct() { parent::__construct(); $this->load->library('session'); + + // Set user's selected language. + if ($this->session->userdata('language')) { + $this->config->set_item('language', $this->session->userdata('language')); + $this->lang->load('translations', $this->session->userdata('language')); + } else { + $this->lang->load('translations', $this->config->item('language')); // default + } } /** diff --git a/src/application/controllers/backend_api.php b/src/application/controllers/backend_api.php index 05ec1807..2b73d9db 100644 --- a/src/application/controllers/backend_api.php +++ b/src/application/controllers/backend_api.php @@ -1038,6 +1038,40 @@ class Backend_api extends CI_Controller { )); } } + + /** + * [AJAX] Change system language for current user. + * + * The language setting is stored in session data and retrieved every time the user + * visits any of the system pages. + * + * @param string $_POST['language'] Selected language name. + */ + public function ajax_change_language() { + try { + // Check if language exists in the available languages. + $found = false; + foreach($this->config->item('available_languages') as $lang) { + if ($lang == $_POST['language']) { + $found = true; + break; + } + } + + if (!$found) + throw new Exception('Translations for the given language does not exist (' . $_POST['language'] . ').'); + + $this->session->set_userdata('language', $_POST['language']); + $this->config->set_item('language', $_POST['language']); + + echo json_encode(AJAX_SUCCESS); + + } catch(Exception $exc) { + echo json_encode(array( + 'exceptions' => array(exceptionToJavaScript($exc)) + )); + } + } } /* End of file backend_api.php */ diff --git a/src/application/controllers/errors.php b/src/application/controllers/errors.php index 8e429b40..7ead0770 100644 --- a/src/application/controllers/errors.php +++ b/src/application/controllers/errors.php @@ -1,6 +1,18 @@ load->library('session'); + // Set user's selected language. + if ($this->session->userdata('language')) { + $this->config->set_item('language', $this->session->userdata('language')); + $this->lang->load('translations', $this->session->userdata('language')); + } else { + $this->lang->load('translations', $this->config->item('language')); // default + } + } + public function index() { $this->e404(); } diff --git a/src/application/controllers/google.php b/src/application/controllers/google.php index 80e95639..8dc0f5a3 100644 --- a/src/application/controllers/google.php +++ b/src/application/controllers/google.php @@ -1,6 +1,10 @@ load->library('session'); + + // Set user's selected language. + if ($this->session->userdata('language')) { + $this->config->set_item('language', $this->session->userdata('language')); + $this->lang->load('translations', $this->session->userdata('language')); + } else { + $this->lang->load('translations', $this->config->item('language')); // default + } } public function index() { diff --git a/src/application/language/english/translations_lang.php b/src/application/language/english/translations_lang.php index 627915d3..45907558 100644 --- a/src/application/language/english/translations_lang.php +++ b/src/application/language/english/translations_lang.php @@ -143,7 +143,7 @@ $lang['secretary_deleted'] = 'Secretary deleted successfully!'; $lang['service_saved'] = 'Service saved successfully!'; $lang['service_category_saved'] = 'Service category saved successfully!'; $lang['service_deleted'] = 'Service deleted successfully!'; -$lang['servce_category_deleted'] = 'Service category deleted successfully!'; +$lang['service_category_deleted'] = 'Service category deleted successfully!'; $lang['customer_saved'] = 'Customer saved successfully!'; $lang['customer_deleted'] = 'Customer deleted successfully!'; $lang['current_view'] = 'Current View'; diff --git a/src/application/language/german/translations_lang.php b/src/application/language/german/translations_lang.php index 29113151..902fe637 100644 --- a/src/application/language/german/translations_lang.php +++ b/src/application/language/german/translations_lang.php @@ -143,7 +143,7 @@ $lang['secretary_deleted'] = 'Bearbeiter erfolgreich gelöscht!'; $lang['service_saved'] = 'Dienstleistung erfolgreich gesichert!'; $lang['service_category_saved'] = 'Dienstleistungskategorie erfolgreich gesichert!'; $lang['service_deleted'] = 'Dienstleistung erfolgreich gelöscht!'; -$lang['servce_category_deleted'] = 'Dienstleistungskategorie erfolgreicht gelöscht!'; +$lang['service_category_deleted'] = 'Dienstleistungskategorie erfolgreicht gelöscht!'; $lang['customer_saved'] = 'Kunde erfolgreich gesichert!'; $lang['customer_deleted'] = 'Kunde erfolgreich gelöscht!'; $lang['current_view'] = 'Laufende Ansicht'; diff --git a/src/application/language/greek/translations_lang.php b/src/application/language/greek/translations_lang.php index 62cc135a..159c7e99 100644 --- a/src/application/language/greek/translations_lang.php +++ b/src/application/language/greek/translations_lang.php @@ -143,7 +143,7 @@ $lang['secretary_deleted'] = 'Ο γραμματέας διαγράφηκε επ $lang['service_saved'] = 'Η υπηρεσία αποθηκεύτηκε επιτυχώς!'; $lang['service_category_saved'] = 'Η κατηγορία υπηρεσιών αποθηκεύτηκε επιτυχώς!'; $lang['service_deleted'] = 'Η υπηρεσία διαγράφηκε επιτυχώς!'; -$lang['servce_category_deleted'] = 'Η κατηγορία υπηρεσιών διαγράφηκε επιτυχώς!'; +$lang['service_category_deleted'] = 'Η κατηγορία υπηρεσιών διαγράφηκε επιτυχώς!'; $lang['customer_saved'] = 'Ο πελάτης αποθηκεύτηκε επιτυχώς!'; $lang['customer_deleted'] = 'Ο πελάτης διαγράφηκε επιτυχώς!'; $lang['current_view'] = 'Τρέχων Προβολή'; diff --git a/src/application/views/backend/calendar.php b/src/application/views/backend/calendar.php index 1bab70eb..4102b081 100644 --- a/src/application/views/backend/calendar.php +++ b/src/application/views/backend/calendar.php @@ -27,8 +27,6 @@ } }; - var EALang = lang->language); ?>; - $(document).ready(function() { BackendCalendar.initialize(true); }); diff --git a/src/application/views/backend/customers.php b/src/application/views/backend/customers.php index 214404dd..221c1622 100644 --- a/src/application/views/backend/customers.php +++ b/src/application/views/backend/customers.php @@ -18,8 +18,6 @@ } }; - var EALang = lang->language); ?> - $(document).ready(function() { BackendCustomers.initialize(true); }); diff --git a/src/application/views/backend/footer.php b/src/application/views/backend/footer.php index ae076553..030a32dd 100644 --- a/src/application/views/backend/footer.php +++ b/src/application/views/backend/footer.php @@ -12,7 +12,10 @@ } ?> | - lang->line('licensed_under'); ?> GPLv3 + lang->line('licensed_under'); ?> GPLv3 | + + config->item('language')); ?> +