language.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Definition of language-related functions for cases where th user isn't
  5. * logged in yet
  6. * @package chamilo.custompages
  7. */
  8. // Get helper functions
  9. require_once __DIR__.'/language.inc.php';
  10. // Define the languages you want to make available for auto-detection here
  11. $available_langs = array('en', 'fr', 'es', 'gl', 'eu');
  12. // Define the translation of these language codes to Chamilo languages
  13. $chamilo_langs = array(
  14. null => 'english',
  15. 'en' => 'english',
  16. 'fr' => 'french',
  17. 'nl' => 'dutch',
  18. 'de' => 'german',
  19. 'es' => 'spanish',
  20. 'gl' => 'galician',
  21. 'eu' => 'basque'
  22. );
  23. $lang_match = $chamilo_langs[get_preferred_language($available_langs)];
  24. // recover previous value ...
  25. if (isset($_SESSION['user_language_choice'])) {
  26. $lang_match = $_SESSION['user_language_choice'];
  27. }
  28. // Chamilo parameter, on logout
  29. if (isset($_REQUEST['language']) && !empty($_REQUEST['language']) && in_array($_REQUEST['language'], $chamilo_langs)) {
  30. $lang_match = $_REQUEST['language'];
  31. }
  32. // Incoming link parameter
  33. if (isset($_REQUEST['lang']) && !empty($_REQUEST['lang']) && in_array($_REQUEST['lang'], $available_langs)) {
  34. $lang_match = $chamilo_langs[$_REQUEST['lang']];
  35. }
  36. $detect = api_get_setting('auto_detect_language_custom_pages');
  37. if ($detect === 'true') {
  38. // Auto detect
  39. $_user['language'] = $lang_match;
  40. $_SESSION['user_language_choice'] = $lang_match;
  41. } else {
  42. // Chamilo default platform.
  43. $defaultLanguage = api_get_interface_language();
  44. $_user['language'] = $defaultLanguage;
  45. $_SESSION['user_language_choice'] = $defaultLanguage;
  46. }