lang.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 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. // Some modules do not follow the established pattern and therefore don't have the functions loaded :(
  26. if(file_exists('includes/functions.php'))
  27. require_once('includes/functions.php');
  28. if(file_exists('functions.php'))
  29. require_once('functions.php');
  30. function add_lang_module($lang_module)
  31. {
  32. global $lang_modules;
  33. array_push($lang_modules,$lang_module);
  34. // Need to reload langs if module is added after the first ogpLang call.
  35. ogpLang();
  36. }
  37. function ogpLang()
  38. {
  39. global $lang_modules;
  40. $locale_files = makefilelist("lang/", ".|..|.svn", true, "folders");
  41. if( isset($_REQUEST['lang']) and !in_array($_REQUEST['lang'],$locale_files) )
  42. unset($_REQUEST['lang'], $_GET['lang'], $_POST['lang']);
  43. // For debugging purposes we allow lang change from url.
  44. if ( isset($_REQUEST['lang']) && is_dir("lang/".$_REQUEST['lang']) )
  45. define("LANG_DIR","lang/".$_REQUEST['lang']);
  46. // Check that the language exists
  47. else if ( !empty($_SESSION['users_lang']) && is_dir("lang/".$_SESSION['users_lang']) )
  48. define("LANG_DIR","lang/".$_SESSION['users_lang']);
  49. // ... if lang does not exist lets use english.
  50. else if ( isset($GLOBALS['panel_language']) && is_dir("lang/".$GLOBALS['panel_language']) )
  51. define("LANG_DIR","lang/".$GLOBALS['panel_language']);
  52. else
  53. define("LANG_DIR","lang/English/");
  54. $files = glob(LANG_DIR."/*.php");
  55. // If we are inside some module also the modules language file
  56. // needs to be loaded.
  57. if ( isset( $_REQUEST['m'] ) )
  58. {
  59. if ( preg_match('[/|\\|;|\.]',$_REQUEST['m']) !== 0 )
  60. return;
  61. array_push($lang_modules,$_REQUEST['m']);
  62. }
  63. $modules = preg_grep("/.*/",get_included_files());
  64. foreach ($lang_modules as $lang_module)
  65. {
  66. $lang_file = LANG_DIR."/modules/".$lang_module.".php";
  67. if ( is_file($lang_file) )
  68. array_push($files,$lang_file);
  69. }
  70. foreach ($files as $file_name)
  71. {
  72. // Load the actual language files.
  73. include_once($file_name);
  74. }
  75. }
  76. function get_lang($lang_index)
  77. {
  78. global $OGPLangPre;
  79. if (defined($lang_index))
  80. {
  81. return constant($lang_index);
  82. }
  83. if(!startsWith($lang_index, $OGPLangPre)){
  84. $newLangIndex = $OGPLangPre . $lang_index;
  85. if (defined($newLangIndex))
  86. {
  87. return constant($newLangIndex);
  88. }
  89. }
  90. // Any other case is error.
  91. return "_".$lang_index."_";
  92. }
  93. function get_lang_f()
  94. {
  95. global $OGPLangPre;
  96. $args = func_get_args();
  97. $lang_index = array_shift($args);
  98. if (defined($lang_index))
  99. {
  100. return vsprintf(constant($lang_index),$args);
  101. }
  102. if(!startsWith($lang_index, $OGPLangPre)){
  103. $newLangIndex = $OGPLangPre . $lang_index;
  104. if (defined($newLangIndex))
  105. {
  106. return vsprintf(constant($newLangIndex),$args);
  107. }
  108. }
  109. return "_".$lang_index."_".implode("_",$args)."_";
  110. }
  111. function print_lang($lang_index)
  112. {
  113. print get_lang($lang_index);
  114. }
  115. ?>