lan.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //設定cookie
  2. function setCookie(name,value)
  3. {
  4. var Days = 30;
  5. var exp = new Date();
  6. exp.setTime(exp.getTime() + Days*24*60*60*1000);
  7. document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
  8. }
  9. //獲取cookie
  10. function getCookie(name)
  11. {
  12. var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
  13. if(arr=document.cookie.match(reg))
  14. return unescape(arr[2]);
  15. else
  16. return null;
  17. }
  18. var zh = {
  19. "make_video" : "製作影片",
  20. "make_slides" : "影片製作(投影片版本)",
  21. "login" : "登入",
  22. "user_profile": "會員資料",
  23. "logout": "登出",
  24. "en": "英文",
  25. "zh": "中文",
  26. "choose_character": "選擇人物",
  27. "usage_intro": "使用說明",
  28. "history": "歷史紀錄",
  29. "preview_videos": "預覽影片",
  30. "video_link": "影片連結",
  31. "video_title": "標題",
  32. "p_choose_character": "請選擇人物",
  33. "lines": "台詞",
  34. "img_link": "影像連結",
  35. "processing_progress": "處理進度",
  36. "usage_intro": "使用說明",
  37. "one_line_to_one_img": "1. 一句台詞請對應提供一個影像連結做為搭配",
  38. "sup_img_profile": "2. 影像連結檔案格式支援:",
  39. "submit_to_wait": "3. 點選“送出”之後需等待一段影片製作的時間,請您耐心等候,待製作完畢可於通知網址查看",
  40. "add_eng": "加入英文:",
  41. "submut": "送出",
  42. "privacy_term": "同意隱私政策及使用條款",
  43. "newHere": "還沒有帳號?",
  44. "goRegister": "註冊",
  45. "pricing" : "早鳥方案",
  46. "errorEmail": "請輸入正確E-mail",
  47. "errorPsd": "密碼至少為4個字元"
  48. };
  49. var en = {
  50. "make_video" : "Make Videos",
  51. "make_slides" : "Make Videos By Slides",
  52. "login" : "Login",
  53. "user_profile": "User Profile",
  54. "logout": "Logout",
  55. "en": "English",
  56. "zh": "Chinese",
  57. "choose_character": "Choose Character",
  58. "usage_intro": "Usage Introduction",
  59. "history": "History",
  60. "preview_videos": "Preview Videos",
  61. "video_link": "Video Link",
  62. "video_title": "Video Title",
  63. "p_choose_character": "Choose Character",
  64. "lines": "Lines",
  65. "img_link": "Image Link",
  66. "processing_progress": "Processing Progress",
  67. "usage_intro": "Usage Introduction",
  68. "one_line_to_one_img": "1. Please Provide an Image Link Corresponding to a Line as a Collocation",
  69. "sup_img_profile": "2. Support File Format:",
  70. "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.",
  71. "add_eng": "Allow English Lines:",
  72. "submut": "Submit",
  73. "privacy_term": "I Agree to privacy policy and terms of use.",
  74. "newHere": "New here?",
  75. "goRegister": "REGISTER",
  76. "pricing" : "Pricing",
  77. "errorEmail": "Please enter valid Email format.",
  78. "errorPsd": "Passwords must be at least 4 characters long."
  79. };
  80. // 4. 轉換
  81. function changeLan(val) {
  82. var val = val.value;
  83. console.log(`val: ${val}`);
  84. setCookie('lan', val);
  85. $('[set-lan]').each(function(){
  86. var me = $(this);
  87. var a = me.attr('set-lan').split(':');
  88. var p = a[0]; //文字放置位置
  89. var m = a[1]; //文字標示
  90. //用虎選擇語言後保存在cookie中,這裡讀取cooikes的語言版本
  91. var lan = getCookie('lan');
  92. console.log(lan);
  93. //選取語言文字
  94. switch(lan){
  95. case 'zh':
  96. var t = zh[m];
  97. console.log(t);
  98. break;
  99. case 'en':
  100. var t = en[m];
  101. console.log(t);
  102. break;
  103. default:
  104. var t = zh[m];
  105. console.log(t);
  106. }
  107. //所選語言沒有就換
  108. if(t==undefined) t = en[m];
  109. if(t==undefined) t = zh[m];
  110. if(t==undefined) return true; //都沒有就跳出
  111. //文字放置位置有(html,val等,可以自己添加)
  112. switch(p){
  113. case 'html':
  114. me.html(t);
  115. break;
  116. case 'placeholder':
  117. me.placeholder(t);
  118. console.log("placeholder");
  119. console.log(t);
  120. case 'val':
  121. case 'value':
  122. me.val(t);
  123. break;
  124. default:
  125. me.html(t);
  126. }
  127. });
  128. }
  129. // js裡面的轉換
  130. function get_lan(m)
  131. {
  132. //獲取文字
  133. var lan = getCookie('lan'); //語言版本
  134. //選取語言文字
  135. switch(lan){
  136. case 'zh':
  137. var t = zh[m];
  138. break;
  139. case 'hk':
  140. var t = hk[m];
  141. break;
  142. default:
  143. var t = en[m];
  144. }
  145. //如果沒有找到就轉換其他語言
  146. if(t==undefined) t = zh[m];
  147. if(t==undefined) t = en[m];
  148. if(t==undefined) t = hk[m];
  149. if(t==undefined) t = m; //如果還是沒有就直接用標示
  150. return t;
  151. }
  152. // 預設中文版
  153. var lan = getCookie('lan');
  154. console.log(`目前語言版本: ${lan}`);
  155. changeLan('zh');