aaron-1015 3 år sedan
förälder
incheckning
01ccd08bda
2 ändrade filer med 174 tillägg och 5 borttagningar
  1. 162 0
      api/static/lan.js
  2. 12 5
      api/templates/index.html

+ 162 - 0
api/static/lan.js

@@ -0,0 +1,162 @@
+//設定cookie
+function setCookie(name,value)
+{
+    var Days = 30;
+    var exp = new Date();
+    exp.setTime(exp.getTime() + Days*24*60*60*1000);
+    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
+}
+
+//獲取cookie
+function getCookie(name)
+{
+    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
+    if(arr=document.cookie.match(reg))
+    return unescape(arr[2]);
+    else
+    return null;
+}
+
+var zh = {
+    "make_video" : "製作影片",
+    "make_slides" : "影片製作(投影片版本)",
+    "login" : "登入",
+    "user_profile": "會員資料",
+    "logout": "登出",
+    "en": "英文",
+    "zh": "中文",
+    "choose_character": "選擇人物",
+    "usage_intro": "使用說明",
+    "history": "歷史紀錄",
+    "preview_videos": "預覽影片",
+    "video_link":  "影片連結",
+    "video_title": "標題",
+    "p_choose_character": "請選擇人物",
+    "lines": "台詞",
+    "img_link": "影像連結",
+    "processing_progress": "處理進度",
+    "usage_intro": "使用說明",
+    "one_line_to_one_img": "1. 一句台詞請對應提供一個影像連結做為搭配",
+    "sup_img_profile": "2. 影像連結檔案格式支援:",
+    "submit_to_wait": "3. 點選“送出”之後需等待一段影片製作的時間,請您耐心等候,待製作完畢可於通知網址查看",
+    "add_eng": "加入英文:",
+    "submut": "送出"
+};
+
+var en = {
+    "make_video" : "Make Videos",
+    "make_slides" : "Make Videos By Slides",
+    "login" : "Login",
+    "user_profile": "User Profile",
+    "logout": "Logout",
+    "en": "English",
+    "zh": "Chinese",
+    "choose_character": "Choose Character",
+    "usage_intro": "Usage Introduction",
+    "history": "History",
+    "preview_videos": "Preview Videos",
+    "video_link":  "Video Link",
+    "video_title": "Video Title",
+    "p_choose_character": "Choose Character",
+    "lines": "Lines",
+    "img_link": "Image Link",
+    "processing_progress": "Processing Progress",
+    "usage_intro": "Usage Introduction",
+    "one_line_to_one_img": "1. Please Provide an Image Link Corresponding to a Line as a Collocation",
+    "sup_img_profile": "2. Support File Format:",
+    "submit_to_wait": "3. After Clicking Submit, You Will Need To Wait For A Period Of Time For The Production Of The Video. Please Wait Patiently. You Can Check It At The Notification URL When The Production Is Completed.",
+    "add_eng": "Allow English Lines:",
+    "submut": "Submit"
+};
+
+
+// 4. 轉換
+function changeLan(val) {
+    var val = val.value;
+    console.log(`val: ${val}`);
+    setCookie('lan', val);
+    $('[set-lan]').each(function(){
+        var me = $(this);
+        var a = me.attr('set-lan').split(':');
+        var p = a[0];   //文字放置位置
+        var m = a[1];   //文字標示
+        
+        //用虎選擇語言後保存在cookie中,這裡讀取cooikes的語言版本
+        var lan = getCookie('lan');
+        console.log(lan);
+    
+        //選取語言文字
+        switch(lan){
+            case 'zh':
+                var t = zh[m];  
+                console.log(t);
+                break;
+            case 'en':
+                var t = en[m];
+                console.log(t);
+                break;
+            default:
+                var t = zh[m];
+                console.log(t);
+        }
+    
+        //所選語言沒有就換
+        if(t==undefined) t = en[m];
+        if(t==undefined) t = zh[m];
+    
+        if(t==undefined) return true;   //都沒有就跳出
+    
+        //文字放置位置有(html,val等,可以自己添加)
+        switch(p){
+            case 'html':
+                me.html(t);
+                break;
+            case 'placeholder':
+                me.placeholder(t);
+                console.log("placeholder");
+                console.log(t);
+            case 'val':
+            case 'value':
+                me.val(t);
+                break;
+            default:
+                me.html(t);
+        }
+    
+    });
+}
+
+
+
+// js裡面的轉換
+function get_lan(m)
+{
+    //獲取文字
+    var lan = getCookie('lan');     //語言版本
+    //選取語言文字
+    switch(lan){
+        case 'zh':
+            var t = zh[m];
+            break;
+        case 'hk':
+            var t = hk[m];
+            break;
+        default:
+            var t = en[m];
+    }
+
+    //如果沒有找到就轉換其他語言
+    if(t==undefined) t = zh[m];
+    if(t==undefined) t = en[m];
+    if(t==undefined) t = hk[m];
+
+    if(t==undefined) t = m; //如果還是沒有就直接用標示
+
+    return t;
+}
+
+
+// 預設中文版
+var lan = getCookie('lan');
+console.log(`目前語言版本: ${lan}`);
+changeLan(lan);

+ 12 - 5
api/templates/index.html

@@ -40,22 +40,28 @@
             <div class="collapse navbar-collapse" id="navbarSupportedContent">
                 <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                     <li class="nav-item">
-                        <a class="nav-link active btn-gocreate text-white" aria-current="page" href="/make_video">製作影片</a>
+                        <a class="nav-link active btn-gocreate text-white" aria-current="page" href="/make_video" set-lan="html:make_video">製作影片</a>
                     </li>
                     <li class="nav-item">
-                        <a class="nav-link active btn-gocreate text-white" aria-current="page" href="/make_video_slide">SLIDE製作影片</a>
+                        <a class="nav-link active btn-gocreate text-white" aria-current="page" href="/make_video_slide" set-lan="html:make_slides">SLIDE製作影片</a>                        
                     </li>
                 </ul>
                 
                 <ul class="navbar-nav mb-2 mb-lg-0">
                     <li class="nav-item">
-                        <a class="nav-link active" aria-current="page" href="/login">Login</a>
+                        <button class="nav-link active" aria-current="page" set-lan="html:en" onclick="changeLan(this)" value="en">英文</button>
                     </li>
                     <li class="nav-item">
-                        <a class="nav-link" aria-current="page" href="/user_profile">User Profile</a>
+                        <button class="nav-link active" aria-current="page" set-lan="html:zh" onclick="changeLan(this)" value="zh">中文</button>
                     </li>
                     <li class="nav-item">
-                        <a class="nav-link" aria-current="page" href="/logout">Logout</a>
+                        <a class="nav-link active" aria-current="page" href="/login" set-lan="html:login">登入</a>
+                    </li>
+                    <li class="nav-item">
+                        <a class="nav-link" aria-current="page" href="/user_profile" set-lan="html:user_profile">會員資料</a>
+                    </li>
+                    <li class="nav-item">
+                        <a class="nav-link" aria-current="page" href="/logout" set-lan="html:logout">登出</a>
                     </li>
                 </ul>
             </div>
@@ -89,6 +95,7 @@
     <script src="static/owl.carousel.min.js"></script>
     <script src="static/script_util.js"></script>
     <script src="templates/script_index.js"></script>
+    <script type="text/javascript" src="static/lan.js"></script>
 </body>
 
 </html>