BxDolInstallLang.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php defined('BX_DOL_INSTALL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentInstall Trident Install
  7. * @{
  8. */
  9. class BxDolInstallLang
  10. {
  11. protected $_aLang;
  12. protected $_sLang;
  13. protected $_oModulesTools;
  14. public function __construct($sLang)
  15. {
  16. $this->_oModulesTools = new BxDolInstallModulesTools();
  17. if (!$sLang)
  18. $sLang = BX_INSTALL_DEFAULT_LANGUAGE;
  19. $aModules = $this->_oModulesTools->getModules('language');
  20. $aModuleConfig = $this->_oModulesTools->getModuleConfigByUri ($sLang, $aModules);
  21. if (!$aModuleConfig && BX_INSTALL_DEFAULT_LANGUAGE != $sLang) {
  22. $sLang = BX_INSTALL_DEFAULT_LANGUAGE;
  23. $aModuleConfig = $this->_oModulesTools->getModuleConfigByUri ($sLang, $aModules);
  24. }
  25. $this->_sLang = $sLang;
  26. $this->_aLang = $this->_oModulesTools->readLanguage($aModuleConfig);
  27. }
  28. static function getInstance($sLang = '')
  29. {
  30. if (!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  31. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolInstallLang($sLang);
  32. return $GLOBALS['bxDolClasses'][__CLASS__];
  33. }
  34. public function _t ($sKey)
  35. {
  36. $sKey = func_get_arg(0);
  37. if (isset($this->_aLang[$sKey])) {
  38. $s = $this->_aLang[$sKey];
  39. if (($iNumArgs = func_num_args()) > 1)
  40. for ($i = 1; $i < $iNumArgs; $i++)
  41. $s = str_replace('{' . ($i - 1) . '}', func_get_arg($i), $s);
  42. return $s;
  43. }
  44. return $sKey;
  45. }
  46. public function getAvailableLanguages ()
  47. {
  48. $aRet = array();
  49. $aModules = $this->_oModulesTools->getModules('language');
  50. foreach ($aModules as $aModuleConfig)
  51. $aRet[$aModuleConfig['home_uri']] = array(
  52. 'code' => $aModuleConfig['home_uri'],
  53. 'title' => $aModuleConfig['title'],
  54. 'icon' => BX_INSTALL_URL_MODULES . $aModuleConfig['home_dir'] . 'template/images/icons/std-pi.png',
  55. );
  56. return $aRet;
  57. }
  58. }
  59. if (!function_exists('_t')) {
  60. $sLang = 'en';
  61. if (isset($_GET['lang'])) {
  62. $sLang = $_GET['lang'];
  63. setcookie( 'lang', '', time() - 60*60*24);
  64. setcookie( 'lang', $sLang, time() + 60*60*24*365);
  65. } elseif (isset($_COOKIE['lang'])) {
  66. $sLang = $_COOKIE['lang'];
  67. }
  68. BxDolInstallLang::getInstance($sLang);
  69. function _t()
  70. {
  71. return call_user_func_array(array(BxDolInstallLang::getInstance(), '_t'), func_get_args());
  72. }
  73. }
  74. /** @} */