lang.php 3.5 KB

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