lan.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. "submit": "送出",
  42. "privacy_term": "同意隱私政策及使用條款"
  43. };
  44. var en = {
  45. "make_video" : "Make Videos",
  46. "make_slides" : "Make Videos By Slides",
  47. "login" : "Login",
  48. "user_profile": "User Profile",
  49. "logout": "Logout",
  50. "en": "English",
  51. "zh": "Chinese",
  52. "choose_character": "Choose Character",
  53. "usage_intro": "Usage Introduction",
  54. "history": "History",
  55. "preview_videos": "Preview Videos",
  56. "video_link": "Video Link",
  57. "video_title": "Video Title",
  58. "p_choose_character": "Choose Character",
  59. "lines": "Lines",
  60. "img_link": "Image Link",
  61. "processing_progress": "Processing Progress",
  62. "usage_intro": "Usage Introduction",
  63. "one_line_to_one_img": "1. Please Provide an Image Link Corresponding to a Line as a Collocation",
  64. "sup_img_profile": "2. Supported File Format:",
  65. "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.",
  66. "add_eng": "Allow English Lines:",
  67. "submit": "Submit",
  68. "privacy_term": "I Agree to privacy policy and terms of use."
  69. };
  70. // 4. 轉換
  71. function changeLan(val) {
  72. var val = val.value;
  73. console.log(`val: ${val}`);
  74. setCookie('lan', val);
  75. $('[set-lan]').each(function(){
  76. var me = $(this);
  77. var a = me.attr('set-lan').split(':');
  78. var p = a[0]; //文字放置位置
  79. var m = a[1]; //文字標示
  80. //用虎選擇語言後保存在cookie中,這裡讀取cooikes的語言版本
  81. var lan = getCookie('lan');
  82. console.log(lan);
  83. //選取語言文字
  84. switch(lan){
  85. case 'zh':
  86. var t = zh[m];
  87. console.log(t);
  88. break;
  89. case 'en':
  90. var t = en[m];
  91. console.log(t);
  92. break;
  93. default:
  94. var t = zh[m];
  95. console.log(t);
  96. }
  97. //所選語言沒有就換
  98. if(t==undefined) t = en[m];
  99. if(t==undefined) t = zh[m];
  100. if(t==undefined) return true; //都沒有就跳出
  101. //文字放置位置有(html,val等,可以自己添加)
  102. switch(p){
  103. case 'html':
  104. me.html(t);
  105. break;
  106. case 'placeholder':
  107. me.placeholder(t);
  108. console.log("placeholder");
  109. console.log(t);
  110. case 'val':
  111. me.val(t);
  112. break;
  113. case 'value':
  114. me.val(t);
  115. break;
  116. default:
  117. me.html(t);
  118. }
  119. });
  120. }
  121. // js裡面的轉換
  122. function get_lan(m)
  123. {
  124. //獲取文字
  125. var lan = getCookie('lan'); //語言版本
  126. //選取語言文字
  127. switch(lan){
  128. case 'zh':
  129. var t = zh[m];
  130. break;
  131. case 'hk':
  132. var t = hk[m];
  133. break;
  134. default:
  135. var t = en[m];
  136. }
  137. //如果沒有找到就轉換其他語言
  138. if(t==undefined) t = zh[m];
  139. if(t==undefined) t = en[m];
  140. if(t==undefined) t = hk[m];
  141. if(t==undefined) t = m; //如果還是沒有就直接用標示
  142. return t;
  143. }
  144. // 預設中文版
  145. var lan = getCookie('lan');
  146. console.log(`目前語言版本: ${lan}`);