BxDolInstallLang.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php defined('BX_DOL_INSTALL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaInstall UNA 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 getLang()
  47. {
  48. return $this->_sLang;
  49. }
  50. public function getAvailableLanguages ()
  51. {
  52. $aRet = array();
  53. $aModules = $this->_oModulesTools->getModules('language');
  54. foreach ($aModules as $aModuleConfig) {
  55. $sStudioTitle = $aModuleConfig['title'];
  56. $sTitle = $sStudioTitle;
  57. $aOwnStrings = $this->_oModulesTools->readLanguage($aModuleConfig);
  58. if (!empty($aOwnStrings['__' . $sStudioTitle]))
  59. $sTitle = $aOwnStrings['__' . $sStudioTitle];
  60. $aRet[$aModuleConfig['home_uri']] = array(
  61. 'code' => $aModuleConfig['home_uri'],
  62. 'title' => $sTitle,
  63. 'icon' => BX_INSTALL_URL_MODULES . $aModuleConfig['home_dir'] . 'template/images/icons/' . (file_exists(BX_INSTALL_DIR_MODULES . $aModuleConfig['home_dir'] . 'template/images/icons/std-pi.png') ? 'std-pi.png' : 'std-icon.svg'),
  64. );
  65. }
  66. return $aRet;
  67. }
  68. }
  69. if (!function_exists('_t')) {
  70. $sLang = 'en';
  71. if (isset($_GET['lang'])) {
  72. $sLang = $_GET['lang'];
  73. setcookie( 'lang', '', time() - 60*60*24);
  74. setcookie( 'lang', $sLang, time() + 60*60*24*365);
  75. } elseif (isset($_COOKIE['lang'])) {
  76. $sLang = $_COOKIE['lang'];
  77. }
  78. BxDolInstallLang::getInstance($sLang);
  79. function _t()
  80. {
  81. return call_user_func_array(array(BxDolInstallLang::getInstance(), '_t'), func_get_args());
  82. }
  83. }
  84. /** @} */