找回密码
 注册账号

QQ登录

只需一步,快速开始

《泰拉瑞亚下载-1.4.2.3版》 泰拉瑞亚服务器 - MOD模组下载

入驻泰拉战网 新手指引 - 升级 - 师徒

泰拉瑞亚合成表 泰拉卡牌 - 泰拉江湖 - 泰拉刺客

联系泰拉开发组👈进入 积分市场 - 房产交易 - 水晶获取

查看: 2495|回复: 0

Discuz lang 函数 加载语言包函数

[复制链接]

498

主题

18

回帖

5

广播

论坛版主

积分
257
泰拉
22
水晶
1
铜钥匙
0
银钥匙
0
金钥匙
0

【江湖新秀】【宝剑回鞘】【泰拉达人】【奥运选手】

发表于 2020-9-29 13:12:57 | 显示全部楼层 |阅读模式

  1. /**
  2. * 加载语言
  3. * 语言文件统一为 $lang = array();
  4. * @param $file - 语言文件,可包含路径如 forum/xxx home/xxx
  5. * @param $langvar - 语言文字索引
  6. * @param $vars - 变量替换数组
  7. * @return 语言文字
  8. */
复制代码


  1. function lang($file, $langvar = null, $vars = array(), $default = null) {
  2.         global $_G;
  3.         $fileinput = $file;
  4.         list($path, $file) = explode('/', $file);
  5.         if(!$file) {
  6.                 $file = $path;
  7.                 $path = '';
  8.         }
  9.         if(strpos($file, ':') !== false) {
  10.                 $path = 'plugin';
  11.                 list($file) = explode(':', $file);
  12.         }

  13.         if($path != 'plugin') {
  14.                 $key = $path == '' ? $file : $path.'_'.$file;
  15.                 if(!isset($_G['lang'][$key])) {
  16.                         include DISCUZ_ROOT.'./source/language/'.($path == '' ? '' : $path.'/').'lang_'.$file.'.php';
  17.                         $_G['lang'][$key] = $lang;
  18.                 }
  19.                 if(defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
  20.                         include DISCUZ_ROOT.'./source/language/mobile/lang_template.php';
  21.                         $_G['lang'][$key] = array_merge($_G['lang'][$key], $lang);
  22.                 }
  23.                 if($file != 'error' && !isset($_G['cache']['pluginlanguage_system'])) {
  24.                         loadcache('pluginlanguage_system');
  25.                 }
  26.                 if(!isset($_G['hooklang'][$fileinput])) {
  27.                         if(isset($_G['cache']['pluginlanguage_system'][$fileinput]) && is_array($_G['cache']['pluginlanguage_system'][$fileinput])) {
  28.                                 $_G['lang'][$key] = array_merge($_G['lang'][$key], $_G['cache']['pluginlanguage_system'][$fileinput]);
  29.                         }
  30.                         $_G['hooklang'][$fileinput] = true;
  31.                 }
  32.                 $returnvalue = &$_G['lang'];
  33.         } else {
  34.                 if(empty($_G['config']['plugindeveloper'])) {
  35.                         loadcache('pluginlanguage_script');
  36.                 } elseif(!isset($_G['cache']['pluginlanguage_script'][$file]) && preg_match("/^[a-z]+[a-z0-9_]*$/i", $file)) {
  37.                         if(@include(DISCUZ_ROOT.'./data/plugindata/'.$file.'.lang.php')) {
  38.                                 $_G['cache']['pluginlanguage_script'][$file] = $scriptlang[$file];
  39.                         } else {
  40.                                 loadcache('pluginlanguage_script');
  41.                         }
  42.                 }
  43.                 $returnvalue = & $_G['cache']['pluginlanguage_script'];
  44.                 $key = &$file;
  45.         }
  46.         $return = $langvar !== null ? (isset($returnvalue[$key][$langvar]) ? $returnvalue[$key][$langvar] : null) : $returnvalue[$key];
  47.         $return = $return === null ? ($default !== null ? $default : $langvar) : $return;
  48.         $searchs = $replaces = array();
  49.         if($vars && is_array($vars)) {
  50.                 foreach($vars as $k => $v) {
  51.                         $searchs[] = '{'.$k.'}';
  52.                         $replaces[] = $v;
  53.                 }
  54.         }
  55.         if(is_string($return) && strpos($return, '{_G/') !== false) {
  56.                 preg_match_all('/\{_G\/(.+?)\}/', $return, $gvar);
  57.                 foreach($gvar[0] as $k => $v) {
  58.                         $searchs[] = $v;
  59.                         $replaces[] = getglobal($gvar[1][$k]);
  60.                 }
  61.         }
  62.         $return = str_replace($searchs, $replaces, $return);
  63.         return $return;
  64. }
复制代码
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

QQ|友链申请|Archiver|手机版|小黑屋|游芯沙盒 ( 陕ICP备11006283号-1 )

GMT+8, 2024-5-3 08:05 , Processed in 0.114844 second(s), 35 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表