From 3b60a4745208e3b7ca69384e6f3b7d58b6d5cc64 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 12 Mar 2013 14:15:55 +0100 Subject: [PATCH] Fixing index.php lang error --- main/inc/global.inc.php | 8 ++++--- main/inc/lib/internationalization.lib.php | 16 +++++++++---- src/ChamiloLMS/Controller/Controller.php | 24 +++++++++++++++++++ src/ChamiloLMS/Controller/IndexController.php | 6 +++-- 4 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 src/ChamiloLMS/Controller/Controller.php diff --git a/main/inc/global.inc.php b/main/inc/global.inc.php index 54c50f0618..4f2d22623f 100755 --- a/main/inc/global.inc.php +++ b/main/inc/global.inc.php @@ -121,6 +121,7 @@ use Symfony\Component\HttpFoundation\Response; $app = new Application(); $app['configuration_file'] = $main_configuration_file_path; $app['configuration'] = $_configuration; +$app['languages_file'] = array(); //require_once __DIR__.'/../../resources/config/prod.php'; require_once __DIR__.'/../../resources/config/dev.php'; @@ -641,6 +642,8 @@ if ($already_installed) { $app['language_interface'] = $language_interface = 'english'; } + + // Sometimes the variable $language_interface is changed // temporarily for achieving translation in different language. // We need to save the genuine value of this variable and @@ -727,6 +730,7 @@ $language_files = array(); $language_files[] = 'trad4all'; $language_files[] = 'notification'; $language_files[] = 'accessibility'; +$language_files[] = 'index'; if (isset($language_file)) { if (!is_array($language_file)) { @@ -737,7 +741,7 @@ if (isset($language_file)) { } if (isset($app['languages_file'])) { - $language_files = array_merge($language_files, $this->app['languages_file']); + $language_files = array_merge($language_files, $app['languages_file']); } // if a set of language files has been properly defined @@ -836,9 +840,7 @@ if (api_get_setting('server_type') == 'test') { $app->before( function () use ($app) { if (!file_exists($app['configuration_file'])) { - return new RedirectResponse(api_get_path(WEB_CODE_PATH).'install'); - $app->abort(500, "Incorrect PHP version"); } diff --git a/main/inc/lib/internationalization.lib.php b/main/inc/lib/internationalization.lib.php index ba9b8251cf..ba000f9634 100644 --- a/main/inc/lib/internationalization.lib.php +++ b/main/inc/lib/internationalization.lib.php @@ -140,6 +140,10 @@ function get_lang($variable, $reserved = null, $language = null) } return $translated;*/ $language_interface = api_get_language_interface(); + /*$helo = false; + if ($variable == 'LostPassword') { + $helo = true; + }*/ global // For serving some old hacks: // By manipulating this global variable the translation may be done in different languages too (not the elegant way). @@ -167,8 +171,8 @@ function get_lang($variable, $reserved = null, $language = null) $encoding = api_get_system_encoding(); $is_utf8_encoding = api_is_utf8($encoding); $langpath = api_get_path(SYS_LANG_PATH); - //$test_server_mode = api_get_setting('server_type') == 'test'; - $test_server_mode = false; + $test_server_mode = api_get_setting('server_type') == 'test'; + //$test_server_mode = false; $show_special_markup = api_get_setting('hide_dltt_markup') != 'true' || $test_server_mode; $initialized = true; } @@ -177,6 +181,7 @@ function get_lang($variable, $reserved = null, $language = null) if (empty($language)) { $language = $language_interface; } + $lang_postfix = isset($is_interface_language) && $is_interface_language ? '' : '('.$language.')'; $is_interface_language = $language == $language_interface_initial_value; @@ -193,6 +198,7 @@ function get_lang($variable, $reserved = null, $language = null) return $ret; } + $_api_is_translated = false; // There is no cached translation, we have to retrieve it: @@ -204,7 +210,6 @@ function get_lang($variable, $reserved = null, $language = null) if (!$read_global_variables) { global $language_files; - //var_dump($language_files);exit; if (isset($language_files)) { $parent_language = null; if (api_get_setting('allow_use_sub_language') == 'true') { @@ -227,8 +232,8 @@ function get_lang($variable, $reserved = null, $language = null) } } - // Translation mode for production servers. + if (!$test_server_mode) { if ($read_global_variables) { if (isset($GLOBALS[$variable])) { @@ -261,6 +266,7 @@ function get_lang($variable, $reserved = null, $language = null) return $ret; } + // Translation mode for test/development servers. if (!is_string($variable)) { //return $cache[$language][$variable] = SPECIAL_OPENING_TAG.'get_lang(?)'.SPECIAL_CLOSING_TAG; @@ -268,6 +274,8 @@ function get_lang($variable, $reserved = null, $language = null) $used_lang_vars[$variable.$lang_postfix] = $ret; return $ret; } + + if (isset($$variable)) { $langvar = $$variable; $_api_is_translated = true; diff --git a/src/ChamiloLMS/Controller/Controller.php b/src/ChamiloLMS/Controller/Controller.php new file mode 100644 index 0000000000..683ef12279 --- /dev/null +++ b/src/ChamiloLMS/Controller/Controller.php @@ -0,0 +1,24 @@ +language_files)) { + $language_interface = api_get_language_interface(); + $langPath = api_get_path(SYS_LANG_PATH); + + $language_files = $this->language_files; + foreach ($language_files as $index => $language_file) { + // include English + include $langPath.'english/'.$language_file.'.inc.php'; + // prepare string for current language + $langFile = $langPath.$language_interface.'/'.$language_file.'.inc.php'; + if (file_exists($langFile)) { + include $langFile; + } + } + }*/ + } +} \ No newline at end of file diff --git a/src/ChamiloLMS/Controller/IndexController.php b/src/ChamiloLMS/Controller/IndexController.php index 8d17d8ea83..6c42573240 100644 --- a/src/ChamiloLMS/Controller/IndexController.php +++ b/src/ChamiloLMS/Controller/IndexController.php @@ -9,9 +9,10 @@ use Symfony\Component\HttpFoundation\Response; /** * */ -class IndexController +class IndexController// extends Controller { public $section; + public $language_files = array('courses', 'index', 'admin'); /** * Handles default Chamilo scripts handled by Display::display_header() and display_footer() @@ -217,7 +218,8 @@ class IndexController $loginForm = null; if (!$userId || api_is_anonymous($userId)) { - // Only display if the user isn't logged in. + // Only display if the user isn't logged in + $app['template']->assign('login_language_form', api_display_language_form(true)); $app['template']->assign('login_form', self::display_login_form($app));