LangService.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/7/6
  8. * Time: 14:07
  9. */
  10. namespace app\common\services;
  11. use app\common\services\Utils;
  12. class LangService
  13. {
  14. public static function getCurrentLang()
  15. {
  16. $content = (new self())->getFileContent();
  17. return json_decode($content, true);
  18. }
  19. /**
  20. * 读取文件内容
  21. * @return bool|string
  22. */
  23. public function getFileContent()
  24. {
  25. $file_path = $this->getPath();
  26. $content = file_get_contents($file_path . '/language.json');
  27. if (strlen($content) < 1) {
  28. $content = $this->getDefault();
  29. }
  30. return $content;
  31. }
  32. /**
  33. * 获取文件目录
  34. * @return string
  35. */
  36. public function getPath()
  37. {
  38. if (config('app.framework') == 'platform') {
  39. $file_dir = base_path().'/addons/yun_shop/static';
  40. } else {
  41. $file_dir = base_path().'/static';
  42. }
  43. $path = $file_dir.'/locales/'.\YunShop::app()->uniacid;
  44. if (!is_dir($path)) {
  45. Utils::mkdirs($path);
  46. }
  47. return $path;
  48. }
  49. /**
  50. * 默认语言设置
  51. * @return bool|string
  52. */
  53. public function getDefault()
  54. {
  55. $file = base_path().'/static/language.json';
  56. return file_get_contents($file);
  57. }
  58. }