From 068bb7dc78d0b3565c100b61acc859ede0adc0d4 Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Wed, 29 Jul 2009 00:00:52 +0800 Subject: merge Evgeny's English and Botum's Spanish translations --- templates/content/js/com.cnprog.i18n.js | 90 ++++++++++++++++++ templates/content/js/com.cnprog.post.js | 109 +++++++++++++++------- templates/content/js/com.cnprog.post.pack.js | 1 - templates/content/js/com.cnprog.utils.js | 22 +++-- templates/content/js/jquery.i18n.js | 133 +++++++++++++++++++++++++++ templates/content/js/wmd/wmd.js | 34 ++++--- 6 files changed, 329 insertions(+), 60 deletions(-) create mode 100644 templates/content/js/com.cnprog.i18n.js delete mode 100644 templates/content/js/com.cnprog.post.pack.js create mode 100644 templates/content/js/jquery.i18n.js (limited to 'templates/content/js') diff --git a/templates/content/js/com.cnprog.i18n.js b/templates/content/js/com.cnprog.i18n.js new file mode 100644 index 00000000..2d8c90a6 --- /dev/null +++ b/templates/content/js/com.cnprog.i18n.js @@ -0,0 +1,90 @@ +// Evgeny Fadeev evgeny.fadeev@gmail.com localized for english and chinese +// i18nLang variable must be set in html header to extract correct language +var i18nZh = { + 'insufficient privilege':'用户权限不在操作范围', + 'cannot pick own answer as best':'不能设置自己的回答为最佳答案', + 'anonymous users cannot select favorite questions':'匿名用户不能收藏问题,请先', + 'please login':'注册或者登录', + 'anonymous users cannot vote':'匿名用户不能投票', + '>15 points requried to upvote':'需要+15积分才能投支持票。', + '>100 points required to downvote':'需要+100积分才能投反对票。', + 'please see': '查看', + 'cannot vote for own posts':'不能给自己的帖子投票', + 'daily vote cap exhausted':'对不起,您已用完今日所有的投票。', + 'cannot revoke old vote':'这个投票已经过时,不能撤销。', + 'please confirm offensive':"确定要归类该帖为广告、人身攻击、恶意言论吗?", + 'anonymous users cannot flag offensive posts':'匿名用户不能操作,请先', + 'cannot flag message as offensive twice':'不能重复操作。', + 'flag offensive cap exhausted':'对不起,您已用完今日所有的5次‘水帖’操作。', + 'need >15 points to report spam':"需要+15积分才能归类‘垃圾帖’。", + 'confirm delete':"确定要删除/撤销删除该帖吗?", + 'anonymous users cannot delete/undelete':"匿名用户不能删除或撤销删除帖子", + 'post recovered':"操作成功!该帖子已被恢复。", + 'post deleted':"操作成功!该帖子已删除。", + 'add comment':'添加评论', + 'community reputation points':'社区积分', + 'to comment, need':'评论需要', + 'delete this comment':'删除此评论', + 'hide comments':"隐藏评论", + 'add a comment':"添加评论", + 'comments':"评论", + 'confirm delete comment':"真要删除此评论吗?", + 'characters':'字符', + 'can write':'还可写', + 'click to close':'点击消息框关闭', + 'loading...':'读取中...', + 'tags cannot be empty':'标签不能为空。', + 'tablimits info':"最多5个标签,每个标签长度小于20个字符。", + 'content cannot be empty':'内容不能为空。', + 'content minchars': '请输入至少 {0} 字符。', + 'please enter title':'请输入标题。', + 'title minchars':"请输入至少 {0} 字符。", + 'delete':'删除', + 'undelete': '取消', + 'bold':'粗体', + 'italic':'斜体', + 'link':'超链接', + 'quote':'引用', + 'preformatted text':'代码', + 'image':'图片', + 'numbered list':'数字编号列表', + 'bulleted list':'项目符号列表', + 'heading':'标题', + 'horizontal bar':'水平线', + 'undo':'撤销', + 'redo':'重做', + 'enter image url':'输入图片地址

示例:
http://www.example.com/image.jpg \"我的截图\"', + 'enter url':'输入Web地址

示例:
http://www.cnprog.com/ \"我的网站\"

