lang.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) Copyright (C) 2008 - 2013 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. $lang_modules = array();
  25. function add_lang_module($lang_module)
  26. {
  27. global $lang_modules;
  28. array_push($lang_modules,$lang_module);
  29. // Need to reload langs if module is added after the first ogpLang call.
  30. ogpLang();
  31. }
  32. function ogpLang()
  33. {
  34. global $lang_modules;
  35. $locale_files = makefilelist("lang/", ".|..|.svn", true, "folders");
  36. if( isset($_REQUEST['lang']) and !in_array($_REQUEST['lang'],$locale_files) )
  37. unset($_REQUEST['lang'], $_GET['lang'], $_POST['lang']);
  38. // For debugging purposes we allow lang change from url.
  39. if ( isset($_REQUEST['lang']) && is_dir("lang/".$_REQUEST['lang']) )
  40. define("LANG_DIR","lang/".$_REQUEST['lang']);
  41. // Check that the language exists
  42. else if ( !empty($_SESSION['users_lang']) && is_dir("lang/".$_SESSION['users_lang']) )
  43. define("LANG_DIR","lang/".$_SESSION['users_lang']);
  44. // ... if lang does not exist lets use english.
  45. else if ( isset($GLOBALS['panel_language']) && is_dir("lang/".$GLOBALS['panel_language']) )
  46. define("LANG_DIR","lang/".$GLOBALS['panel_language']);
  47. else
  48. define("LANG_DIR","lang/English/");
  49. $files = glob(LANG_DIR."/*.php");
  50. // If we are inside some module also the modules language file
  51. // needs to be loaded.
  52. if ( isset( $_REQUEST['m'] ) )
  53. {
  54. if ( preg_match('[/|\\|;|\.]',$_REQUEST['m']) !== 0 )
  55. return;
  56. array_push($lang_modules,$_REQUEST['m']);
  57. }
  58. $modules = preg_grep("/.*/",get_included_files());
  59. foreach ($lang_modules as $lang_module)
  60. {
  61. $lang_file = LANG_DIR."/modules/".$lang_module.".php";
  62. if ( is_file($lang_file) )
  63. array_push($files,$lang_file);
  64. }
  65. foreach ($files as $file_name)
  66. {
  67. // Load the actual language files.
  68. include_once($file_name);
  69. }
  70. }
  71. function get_lang($lang_index)
  72. {
  73. if (defined($lang_index))
  74. {
  75. return constant($lang_index);
  76. }
  77. // Any other case is error.
  78. return "_".$lang_index."_";
  79. }
  80. function get_lang_f()
  81. {
  82. $args = func_get_args();
  83. $lang_index = array_shift($args);
  84. if (defined($lang_index))
  85. {
  86. return vsprintf(constant($lang_index),$args);
  87. }
  88. return "_".$lang_index."_".implode("_",$args)."_";
  89. }
  90. function print_lang($lang_index)
  91. {
  92. print get_lang($lang_index);
  93. }
  94. ?>