lan.js 4.5 KB

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