language.php 1.6 KB

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