Browse Source

设置默认语言

visuddhinanda 2 years ago
parent
commit
99f0051475
1 changed files with 22 additions and 12 deletions
  1. 22 12
      app/Http/Api/TemplateRender.php

+ 22 - 12
app/Http/Api/TemplateRender.php

@@ -35,7 +35,7 @@ class TemplateRender{
      * string $format  'react' | 'text' | 'tex' | 'unity'
      * @return void
      */
-    public function __construct($param, $channelInfo, $mode,$format='react',$studioId,$debug=[])
+    public function __construct($param, $channelInfo, $mode,$format='react',$studioId,$debug=[],$lang='zh-Hans')
     {
         $this->param = $param;
         foreach ($channelInfo as $value) {
@@ -51,12 +51,12 @@ class TemplateRender{
             $channelId = $this->channel_id[0];
             if(Str::isUuid($channelId)){
                 $lang = Channel::where('uid',$channelId)->value('lang');
-                if(!empty($lang)){
-                    $this->lang = $lang;
-                    $this->langFamily = explode('-',$lang)[0];
-                }
             }
         }
+        if(!empty($lang)){
+            $this->lang = $lang;
+            $this->langFamily = explode('-',$lang)[0];
+        }
     }
     /**
      * TODO 设置默认语言。在渲染某些内容的时候需要语言信息
@@ -139,14 +139,24 @@ class TemplateRender{
         }
 
         if(count($this->channelInfo)===0){
-            Log::error('channel is null');
-            $output = [
-                "word" => $word,
-                'innerHtml' => '',
-            ];
-            return $output;
+            if(!empty($channel)){
+                $channelInfo = Channel::where('uid',$channel)->first();
+                if(!$channelInfo){
+                    unset($channelInfo);
+                }
+            }
+            if(!isset($channelInfo)){
+                Log::error('channel is null');
+                $output = [
+                    "word" => $word,
+                    'innerHtml' => '',
+                ];
+                return $output;
+            }
+        }else{
+            $channelInfo = $this->channelInfo[0];
         }
-        $channelInfo = $this->channelInfo[0];
+
         if(Str::isUuid($channelId)){
             $lang = Channel::where('uid',$channelId)->value('lang');
             if(!empty($lang)){