Lang.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace core\dict;
  12. class Lang extends BaseDict
  13. {
  14. /**
  15. * 加载事件
  16. * @param array $data //传入语言类型
  17. * @return array|mixed
  18. */
  19. public function load(array $data)
  20. {
  21. $addons = $this->getLocalAddons();
  22. $system_lang_path = $this->getAppPath() . "lang" . DIRECTORY_SEPARATOR . $data['lang_type'] . DIRECTORY_SEPARATOR;
  23. $lang_files = [
  24. $system_lang_path . "api.php",
  25. $system_lang_path . "dict.php",
  26. $system_lang_path . "validate.php",
  27. ];
  28. foreach ($addons as $v) {
  29. $lang_path = $this->getAddonAppPath($v) . "lang" . DIRECTORY_SEPARATOR . $data['lang_type'] . DIRECTORY_SEPARATOR;
  30. $api_path = $lang_path . "api.php";
  31. $dict_path = $lang_path . "dict.php";
  32. $validate_path = $lang_path . "validate.php";
  33. if (is_file($api_path)) {
  34. $lang_files[] = $api_path;
  35. }
  36. if (is_file($dict_path)) {
  37. $lang_files[] = $dict_path;
  38. }
  39. if (is_file($validate_path)) {
  40. $lang_files[] = $validate_path;
  41. }
  42. }
  43. $files_data = $this->loadFiles($lang_files);
  44. $lang = [];
  45. foreach ($files_data as $file_data) {
  46. $lang = empty($lang) ? $file_data : array_merge2($lang, $file_data);
  47. }
  48. return $lang;
  49. }
  50. }