"', + 'upload image':'或者上传本地图片:', +}; + +var i18nEn = { + 'to comment, need': 'to comment, need reputation ', + 'please see':'please see ', + 'community reputation points':' ', + 'upload image':'Upload image:', + 'enter image url':'enter URL of the image, e.g. http://www.example.com/image.jpg \"image title\"', + 'enter url':'enter Web address, e.g. http://www.example.com \"page title\"', + 'daily vote cap exhausted':'sorry, you\'ve used up todays vote cap', + 'cannot pick own answer as best':'cannot accept own answer', + 'cannot revoke old vote':'older votes cannot be revoked', + 'please confirm offensive':'are you sure this post is offensive, contains spam, advertising, malicious remarks, etc.?', + 'flag offensive cap exhausted':'sorry, you\'ve used up todays cap of flagging offensive messages', + 'confirm delete':'are you sure you want to delete this?', + 'anonymous users cannot delete/undelete':'anonymous users cannot delete or undelete posts', + 'post recovered':'your post is now restored!', + 'post deleted':'your post has been deleted', + 'confirm delete comment':'do you really want to delete this comment?', + 'can write':'have ', + 'tablimits info':'up to 5 tags, no more than 20 characters each', + 'content minchars': 'please enter more than {0} characters', + 'title minchars':"please enter at least {0} characters", + 'characters':'characters left', +}; + +var i18n = { + 'en':i18nEn, + 'zh':i18nZh +}; + +var i18n_dict = i18n[i18nLang]; diff --git a/templates/content/js/com.cnprog.post.js b/templates/content/js/com.cnprog.post.js index dbf5d128..e3101ea7 100644 --- a/templates/content/js/com.cnprog.post.js +++ b/templates/content/js/com.cnprog.post.js @@ -49,24 +49,37 @@ var Vote = function(){ var removeQuestionLinkIdPrefix = 'question-delete-link-'; var removeAnswerLinkIdPrefix = 'answer-delete-link-'; - var acceptAnonymousMessage = "用户权限不在操作范围"; - var acceptOwnAnswerMessage = "不能设置自己的回答为最佳答案"; - var favoriteAnonymousMessage = "匿名用户不能收藏问题,请先注册或者登录"; - var voteAnonymousMessage = "匿名用户不能投票,请先注册或者登录"; - var upVoteRequiredScoreMessage = "需要+15积分才能投支持票。查看faq"; - var downVoteRequiredScoreMessage = "需要+100积分才能投反对票。查看faq"; - var voteOwnDeniedMessage = "不能给自己的帖子投票"; - var voteRequiredMoreVotes = "对不起,您已用完今日所有的投票。查看faq"; - var voteDenyCancelMessage = "这个投票已经过时,不能撤销。查看faq"; - var offensiveConfirmation = "确定要归类该帖为广告、人身攻击、恶意言论吗?"; - var offensiveAnonymousMessage = "匿名用户不能操作,请先注册或者登录"; - var offensiveTwiceMessage = "不能重复操作。查看faq"; - var offensiveNoFlagsLeftMessage = "对不起,您已用完今日所有的5次‘水帖’操作。查看faq"; - var offensiveNoPermissionMessage = "需要+15积分才能归类‘垃圾帖’。查看faq"; - var removeConfirmation = "确定要删除/撤销删除该帖吗?"; - var removeAnonymousMessage = "匿名用户不能删除或撤销删除帖子"; - var recoveredMessage = "操作成功!该帖子已被恢复。"; - var deletedMessage = "操作成功!该帖子已删除。" + var acceptAnonymousMessage = $.i18n._('insufficient privilege'); + var acceptOwnAnswerMessage = $.i18n._('cannot pick own answer as best'); + var favoriteAnonymousMessage = $.i18n._('anonymous user cannot select favorite questions') + + "" + + $.i18n._('please login') + ""; + var voteAnonymousMessage = $.i18n._('anonymous users cannot vote') + + "" + + $.i18n._('please login') + ""; + var upVoteRequiredScoreMessage = $.i18n._('>15 points requried to upvote') + + $.i18n._('please see') + "faq"; + var downVoteRequiredScoreMessage = $.i18n._('>100 points requried to downvote') + + $.i18n._('please see') + "faq"; + var voteOwnDeniedMessage = $.i18n._('cannot vote for own posts'); + var voteRequiredMoreVotes = $.i18n._('daily vote cap exhausted') + + $.i18n._('please see') + "faq"; + var voteDenyCancelMessage = $.i18n._('cannot revoke old vote') + + $.i18n._('please see') + "faq"; + var offensiveConfirmation = $.i18n._('please confirm offensive'); + var offensiveAnonymousMessage = $.i18n._('anonymous users cannot flag offensive posts') + + "" + + $.i18n._('please login') + ""; + var offensiveTwiceMessage = $.i18n._('cannot flag message as offensive twice') + + $.i18n._('please see') + "faq"; + var offensiveNoFlagsLeftMessage = $.i18n._('flag offensive cap exhausted') + + $.i18n._('please see') + "faq"; + var offensiveNoPermissionMessage = $.i18n._('need >15 points to report spam') + + $.i18n._('please see') + "faq"; + var removeConfirmation = $.i18n._('confirm delete'); + var removeAnonymousMessage = $.i18n._('anonymous users cannot delete/undelete'); + var recoveredMessage = $.i18n._('post recovered'); + var deletedMessage = $.i18n._('post deleted'); var VoteType = { acceptAnswer : 0, @@ -201,7 +214,7 @@ var Vote = function(){ }); getremoveQuestionLink().unbind('click').click(function(event){ - Vote.remove(this, VoteType.removeQuestion) + Vote.remove(this, VoteType.removeQuestion); }); getremoveAnswersLinks().unbind('click').click(function(event){ @@ -330,15 +343,22 @@ var Vote = function(){ }; var callback_remove = function(object, voteType, data){ + alert(data.status); if(data.allowed == "0" && data.success == "0"){ showMessage(object, removeAnonymousMessage.replace("{{QuestionID}}", questionId)); } - else if(data.status == "1"){ - showMessage(object, recoveredMessage); - } - else if(data.success == "1"){ - showMessage(object, deletedMessage); - } + else if (data.success == "1"){ + if (removeActionType == 'delete'){ + postNode.addClass('deleted'); + postRemoveLink.innerHTML = $.i18n._('undelete'); + showMessage(object, deletedMessage); + } + else if (removeActionType == 'undelete') { + postNode.removeClass('deleted'); + postRemoveLink.innerHTML = $.i18n._('delete'); + showMessage(object, recoveredMessage); + } + } }; return { @@ -395,8 +415,23 @@ var Vote = function(){ return false; } if(confirm(removeConfirmation)){ - postId = object.id.substr(object.id.lastIndexOf('-') + 1); + bits = object.id.split('-'); + postId = bits.pop();/* this seems to be used within submit! */ + postType = bits.shift(); + + if (postType == 'answer'){ + postNode = $('#answer-container-' + postId); + postRemoveLink = object; + if (postNode.hasClass('deleted')){ + removeActionType = 'undelete'; + } + else { + removeActionType = 'delete'; + } + } submit($(object), voteType, callback_remove); + + } } } @@ -426,7 +461,8 @@ function createComments(type) { var form = '
'; form += ''; - form += '
'; + form += '
'; form += '
'; jDiv.append(form); @@ -439,7 +475,10 @@ function createComments(type) { else { var divId = "comments-rep-needed-" + objectType + '-' + id; if (jDiv.find("#" + divId).length == 0) { - jDiv.append('
评论需要 ' + repNeededForComments + ' 社区积分 - 查看faq'); + jDiv.append('
' + + $.i18n._('to comment, need') + ' ' + + + repNeededForComments + ' ' + $.i18n._('community reputation points') + + '' + $.i18n._('please see') + 'faq'); } } }; @@ -477,7 +516,7 @@ function createComments(type) { var imgHover = "/content/images/close-small-hover.png"; html += ''; + html += '\')" title="' + $.i18n._('delete this comment') + '" />'; } html += '
'; @@ -524,13 +563,15 @@ function createComments(type) { renderForm(id, jDiv); jDiv.show(); if (canPostComments(id, jDiv)) jDiv.find("textarea").get(0).focus(); - jDiv.siblings("a").unbind("click").click(function() { commentsFactory[objectType].hide(id); }).text("隐藏评论"); + jDiv.siblings("a").unbind("click").click(function(){ + commentsFactory[objectType].hide(id); + }).text($.i18n._('hide comments')); }, hide: function(id) { var jDiv = jDivInit(id); var len = jDiv.children("div.comments").children().length; - var anchorText = len == 0 ? "添加评论" : "评论 (" + len + ")"; + var anchorText = len == 0 ? $.i18n._('add a comment') : $.i18n._('comments') + ' (' + len + ")"; jDiv.hide(); jDiv.siblings("a").unbind("click").click(function() { commentsFactory[objectType].show(id); }).html(anchorText); @@ -538,7 +579,7 @@ function createComments(type) { }, deleteComment: function(jImg, id, deleteUrl) { - if (confirm("真要删除此评论吗?")) { + if (confirm($.i18n._('confirm delete comment'))) { jImg.hide(); appendLoaderImg(id); $.post(deleteUrl, { dataNeeded: "forIIS7" }, function(json) { @@ -551,7 +592,9 @@ function createComments(type) { var length = textarea.value ? textarea.value.length : 0; var color = length > 270 ? "#f00" : length > 200 ? "#f60" : "#999"; var jSpan = $(textarea).siblings("span.text-counter"); - jSpan.html('还可写' + (300 - length) + ' 字符').css("color", color); + jSpan.html($.i18n._('can write') + + (300 - length) + ' ' + + $.i18n._('characters')).css("color", color); } }; } diff --git a/templates/content/js/com.cnprog.post.pack.js b/templates/content/js/com.cnprog.post.pack.js deleted file mode 100644 index 8af19d13..00000000 --- a/templates/content/js/com.cnprog.post.pack.js +++ /dev/null @@ -1 +0,0 @@ -var lanai={highlightSyntax:function(){var a=false;$("pre code").parent().each(function(){if(!$(this).hasClass("prettyprint")){$(this).addClass("prettyprint");a=true}});if(a){prettyPrint()}}};var Vote=function(){var M;var v;var ah;var O;var X="answer-container-";var V="vote-buttons";var s="answer-img-accept-";var T="question-img-favorite";var N="question-img-upvote-";var r="question-img-downvote-";var L="answer-img-upvote-";var ae="answer-img-downvote-";var ad="favorite-number";var j="comment-";var H="vote-number";var a="question-offensive-flag-";var t="answer-offensive-flag-";var x="offensive-flag";var aa="question-controls";var J="question-delete-link-";var b="answer-delete-link-";var o="用户权限不在操作范围";var w="不能设置自己的回答为最佳答案";var g="匿名用户不能收藏问题,请先注册或者登录";var aj="匿名用户不能投票,请先注册或者登录";var K="需要+15积分才能投支持票。查看faq";var Y="需要+100积分才能投反对票。查看faq";var q="不能给自己的帖子投票";var n="对不起,您已用完今日所有的投票。查看faq";var A="这个投票已经过时,不能撤销。查看faq";var u="确定要归类该帖为广告、人身攻击、恶意言论吗?";var ab="匿名用户不能操作,请先注册或者登录";var C="不能重复操作。查看faq";var B="对不起,您已用完今日所有的5次‘水帖’操作。查看faq";var af="需要+15积分才能归类‘垃圾帖’。查看faq";var p="确定要删除/撤销删除该帖吗?";var W="匿名用户不能删除或撤销删除帖子";var Q="操作成功!该帖子已被恢复。";var i="操作成功!该帖子已删除。";var h={acceptAnswer:0,questionUpVote:1,questionDownVote:2,favorite:4,answerUpVote:5,answerDownVote:6,offensiveQuestion:7,offensiveAnswer:8,removeQuestion:9,removeAnswer:10};var Z=function(){var ak="div."+V+" img[class="+T+"]";return $(ak)};var I=function(){var ak="#"+ad;return $(ak)};var e=function(){var ak="div."+V+" img[id^="+N+"]";return $(ak)};var E=function(){var ak="div."+V+" img[id^="+r+"]";return $(ak)};var l=function(){var ak="div."+V+" img[id^="+L+"]";return $(ak)};var k=function(){var ak="div."+V+" img[id^="+ae+"]";return $(ak)};var m=function(al){var ak="div."+V+" img[id="+L+al+"]";return $(ak)};var y=function(al){var ak="div."+V+" img[id="+ae+al+"]";return $(ak)};var z=function(){var ak="table[id=question-table] span[class="+x+"]";return $(ak)};var c=function(){var ak="div.answer span[class="+x+"]";return $(ak)};var R=function(){var ak="div#question-controls a[id^="+J+"]";return $(ak)};var f=function(){var ak="div.answer-controls a[id^="+b+"]";return $(ak)};var U=function(an,al,am){var ak=al?"":"-on";var ao=(an==h.questionUpVote||an==h.answerUpVote)?"up":"down";am.attr("src","/content/images/vote-arrow-"+ao+ak+".png");if(al){if(an==h.questionUpVote||an==h.questionDownVote){$(e()).attr("src","/content/images/vote-arrow-up.png");$(E()).attr("src","/content/images/vote-arrow-down.png")}else{$(m(v)).attr("src","/content/images/vote-arrow-up.png");$(y(v)).attr("src","/content/images/vote-arrow-down.png")}}};var P=function(al,am){var ak=al.parent("div."+V).find("div."+H);$(ak).text(am)};var ac=function(){if(ah==O){var am="div."+V+" img[id^="+s+"]";$(am).unbind("click").click(function(aq){Vote.accept($(aq.target))})}var ao=Z();ao.unbind("click").click(function(aq){Vote.favorite($(aq.target))});var an=e();an.unbind("click").click(function(aq){Vote.vote($(aq.target),h.questionUpVote)});var ak=E();ak.unbind("click").click(function(aq){Vote.vote($(aq.target),h.questionDownVote)});var al=l();al.unbind("click").click(function(aq){Vote.vote($(aq.target),h.answerUpVote)});var ap=k();ap.unbind("click").click(function(aq){Vote.vote($(aq.target),h.answerDownVote)});z().unbind("click").click(function(aq){Vote.offensive(this,h.offensiveQuestion)});c().unbind("click").click(function(aq){Vote.offensive(this,h.offensiveAnswer)});R().unbind("click").click(function(aq){Vote.remove(this,h.removeQuestion)});f().unbind("click").click(function(aq){Vote.remove(this,h.removeAnswer)})};var G=function(ak,al,am){$.ajax({type:"POST",cache:false,dataType:"json",url:"/questions/"+M+"/vote/",data:{type:al,postId:v},error:ai,success:function(an){am(ak,al,an)}})};var ai=function(al,ak){alert("Callback invoke error: "+ak)};var d=function(al,am,ao){if(ao.allowed=="0"&&ao.success=="0"){showMessage(al,o)}else{if(ao.allowed=="-1"){showMessage(al,w)}else{if(ao.status=="1"){al.attr("src","/content/images/vote-accepted.png");$("#"+X+v).removeClass("accepted-answer");$("#"+j+v).removeClass("comment-link-accepted")}else{if(ao.success=="1"){var an="div."+V+" img[id^="+s+"]";$(an).attr("src","/content/images/vote-accepted.png");var ap=("div[id^="+X+"]");$(ap).removeClass("accepted-answer");var ak=("div[id^="+X+"] div[id^="+j+"]");$(ak).removeClass("comment-link-accepted");al.attr("src","/content/images/vote-accepted-on.png");$("#"+X+v).addClass("accepted-answer");$("#"+j+v).addClass("comment-link-accepted")}else{showMessage(al,ao.message)}}}}};var F=function(ak,al,am){if(am.allowed=="0"&&am.success=="0"){showMessage(ak,g.replace("{{QuestionID}}",M))}else{if(am.status=="1"){ak.attr("src","/content/images/vote-favorite-off.png");var an=I();an.removeClass("my-favorite-number");if(am.count==0){am.count=""}an.text(am.count)}else{if(am.success=="1"){ak.attr("src","/content/images/vote-favorite-on.png");var an=I();an.text(am.count);an.addClass("my-favorite-number")}else{showMessage(ak,am.message)}}}};var S=function(ak,al,am){if(am.allowed=="0"&&am.success=="0"){showMessage(ak,aj.replace("{{QuestionID}}",M))}else{if(am.allowed=="-3"){showMessage(ak,n)}else{if(am.allowed=="-2"){if(al==h.questionUpVote||al==h.answerUpVote){showMessage(ak,K)}else{if(al==h.questionDownVote||al==h.answerDownVote){showMessage(ak,Y)}}}else{if(am.allowed=="-1"){showMessage(ak,q)}else{if(am.status=="2"){showMessage(ak,A)}else{if(am.status=="1"){U(al,true,ak);P(ak,am.count)}else{if(am.success=="1"){U(al,false,ak);P(ak,am.count);if(am.message.length>0){showMessage(ak,am.message)}}}}}}}}};var ag=function(ak,al,am){ak=$(ak);if(am.allowed=="0"&&am.success=="0"){showMessage(ak,ab.replace("{{QuestionID}}",M))}else{if(am.allowed=="-3"){showMessage(ak,B)}else{if(am.allowed=="-2"){showMessage(ak,af)}else{if(am.status=="1"){showMessage(ak,C)}else{if(am.success=="1"){$(ak).children("span[class=darkred]").text("("+am.count+")")}}}}}};var D=function(ak,al,am){if(am.allowed=="0"&&am.success=="0"){showMessage(ak,W.replace("{{QuestionID}}",M))}else{if(am.status=="1"){showMessage(ak,Q)}else{if(am.success=="1"){showMessage(ak,i)}}}};return{init:function(ak,al,am){M=ak;ah=al;O=am;ac()},accept:function(ak){v=ak.attr("id").substring(s.length);G(ak,h.acceptAnswer,d)},favorite:function(ak){if(!O||O.toUpperCase()=="NONE"){showMessage(ak,g.replace("{{QuestionID}}",M));return false}G(ak,h.favorite,F)},vote:function(ak,al){if(!O||O.toUpperCase()=="NONE"){showMessage(ak,aj.replace("{{QuestionID}}",M));return false}if(al==h.answerUpVote){v=ak.attr("id").substring(L.length)}else{if(al==h.answerDownVote){v=ak.attr("id").substring(ae.length)}}G(ak,al,S)},offensive:function(ak,al){if(!O||O.toUpperCase()=="NONE"){showMessage($(ak),ab.replace("{{QuestionID}}",M));return false}if(confirm(u)){v=ak.id.substr(ak.id.lastIndexOf("-")+1);G(ak,al,ag)}},remove:function(ak,al){if(!O||O.toUpperCase()=="NONE"){showMessage($(ak),W.replace("{{QuestionID}}",M));return false}if(confirm(p)){v=ak.id.substr(ak.id.lastIndexOf("-")+1);G($(ak),al,D)}}}}();function createComments(i){var d=i;var b=function(k){return $("#comments-"+d+"-"+k)};var j=function(k){appendLoader("#comments-"+d+"-"+k+" div.comments")};var h=function(m,l){var k=l.siblings("#can-post-comments-"+d+"-"+m);return k.val().toLowerCase()=="true"};var f=function(o,m){var n="form-comments-"+d+"-"+o;if(h(o,m)){if(m.find("#"+n).length==0){var l='
';l+='';l+='
';l+='
';m.append(l);setupFormValidation("#"+n,{comment:{required:true,minlength:10}},"",function(){e(o,n)})}}else{var k="comments-rep-needed-"+d+"-"+o;if(m.find("#"+k).length==0){m.append('
评论需要 '+repNeededForComments+' 社区积分 - 查看faq')}}};var a=function(l,k){j(l);$.getJSON("/"+d+"s/"+l+"/comments/",function(m){c(l,m)})};var c=function(n,l){var m=b(n);m=m.find("div.comments");m.find("div[id^='comment-"+d+"-']").remove();removeLoader();if(l&&l.length>0){for(var k=0;k'+n.text;m+=n.user_url?' – ":"");m+=' ('+n.add_date+")";if(n.delete_url){var l="/content/images/close-small.png";var k="/content/images/close-small-hover.png";m+=''}m+="
";o.append(m)};var e=function(n,m){j(n);var l="#"+m;var k=$(l+" textarea");$.ajax({type:"POST",url:"/"+d+"s/"+n+"/comments/",dataType:"json",data:{comment:k.val()},success:function(o){c(n,o);k.val("");commentsFactory[d].updateTextCounter(k);enableSubmitButton(l)},error:function(o,q,p){removeLoader();showMessage(l,o.responseText);enableSubmitButton(l)}})};return{init:function(){$("a[id^='comments-link-"+d+"-']").unbind("click").click(function(){commentsFactory[d].show($(this).attr("id").substr(("comments-link-"+d+"-").length))})},show:function(l){var k=b(l);a(l,k);f(l,k);k.show();if(h(l,k)){k.find("textarea").get(0).focus()}k.siblings("a").unbind("click").click(function(){commentsFactory[d].hide(l)}).text("隐藏评论")},hide:function(n){var m=b(n);var k=m.children("div.comments").children().length;var l=k==0?"添加评论":"评论 ("+k+")";m.hide();m.siblings("a").unbind("click").click(function(){commentsFactory[d].show(n)}).html(l);m.children("div.comments").children().hide()},deleteComment:function(m,l,k){if(confirm("真要删除此评论吗?")){m.hide();j(l);$.post(k,{dataNeeded:"forIIS7"},function(n){c(l,n)},"json")}},updateTextCounter:function(l){var n=l.value?l.value.length:0;var m=n>270?"#f00":n>200?"#f60":"#999";var k=$(l).siblings("span.text-counter");k.html("还可写"+(300-n)+" 字符").css("color",m)}}}var questionComments=createComments("question");var answerComments=createComments("answer");$().ready(function(){questionComments.init();answerComments.init()});var commentsFactory={question:questionComments,answer:answerComments};var PR_SHOULD_USE_CONTINUATION=true;var PR_TAB_WIDTH=8;var PR_normalizedHtml;var PR;var prettyPrintOne;var prettyPrint;function _pr_isIE6(){var a=navigator&&navigator.userAgent&&/\bMSIE 6\./.test(navigator.userAgent);_pr_isIE6=function(){return a};return a}(function(){function W(av){av=av.split(/ /g);var aw={};for(var au=av.length;--au>=0;){var at=av[au];if(at){aw[at]=null}}return aw}var n="break continue do else for if return while ";var D=n+"auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile ";var w=D+"catch class delete false import new operator private protected public this throw true try ";var p=w+"alignof align_union asm axiom bool concept concept_map const_cast constexpr decltype dynamic_cast explicit export friend inline late_check mutable namespace nullptr reinterpret_cast static_assert static_cast template typeid typename typeof using virtual wchar_t where ";var G=w+"boolean byte extends final finally implements import instanceof null native package strictfp super synchronized throws transient ";var ap=G+"as base by checked decimal delegate descending event fixed foreach from group implicit in interface internal into is lock object out override orderby params readonly ref sbyte sealed stackalloc string select uint ulong unchecked unsafe ushort var ";var F=w+"debugger eval export function get null set undefined var with Infinity NaN ";var y="caller delete die do dump elsif eval exit foreach for goto if import last local my next no our print package redo require sub undef unless until use wantarray while BEGIN END ";var ab=n+"and as assert class def del elif except exec finally from global import in is lambda nonlocal not or pass print raise try with yield False True None ";var k=n+"alias and begin case class def defined elsif end ensure false in module next nil not or redo rescue retry self super then true undef unless until when yield BEGIN END ";var aa=n+"case done elif esac eval fi function in local set then until ";var M=(p+ap+F+y+ab+k+aa);var O="str";var L="kwd";var o="com";var al="typ";var Y="lit";var ah="pun";var V="pln";var q="tag";var U="dec";var ad="src";var ao="atn";var s="atv";var ak="nocode";function aq(at){return(at>="a"&&at<="z")||(at>="A"&&at<="Z")}function N(aw,au,at,av){aw.unshift(at,av||0);try{au.splice.apply(au,aw)}finally{aw.splice(0,2)}}var ai=function(){var av=["!","!=","!==","#","%","%=","&","&&","&&=","&=","(","*","*=","+=",",","-=","->","/","/=",":","::",";","<","<<","<<=","<=","=","==","===",">",">=",">>",">>=",">>>",">>>=","?","@","[","^","^=","^^","^^=","{","|","|=","||","||=","~","break","case","continue","delete","do","else","finally","instanceof","return","throw","try","typeof"];var aw="(?:(?:(?:^|[^0-9.])\\.{1,3})|(?:(?:^|[^\\+])\\+)|(?:(?:^|[^\\-])-)";for(var at=0;at:&])/g,"\\$1")}}aw+="|^)\\s*$";return new RegExp(aw)}();var S=/&/g;var Z=//g;var K=/\"/g;function E(at){return at.replace(S,"&").replace(Z,"<").replace(x,">").replace(K,""")}function r(at){return at.replace(S,"&").replace(Z,"<").replace(x,">")}var e=/</g;var C=/>/g;var d=/'/g;var i=/"/g;var ar=/&/g;var J=/ /g;function t(aw){var ay=aw.indexOf("&");if(ay<0){return aw}for(--ay;(ay=aw.indexOf("&#",ay+1))>=0;){var at=aw.indexOf(";",ay);if(at>=0){var av=aw.substring(ay+3,at);var ax=10;if(av&&av.charAt(0)==="x"){av=av.substring(1);ax=16}var au=parseInt(av,ax);if(!isNaN(au)){aw=(aw.substring(0,ay)+String.fromCharCode(au)+aw.substring(at+1))}}}return aw.replace(e,"<").replace(C,">").replace(d,"'").replace(i,'"').replace(ar,"&").replace(J," ")}function R(at){return"XMP"===at.tagName}function an(ax,av){switch(ax.nodeType){case 1:var au=ax.tagName.toLowerCase();av.push("<",au);for(var aw=0;aw");for(var ay=ax.firstChild;ay;ay=ay.nextSibling){an(ay,av)}if(ax.firstChild||!/^(?:br|link|img)$/.test(au)){av.push("")}break;case 2:av.push(ax.name.toLowerCase(),'="',E(ax.value),'"');break;case 3:case 4:av.push(r(ax.nodeValue));break}}var am=null;function b(aw){if(null===am){var au=document.createElement("PRE");au.appendChild(document.createTextNode('\n'));am=!/=0;aw-=at.length){ax.push(at.substring(0,aw))}aC=ay+1;break;case"\n":au=0;break;default:++au}}if(!ax){return az}ax.push(az.substring(aC));return ax.join("")}}var Q=/(?:[^<]+|||<\/?[a-zA-Z][^>]*>|<)/g;var v=/^|$)/,null],[ad,/^<\?[\s\S]*?(?:\?>|$)/,null],[ad,/^<%[\s\S]*?(?:%>|$)/,null],[ad,/^<(script|style|xmp)\b[^>]*>[\s\S]*?<\/\1\b[^>]*>/i,null],[q,/^<\/?\w[^<>]*>/,null]]);var z=/^(<[^>]*>)([\s\S]*)(<\/[^>]*>)$/;function ae(ay){var av=a(ay);for(var ax=0;ax\/=]+/,null,"<>/="]],[[q,/^[\w:\-]+/,/^=2&&/^[\"\']/.test(aG)&&aG.charAt(0)===aG.charAt(au-1));var aw;var ay;var aC;if(aA){ay=ax+1;aC=aD-1;aw=aG}else{ay=ax+1;aC=aD-1;aw=aG.substring(1,aG.length-1)}var aH=af(aw);for(var aE=0,az=aH.length;aEaI){if(ax&&ax!==aC){aB.push("");ax=null}if(!ax&&aC){ax=aC;aB.push('')}var aL=r(az(aJ.substring(aI,aK))).replace(aE?aF:aw,"$1 ");aE=aD.test(aL);aB.push(aL.replace(aA,"
"));aI=aK}}while(true){var at;if(av");ax=null}aB.push(au[av+1]);av+=2}else{if(aH")}return aB.join("")}var A={};function g(av,aw){for(var at=aw.length;--at>=0;){var au=aw[at];if(!A.hasOwnProperty(au)){A[au]=av}else{if("console" in window){console.log("cannot override language handler %s",au)}}}}g(af,["default-code"]);g(l,["default-markup","html","htm","xhtml","xml","xsl"]);g(m({keywords:p,hashComments:true,cStyleComments:true}),["c","cc","cpp","cs","cxx","cyc"]);g(m({keywords:G,cStyleComments:true}),["java"]);g(m({keywords:aa,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);g(m({keywords:ab,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);g(m({keywords:y,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);g(m({keywords:k,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);g(m({keywords:F,cStyleComments:true,regexLiterals:true}),["js"]);function H(ay,aw){try{var az=B(ay);var av=az.source;var at=az.tags;if(!A.hasOwnProperty(aw)){aw=/^\s*=0){var aD=aH.className.match(/\blang-(\w+)\b/);if(aD){aD=aD[1]}var aM=false;for(var aB=aH.parentNode;aB;aB=aB.parentNode){if((aB.tagName==="pre"||aB.tagName==="code"||aB.tagName==="xmp")&&aB.className&&aB.className.indexOf("prettyprint")>=0){aM=true;break}}if(!aM){var aJ=b(aH);aJ=aJ.replace(/(?:\r\n?|\n)$/,"");var aN=H(aJ,aD);if(!R(aH)){aH.innerHTML=aN}else{var aC=document.createElement("PRE");for(var aF=0;aF=0;){var aL=aI[aE];aL.parentNode.replaceChild(document.createTextNode("\r\n"),aL)}}}}}if(at

' + msg + '

(点击消息框关闭)
'); + var div = $('

' + msg + '

(' + + $.i18n._('click to close') + ')
'); div.click(function(event) { $(".vote-notification").fadeOut("fast", function() { $(this).remove(); }); @@ -33,7 +34,12 @@ var notify = function() { } (); function appendLoader(containerSelector) { - $(containerSelector).append('读取中...'); + $(containerSelector).append(''
+		+$.i18n._('loading...')
+		+''); } function removeLoader() { @@ -96,16 +102,16 @@ var CPValidator = function(){ getQuestionFormMessages: function(){ return { tags: { - required: " 标签不能为空。", - maxlength: " 最多5个标签,每个标签长度小于20个字符。" + required: " " + $.i18n._('tags cannot be empty'), + maxlength: " " + $.i18n._('tablimits info'), }, text: { - required: " 内容不能为空。", - minlength: jQuery.format(" 请输入至少 {0} 字符。") + required: " " + $.i18n._('content cannot be empty'), + minlength: jQuery.format(' ' + $.i18n._('content minchars')) }, title: { - required: " 请输入标题。", - minlength: jQuery.format(" 请输入至少 {0} 字符。") + required: " " + $.i18n._('please enter title'), + minlength: jQuery.format(' ' + $.i18n._('title minchars')) } }; } diff --git a/templates/content/js/jquery.i18n.js b/templates/content/js/jquery.i18n.js new file mode 100644 index 00000000..0a155a31 --- /dev/null +++ b/templates/content/js/jquery.i18n.js @@ -0,0 +1,133 @@ +/* + * jQuery i18n plugin + * @requires jQuery v1.1 or later + * + * Examples at: http://recurser.com/articles/2008/02/21/jquery-i18n-translation-plugin/ + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + * Based on 'javascript i18n that almost doesn't suck' by markos + * http://markos.gaivo.net/blog/?p=100 + * + * Revision: $Id$ + * Version: 1.0.0 Feb-10-2008 + */ + (function($) { +/** + * i18n provides a mechanism for translating strings using a jscript dictionary. + * + */ + + +/* + * i18n property list + */ +$.i18n = { + +/** + * setDictionary() + * Initialise the dictionary and translate nodes + * + * @param property_list i18n_dict : The dictionary to use for translation + */ + setDictionary: function(i18n_dict) { + i18n_dict = i18n_dict; + }, + +/** + * _() + * The actual translation function. Looks the given string up in the + * dictionary and returns the translation if one exists. If a translation + * is not found, returns the original word + * + * @param string str : The string to translate + * @param property_list params : params for using printf() on the string + * @return string : Translated word + * + */ + _: function (str, params) { + var transl = str; + if (i18n_dict&& i18n_dict[str]) { + transl = i18n_dict[str]; + } + return this.printf(transl, params); + }, + +/** + * toEntity() + * Change non-ASCII characters to entity representation + * + * @param string str : The string to transform + * @return string result : Original string with non-ASCII content converted to entities + * + */ + toEntity: function (str) { + var result = ''; + for (var i=0;i 128) + result += "&#"+str.charCodeAt(i)+";"; + else + result += str.charAt(i); + } + return result; + }, + +/** + * stripStr() + * + * @param string str : The string to strip + * @return string result : Stripped string + * + */ + stripStr: function(str) { + return str.replace(/^\s*/, "").replace(/\s*$/, ""); + }, + +/** + * stripStrML() + * + * @param string str : The multi-line string to strip + * @return string result : Stripped string + * + */ + stripStrML: function(str) { + // Split because m flag doesn't exist before JS1.5 and we need to + // strip newlines anyway + var parts = str.split('\n'); + for (var i=0; i Ctrl-B"; + var toolbar_emphasis_label = $.i18n._('italic') + " Ctrl-I"; + var toolbar_hyperlink_label = $.i18n._('link') + "
Ctrl-L"; + var toolbar_blockquote_label = $.i18n._('quote') + "
Ctrl-."; + var toolbar_code_label = $.i18n._('preformatted text') + "
 Ctrl-K";
+    var toolbar_image_label = $.i18n._('image') + "  Ctrl-G";
+    var toolbar_numbered_label = $.i18n._('numbered list') + " 
    Ctrl-O"; + var toolbar_bulleted_label = $.i18n._('bulleted list') + "
      Ctrl-U"; + var toolbar_heading_label = $.i18n._('heading') + "

      /

      Ctrl-H"; + var toolbar_horizontal_label = $.i18n._('horizontal bar') + "
      Ctrl-R"; + var toolbar_undo_label = $.i18n._('undo') + " Ctrl-Z"; + var toolbar_redo_label = $.i18n._('redo') + " Ctrl-Y"; // ------------------------------------------------------------------- // YOUR CHANGES GO HERE @@ -49,11 +49,9 @@ Attacklab.wmdBase = function(){ // The text that appears on the upper part of the dialog box when // entering links. - var imageDialogText = "

      输入图片地址

      示例:
      "+ - "http://www.cnprog.com/images/temp.jpg \"我的截图\"

      "; - var linkDialogText = "

      输入Web地址

      示例:
      "+ - "http://www.cnprog.com/ \"我的网站\"

      "; - var uploadImageHTML ="
      或者上传本地图片:
      " + + var imageDialogText = "

      " + $.i18n._('enter image url') + '

      '; + var linkDialogText = "

      " + $.i18n._('enter url') + '

      '; + var uploadImageHTML ="
      " + $.i18n._('upload image') + "
      " + "
      " + ""; @@ -1079,7 +1077,7 @@ Attacklab.wmdBase = function(){ } else { // mac and other non-Windows platforms - redoButton.title = "重做 - Ctrl+Shift+Z"; + redoButton.title = $.i18n._('redo') + " - Ctrl+Shift+Z"; } redoButton.XShift = "-220px"; redoButton.execute = function(manager){ -- cgit v1.2.3-1-g7c22