Browse Source

use Polyglot.js to translate in JS and in HTML templates

master
Msjoinder 11 years ago
parent
commit
5b1ed424c4
  1. 2
      css/style.css
  2. 12
      following.html
  3. 22
      home.html
  4. 1
      index.html
  5. 45
      interface_common.js
  6. 2
      interface_home.js
  7. 226
      interface_localization.js
  8. 2
      interface_login.js
  9. 14
      interface_profile-edit.js
  10. 2
      network.html
  11. 17
      polyglot.min.js
  12. 8
      tmobile.js
  13. 10
      twister_actions.js
  14. 6
      twister_directmsg.js
  15. 8
      twister_following.js
  16. 6
      twister_io.js
  17. 17
      twister_network.js
  18. 18
      twister_user.js

2
css/style.css

@ -443,7 +443,7 @@ button.disabled:hover
{ {
color: #b43e34; color: #b43e34;
} }
.profile-data li a span .profile-data li a span.posts-count, .profile-data li a span.following-count, .profile-data li a span.followers-count
{ {
font-weight: bold; font-weight: bold;
display: block; display: block;

12
following.html

@ -12,6 +12,8 @@
<script src="jquery.storageapi.js"></script> <script src="jquery.storageapi.js"></script>
<script src="mobile_abstract.js"></script> <script src="mobile_abstract.js"></script>
<script src="twister_io.js"></script> <script src="twister_io.js"></script>
<script src="polyglot.min.js"></script>
<script src="interface_localization.js"></script>
<script src="twister_network.js"></script> <script src="twister_network.js"></script>
<script src="twister_user.js"></script> <script src="twister_user.js"></script>
<script src="twister_formatpost.js"></script> <script src="twister_formatpost.js"></script>
@ -347,9 +349,9 @@
</div> </div>
</div> </div>
<ul class="module profile-data"> <ul class="module profile-data">
<li><a href="#"><span class="posts-count">&nbsp;</span>Posts</a></li> <li><a href="#"><span class="posts-count">&nbsp;</span><span class="label">Posts</span></a></li>
<li><a href="#" class="open-following-modal"><span class="following-count">&nbsp;</span>Following</a></li> <li><a href="#" class="open-following-modal"><span class="following-count">&nbsp;</span><span class="label">Following</span></a></li>
<li><a href="#"><span class="followers-count">&nbsp;</span>Followers</a></li> <li><a href="#"><span class="followers-count">&nbsp;</span><span class="label">Followers</span></a></li>
</ul> </ul>
<button class="follow" href="#">Follow</button> <button class="follow" href="#">Follow</button>
<button class="direct-messages-with-user" href="#">Direct Messages</button> <button class="direct-messages-with-user" href="#">Direct Messages</button>
@ -362,7 +364,7 @@
<h2> <h2>
Posts Posts
<!-- o botão de novas postagens deve ser ocultado quando o usuário clicá-lo via javascript --> <!-- o botão de novas postagens deve ser ocultado quando o usuário clicá-lo via javascript -->
<button class="postboard-news" style="display:none;">5 novos posts</button> <button class="postboard-news" style="display:none;"></button>
</h2> </h2>
<ol id="profile-posts" class="postboard-posts"> <ol id="profile-posts" class="postboard-posts">
@ -382,7 +384,7 @@
<h2> <h2>
Posts Posts
<!-- o botão de novas postagens deve ser ocultado quando o usuário clicá-lo via javascript --> <!-- o botão de novas postagens deve ser ocultado quando o usuário clicá-lo via javascript -->
<button class="postboard-news" style="display:none;">5 novos posts</button> <button class="postboard-news" style="display:none;"></button>
</h2> </h2>
<ol id="profile-posts" class="postboard-posts"> <ol id="profile-posts" class="postboard-posts">

22
home.html

@ -12,6 +12,8 @@
<script src="jquery.storageapi.js"></script> <script src="jquery.storageapi.js"></script>
<script src="mobile_abstract.js"></script> <script src="mobile_abstract.js"></script>
<script src="twister_io.js"></script> <script src="twister_io.js"></script>
<script src="polyglot.min.js"></script>
<script src="interface_localization.js"></script>
<script src="twister_network.js"></script> <script src="twister_network.js"></script>
<script src="twister_user.js"></script> <script src="twister_user.js"></script>
<script src="twister_formatpost.js"></script> <script src="twister_formatpost.js"></script>
@ -106,9 +108,9 @@
<span class="mini-profile-view">View</span> <span class="mini-profile-view">View</span>
</div> </div>
<ul class="module profile-data"> <ul class="module profile-data">
<li><a href="#" class="open-profile-modal"><span class="posts-count">&nbsp;</span>Posts</a></li> <li><a href="#" class="open-profile-modal"><span class="posts-count">&nbsp;</span><span class="label">Posts</span></a></li>
<li><a href="following.html"><span class="following-count">&nbsp;</span>Following</a></li> <li><a href="following.html"><span class="following-count">&nbsp;</span><span class="label">Following</span></a></li>
<li><a href="#"><span class="followers-count">&nbsp;</span>Followers *</a></li> <li><a href="#"><span class="followers-count">&nbsp;</span><span class="label">Followers</span> *</a></li>
</ul> </ul>
<div class="post-area"> <div class="post-area">
@ -143,7 +145,7 @@
<h2> <h2>
Postboard Postboard
<!-- o botão de novas postagens deve ser ocultado quando o usuário clicá-lo via javascript --> <!-- o botão de novas postagens deve ser ocultado quando o usuário clicá-lo via javascript -->
<button class="postboard-news" style="display: none;">5 novos posts</button> <button class="postboard-news" style="display: none;"></button>
</h2> </h2>
<ol id="posts" class="postboard-posts"> <ol id="posts" class="postboard-posts">
@ -354,9 +356,9 @@
</div> </div>
</div> </div>
<ul class="module profile-data"> <ul class="module profile-data">
<li><a href="#"><span class="posts-count">&nbsp;</span>Posts</a></li> <li><a href="#"><span class="posts-count">&nbsp;</span><span class="label">Posts</span></a></li>
<li><a href="#" class="open-following-modal"><span class="following-count">&nbsp;</span>Following</a></li> <li><a href="#" class="open-following-modal"><span class="following-count">&nbsp;</span><span class="label">Following</span></a></li>
<li><a href="#"><span class="followers-count">&nbsp;</span>Followers</a></li> <li><a href="#"><span class="followers-count">&nbsp;</span><span class="label">Followers</span></a></li>
</ul> </ul>
<button class="follow" href="#">Follow</button> <button class="follow" href="#">Follow</button>
<button class="direct-messages-with-user" href="#">Direct Messages</button> <button class="direct-messages-with-user" href="#">Direct Messages</button>
@ -369,7 +371,7 @@
<h2> <h2>
Posts Posts
<!-- o botão de novas postagens deve ser ocultado quando o usuário clicá-lo via javascript --> <!-- o botão de novas postagens deve ser ocultado quando o usuário clicá-lo via javascript -->
<button class="postboard-news" style="display:none;">5 novos posts</button> <button class="postboard-news" style="display:none;"></button>
</h2> </h2>
<ol id="profile-posts" class="postboard-posts"> <ol id="profile-posts" class="postboard-posts">
@ -389,7 +391,7 @@
<h2> <h2>
Posts Posts
<!-- o botão de novas postagens deve ser ocultado quando o usuário clicá-lo via javascript --> <!-- o botão de novas postagens deve ser ocultado quando o usuário clicá-lo via javascript -->
<button class="postboard-news" style="display:none;">5 novos posts</button> <button class="postboard-news" style="display:none;"></button>
</h2> </h2>
<ol id="profile-posts" class="postboard-posts"> <ol id="profile-posts" class="postboard-posts">
@ -403,7 +405,7 @@
<!-- MODAL DE FOLLOWING --> <!-- MODAL DE FOLLOWING -->
<div id="following-modal-template"> <div id="following-modal-template">
<!-- ÁREA DE PROFILE PHOTO INIT --> <!-- ÁREA DE PROFILE PHOTO INIT -->
<h2>All users publicly followed by <span class="following-screen-name">@<b></b></span></h2> <h2><span class="label">All users publicly followed by<span><span class="following-screen-name">@<b></b></span></h2>
<!-- ÁREA DE PROFILE END --> <!-- ÁREA DE PROFILE END -->
<!-- ÁREA DE FOLLOWING INIT --> <!-- ÁREA DE FOLLOWING INIT -->

1
index.html

@ -22,7 +22,6 @@
}); });
</script> </script>
<script src="jquery.mobile-1.3.2.min.js"></script> <script src="jquery.mobile-1.3.2.min.js"></script>
<link rel="icon" type="image/png" href="img/twister_mini.png" /> <link rel="icon" type="image/png" href="img/twister_mini.png" />
</head> </head>
<body> <body>

45
interface_common.js

@ -48,10 +48,7 @@ function checkNetworkStatusAndAskRedirect(cbFunc, cbArg) {
networkUpdate(function(args) { networkUpdate(function(args) {
if( !twisterdConnectedAndUptodate ) { if( !twisterdConnectedAndUptodate ) {
var redirect = var redirect =
window.confirm("Local daemon is not connected to the network or\n" + window.confirm(polyglot.t("switch_to_network"));
"block chain is outdated. If you stay in this page\n" +
"your actions may not work.\n" +
"Do you want to check Network Status page instead?");
if( redirect ) if( redirect )
$.MAL.goNetwork(); $.MAL.goNetwork();
} else { } else {
@ -73,31 +70,19 @@ function timeSincePost(t) {
var now = new Date(); var now = new Date();
var t_delta = Math.ceil((now - d) / 1000); var t_delta = Math.ceil((now - d) / 1000);
var expression = ""; var expression = "";
if(t_delta < 2) { if(t_delta < 60) {
expression = "1 second" expression = polyglot.t("seconds", { seconds: t_delta });
}
else if(t_delta < 60) {
expression = t_delta + " seconds"
}
else if(t_delta < 120) {
expression = "1 second"
} }
else if(t_delta < 60 * 60) { else if(t_delta < 60 * 60) {
expression = Math.floor(t_delta/60) + " minutes" expression = polyglot.t("minutes", { minutes: Math.floor(t_delta/60) });
}
else if(t_delta < 2 * 60 * 60) {
expression = "1 hour"
} }
else if(t_delta < 24 * 60 * 60) { else if(t_delta < 24 * 60 * 60) {
expression = Math.floor(t_delta/60/60) + " hours" expression = polyglot.t("hours", { hours: Math.floor(t_delta/60/60) });
}
else if(t_delta < 2 * 24 * 60 * 60) {
expression = "1 day"
} }
else { else {
expression = Math.floor(t_delta/24/60/60) + " days" expression = polyglot.t("days", { days: Math.floor(t_delta/24/60/60) });
} }
return expression + " ago"; return polyglot.t("time_ago", { time: expression });
} }
// //
@ -127,7 +112,7 @@ function openProfileModal(e)
profileModalContent.appendTo("." +profileModalClass + " .modal-content"); profileModalContent.appendTo("." +profileModalClass + " .modal-content");
//título do modal //título do modal
$( "."+profileModalClass + " h3" ).text( username + "'s Profile" ); $( "."+profileModalClass + " h3" ).text( polyglot.t("users_profile", { username: username }) );
} }
function newHashtagModal(hashtag) { function newHashtagModal(hashtag) {
@ -194,7 +179,7 @@ function openMentionsModal(e)
hashtagModalContent.appendTo("." +hashtagModalClass + " .modal-content"); hashtagModalContent.appendTo("." +hashtagModalClass + " .modal-content");
//título do modal //título do modal
$( "."+hashtagModalClass + " h3" ).text( "Mentions of @" + username ); $( "."+hashtagModalClass + " h3" ).text( polyglot.t("users_mentions", { username: username }) );
resetMentionsCount(); resetMentionsCount();
} }
@ -222,7 +207,7 @@ function openFollowingModal(e)
followingModalContent.appendTo("." +followingModalClass + " .modal-content"); followingModalContent.appendTo("." +followingModalClass + " .modal-content");
//título do modal //título do modal
$( "."+followingModalClass + " h3" ).text( "Followed by " + username ); $( "."+followingModalClass + " h3" ).text( polyglot.t("followed_by", { username: username }) );
} }
// //
@ -235,7 +220,7 @@ var reTwistPopup = function( e )
openModal( reTwistClass ); openModal( reTwistClass );
//título do modal //título do modal
$( ".reTwist h3" ).text( "Retransmit this post to your followers?" ); $( ".reTwist h3" ).text( polyglot.t("retransmit_this") );
var postdata = $(this).parents(".post-data").attr("data-userpost"); var postdata = $(this).parents(".post-data").attr("data-userpost");
var postElem = postToElem($.evalJSON(postdata),""); var postElem = postToElem($.evalJSON(postdata),"");
@ -252,7 +237,7 @@ var replyInitPopup = function(e, post)
//título do modal //título do modal
var fullname = post.find(".post-info-name").text(); var fullname = post.find(".post-info-name").text();
$( ".reply h3" ).text( "Reply to " + fullname); $( ".reply h3" ).text( polyglot.t("reply_to", { fullname: fullname }) );
//para poder exibir a thread selecionada... //para poder exibir a thread selecionada...
var replyModalContent = $(".reply .modal-content").hide(); var replyModalContent = $(".reply .modal-content").hide();
@ -307,7 +292,7 @@ var postExpandFunction = function( e, postLi )
originalPost.detach(); originalPost.detach();
postLi.empty(); postLi.empty();
postLi.addClass( openClass ); postLi.addClass( openClass );
$postInteractionText.text( "Collapse" ); $postInteractionText.text( polyglot.t("Collapse") );
var itemOl = $("<ol/>", {class:"expanded-post"}).appendTo(postLi); var itemOl = $("<ol/>", {class:"expanded-post"}).appendTo(postLi);
var originalLi = $("<li/>", {class: "module post original"}).appendTo(itemOl); var originalLi = $("<li/>", {class: "module post original"}).appendTo(itemOl);
@ -325,7 +310,7 @@ var postExpandFunction = function( e, postLi )
else else
{ {
postLi.removeClass( openClass ); postLi.removeClass( openClass );
$postInteractionText.text( "Expand" ); $postInteractionText.text( polyglot.t("Expand") );
if( $postsRelated ) $postsRelated.slideUp( "fast" ); if( $postsRelated ) $postsRelated.slideUp( "fast" );
$postExpandedContent.slideUp( "fast", function() $postExpandedContent.slideUp( "fast", function()
@ -426,7 +411,7 @@ var postSubmit = function(e)
newPostMsg($replyText.val(), $postOrig); newPostMsg($replyText.val(), $postOrig);
$replyText.val(""); $replyText.val("");
$replyText.attr("placeholder", "Your message was sent!"); $replyText.attr("placeholder", polyglot.t("Your message was sent!"));
closeModal($this); closeModal($this);
} }

2
interface_home.js

@ -23,7 +23,7 @@ var InterfaceFunctions = function()
function initHome(cbFunc, cbArg) { function initHome(cbFunc, cbArg) {
if( !defaultScreenName ) { if( !defaultScreenName ) {
alert("Username undefined, login required."); alert(polyglot.t("username_undefined"));
$.MAL.goLogin(); $.MAL.goLogin();
return; return;
} }

226
interface_localization.js

@ -0,0 +1,226 @@
// interface_localization.js
//
// uses JavaScript to detect browser language
// uses Polyglot.js ( https://github.com/airbnb/polyglot.js ) to translate interface
// translators: add your language code here such as "es" for Spanish, "ru" for Russian
var knownLanguages = ["en"];
// detect language with JavaScript
var preferredLanguage = window.navigator.userLanguage || window.navigator.language || "en";
if(knownLanguages.indexOf(preferredLanguage) > -1){
// en for en or similar
preferredLanguage = preferredLanguage;
}
else if(knownLanguages.indexOf(preferredLanguage.split("-")[0]) > -1){
// en for en-US or similar
preferredLanguage = preferredLanguage.split("-")[0];
}
else{
// did not find match
preferredLanguage = "en";
}
// set up Polyglot
polyglot = new Polyglot();
var wordset = {};
if(preferredLanguage == "en"){
polyglot.locale("en");
wordset = {
"Actions ▼": "Actions ▼",
"Active DHT nodes:": "Active DHT nodes: ",
"Add DNS": "Add DNS",
"Add peer": "Add peer",
"ajax_error": "Ajax error: %{error}", // JavaScript error
"All users publicly followed by": "All users publicly followed by",
"Available": "Available", // username is available
"Block chain information": "Block chain information",
"Block chain is up-to-date, twister is ready to use!": "Block chain is up-to-date, twister is ready to use!",
"Block generation": "Block generation ",
"Cancel": "Cancel",
"Change user": "Change user",
"Checking...": "Checking...", // checking if username is available
"Collapse": "Collapse", // smaller view of a post
"Configure block generation": "Configure block generation",
"Connections:": "Connections: ", // to network
"Connection lost.": "Connection lost.",
"days": "%{days} day |||| %{days} days",
"Detailed information": "Detailed information",
"DHT network down.": "DHT network down.",
"Direct Messages": "Direct Messages",
"Disable": "Disable",
"Display mentions to @": "Display mentions to @",
"Display retransmissions": "Display retransmissions",
"DNS to obtain list of peers:": "DNS to obtain list of peers:",
"downloading_block_chain": "Downloading block chain, please wait before continuing (block chain is %{days} days old).",
"download_posts_status": "Downloaded %{portion} posts", // Downloaded 10/30 posts
"Enable": "Enable",
"error": "Error: %{error}",
"error_connecting_to_daemon": "Error connecting to local twister daemon.",
"Error in 'createwalletuser' RPC.": "Error in 'createwalletuser' RPC.",
"Error in 'importprivkey'": "Error in 'importprivkey' RPC: %{rpc}",
"Error in 'sendnewusertransaction' RPC.": "Error in 'sendnewusertransaction' RPC.",
"Expand": "Expand", // larger view of a post
"Favorite": "Favorite",
"File APIs not supported in this browser.": "File APIs not supported in this browser.",
"Follow": "Follow",
"Followed by": "Followed by",
"followed_by": "Followed by %{username}",
"Followers": "Followers",
"Following": "Following",
"Following users": "Following users",
"Force connection to peer:": "Force connection to peer:",
"General information": "General information",
"Generate blocks (send promoted messages)": "Generate blocks (send promoted messages)",
"Home": "Home", // homepage
"hours": "%{hours} hour |||| %{hours} hours",
"Internal error: lastPostId unknown (following yourself may fix!)": "Internal error: lastPostId unknown (following yourself may fix!)",
"Known peers:": "Known peers: ",
"Last block is ahead of your computer time, check your clock.": "Last block is ahead of your computer time, check your clock.",
"mentions_at": "Mentions @%{user}",
"minutes": "%{minutes} minute |||| %{minutes} minutes",
"Must be 16 characters or less.": "Must be 16 characters or less.", // username
"Network": "Network",
"Network config": "Network config",
"Network status": "Network status",
"New direct message...": "New direct message...",
"New Post...": "New Post...",
"new_posts": "%{count} new post |||| %{count} new posts",
"nobody": "nobody", // used to promote a post without attaching the user
"Not available": "Not available", // username is not available
"Number of blocks in block chain:": "Number of blocks in block chain: ",
"Number of CPUs to use": "Number of CPUs to use ",
"Only alphanumeric and underscore allowed.": "Only alphanumeric and underscore allowed.",
"peer address": "peer address",
"Private": "Private",
"Profile": "Profile",
"Postboard": "Postboard",
"post": "post", // verb - button to post a message
"Post to promote:": "Post to promote: ",
"Posts": "Posts",
"propagating_nickname": "Propagating nickname %{username} to the network...",
"Public": "Public",
"Refresh": "Refresh",
"retransmit_this": "Retransmit this post to your followers?",
"Reply": "Reply",
"Reply...": "Reply...",
"reply_to": "Reply to %{fullname}",
"Retransmit": "Retransmit",
"Retransmits": "Retransmits",
"Retransmitted by": "Retransmitted by",
"search": "search",
"seconds": "%{seconds} second |||| %{seconds} seconds",
"send": "send",
"Send post with username": "Send post with username ",
"Sent Direct Message": "Sent Direct Message",
"Sent Post to @": "Sent Post to @",
"Setup account": "Setup account",
"switch_to_network": "Local daemon is not connected to the network or\n" +
"block chain is outdated. If you stay in this page\n" +
"your actions may not work.\n" +
"Do you want to check Network Status page instead?",
"The File APIs are not fully supported in this browser.": "The File APIs are not fully supported in this browser.",
"time_ago": "%{time} ago", // 5 minutes ago
"Time of the last block:": "Time of the last block: ",
"Type message here": "Type message here",
"Unfollow": "Unfollow",
"Update": "Update",
"Updating status...": "Updating status...", // status of block chain
"user_not_yet_accepted": "Other peers have not yet accepted this new user.\n" +
"Unfortunately it is not possible to save profile\n" +
"or send any posts in this state.\n\n" +
"Please wait a few minutes to continue.\n\n" +
"The 'Save Changes' will be automatically enabled\n" +
"when the process completes. (I promise this is\n"+
"the last time you will have to wait before using\n" +
"twister).\n\n" +
"Tip: choose your avatar in the meantime!",
"users_mentions": "Mentions of @%{username}",
"users_profile": "%{username}'s Profile",
"username_undefined": "Username undefined, login required.",
"View": "View",
"View All": "View All",
"Who to Follow": "Who to Follow",
"Your message was sent!": "Your message was sent!"
};
}
// translators: sample adding a language
if(preferredLanguage == "ru"){
// polyglot.locale() is used to support plurals
// locales currently known by Polyglot.js:
/*
chinese: ['id', 'ja', 'ko', 'ms', 'th', 'tr', 'zh'],
german: ['da', 'de', 'en', 'es', 'fi', 'el', 'he', 'hu', 'it', 'nl', 'no', 'pt', 'sv'],
french: ['fr', 'tl'],
russian: ['hr', 'ru'],
czech: ['cs'],
polish: ['pl'],
icelandic: ['is']
*/
polyglot.locale("ru");
// list of the English words and translations
wordset = {
"Actions ▼": "Действия ▼" // , comma after each match except the last
};
}
// uncomment to see all translated words replaced with filler
//for(var word in wordset){
// wordset[word] = "AAAA";
//}
polyglot.extend(wordset);
// Text from HTML and not JavaScript is selected and translated at $(document).ready
// Add selectors here to translate the text and placeholders inside new UI
var fixedLabels = [
// An easy way to include new items in translation is to add the "label" class
".label",
// navbar and home
"button",
".userMenu > ul > li > a",
".postboard-news",
".post-area-new textarea",
".refresh-users, .view-all-users",
".who-to-follow h3",
".userMenu-search-field",
"a.dropdown-menu-item, a.direct-messages",
".post-interactions span",
".post-expand",
".post-context span",
".post-stats .stat-count span",
".postboard h2",
// following page
".following h2",
".mini-profile-actions span, .mini-profile-actions li",
// network page
".network h2, .network h3",
".network ul li span",
".network label",
".network textarea, .network input, .network option",
];
$(document).ready(function(){
for(var i=0;i<fixedLabels.length;i++){
var elems = $(fixedLabels[i]);
for(var e=0;e<elems.length;e++){
var content = $.trim($(elems[e]).text());
if(wordset[content]){
$(elems[e]).text( polyglot.t(content) );
}
else{
// uncomment to see translations not found
//console.log(content);
}
if(typeof $(elems[e]).attr("placeholder") != "undefined" && wordset[ $(elems[e]).attr("placeholder")]){
$(elems[e]).attr("placeholder", polyglot.t( $(elems[e]).attr("placeholder") ) );
}
}
}
});

2
interface_login.js

@ -13,7 +13,7 @@ function processCreateUser(username, secretKey) {
openModal( newUserClass ); openModal( newUserClass );
//título do modal //título do modal
$( "." + newUserClass + " h3" ).text( "Propagating nickname '"+ username + "' to the network..." ); $( "." + newUserClass + " h3" ).text( polyglot.t("propagating_nickname", { username: username }) );
var modalContent = $("." + newUserClass + " .modal-content"); var modalContent = $("." + newUserClass + " .modal-content");
var templateContent = $( "#new-user-modal-template" ).children().clone(true); var templateContent = $( "#new-user-modal-template" ).children().clone(true);

14
interface_profile-edit.js

@ -10,7 +10,7 @@ function initProfileEdit() {
if (window.File && window.FileReader && window.FileList && window.Blob) { if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported. // Great success! All the File APIs are supported.
} else { } else {
alert('The File APIs are not fully supported in this browser.'); alert(polyglot.t("The File APIs are not fully supported in this browser."));
} }
initInterfaceCommon(); initInterfaceCommon();
@ -22,7 +22,7 @@ function initProfileEdit() {
initUser( function() { initUser( function() {
if( !defaultScreenName ) { if( !defaultScreenName ) {
alert("Username undefined, login required."); alert(polyglot.t("username_undefined"));
$.MAL.goLogin(); $.MAL.goLogin();
return; return;
} }
@ -91,15 +91,7 @@ function verifyUserAlreadyInBlockchain()
}); });
} else { } else {
if( !newUserWarnDisplayed ) { if( !newUserWarnDisplayed ) {
alert("Other peers have not yet accepted this new user.\n" + alert(polyglot.t("user_not_yet_accepted"));
"Unfortunately it is not possible to save profile\n" +
"or send any posts in this state.\n\n" +
"Please wait a few minutes to continue.\n\n" +
"The 'Save Changes' will be automatically enabled\n" +
"when the process completes. (I promise this is\n"+
"the last time you will have to wait before using\n" +
"twister).\n\n" +
"Tip: choose your avatar in the meantime!");
newUserWarnDisplayed = true; newUserWarnDisplayed = true;
} }
setTimeout("verifyUserAlreadyInBlockchain()", 5000); setTimeout("verifyUserAlreadyInBlockchain()", 5000);

2
network.html

@ -15,6 +15,8 @@
<script src="twister_formatpost.js"></script> <script src="twister_formatpost.js"></script>
<script src="twister_following.js"></script> <script src="twister_following.js"></script>
<script src="twister_newmsgs.js"></script> <script src="twister_newmsgs.js"></script>
<script src="polyglot.min.js"></script>
<script src="interface_localization.js"></script>
<script src="twister_network.js"></script> <script src="twister_network.js"></script>
<script src="interface_common.js"></script> <script src="interface_common.js"></script>

17
polyglot.min.js vendored

@ -0,0 +1,17 @@
// (c) 2012 Airbnb, Inc.
//
// polyglot.js may be freely distributed under the terms of the BSD
// license. For all licensing information, details, and documention:
// http://airbnb.github.com/polyglot.js
//
//
// Polyglot.js is an I18n helper library written in JavaScript, made to
// work both in the browser and in Node. It provides a simple solution for
// interpolation and pluralization, based off of Airbnb's
// experience adding I18n functionality to its Backbone.js and Node apps.
//
// Polylglot is agnostic to your translation backend. It doesn't perform any
// translation; it simply gives you a way to manage translated phrases from
// your client- or server-side JavaScript application.
//
!function(e){"use strict";function t(e){e=e||{},this.phrases=e.phrases||{},this.currentLocale=e.locale||"en",this.allowMissing=!!e.allowMissing}function s(e){var t,n,r,i={};for(t in e)if(e.hasOwnProperty(t)){n=e[t];for(r in n)i[n[r]]=t}return i}function o(e){var t=/^\s+|\s+$/g;return e.replace(t,"")}function u(e,t,r){var i,s,u;return r!=null&&e?(s=e.split(n),u=s[f(t,r)]||s[0],i=o(u)):i=e,i}function a(e){var t=s(i);return t[e]||t.en}function f(e,t){return r[a(e)](t)}function l(e,t){for(var n in t)n!=="_"&&t.hasOwnProperty(n)&&(e=e.replace(new RegExp("%\\{"+n+"\\}","g"),t[n]));return e}function c(t){e.console&&e.console.warn&&e.console.warn("WARNING: "+t)}function h(e){var t={};for(var n in e)t[n]=e[n];return t}t.VERSION="0.2.0",t.prototype.locale=function(e){return e&&(this.currentLocale=e),this.currentLocale},t.prototype.extend=function(e){for(var t in e)e.hasOwnProperty(t)&&(this.phrases[t]=e[t])},t.prototype.clear=function(){this.phrases={}},t.prototype.replace=function(e){this.clear(),this.extend(e)},t.prototype.t=function(e,t){var n;t=t==null?{}:t,typeof t=="number"&&(t={smart_count:t});var r=this.phrases[e]||t._||(this.allowMissing?e:"");return r===""?(c('Missing translation for key: "'+e+'"'),n=e):(t=h(t),n=u(r,this.currentLocale,t.smart_count),n=l(n,t)),n};var n="||||",r={chinese:function(e){return 0},german:function(e){return e!==1?1:0},french:function(e){return e>1?1:0},russian:function(e){return e%10===1&&e%100!==11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2},czech:function(e){return e===1?0:e>=2&&e<=4?1:2},polish:function(e){return e===1?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2},icelandic:function(e){return e%10!==1||e%100===11?1:0}},i={chinese:["id","ja","ko","ms","th","tr","zh"],german:["da","de","en","es","fi","el","he","hu","it","nl","no","pt","sv"],french:["fr","tl"],russian:["hr","ru"],czech:["cs"],polish:["pl"],icelandic:["is"]};typeof module!="undefined"&&module.exports?module.exports=t:e.Polyglot=t}(this);

8
tmobile.js

@ -180,7 +180,7 @@ var router=new $.mobile.Router(
var params=router.getParams(match[1]); var params=router.getParams(match[1]);
initializeTwister( true, true, function() { initializeTwister( true, true, function() {
var $replyTextarea = $("#newmsg .post-area-new textarea"); var $replyTextarea = $("#newmsg .post-area-new textarea");
$replyTextarea.attr("placeholder", "New Post..."); $replyTextarea.attr("placeholder", polyglot.t("New Post..."));
if( params && params.hasOwnProperty("replyto") ) { if( params && params.hasOwnProperty("replyto") ) {
$replyTextarea.val(params.replyto); $replyTextarea.val(params.replyto);
} else { } else {
@ -227,7 +227,7 @@ var router=new $.mobile.Router(
$newmsgLink.attr("href","#newmsg"); $newmsgLink.attr("href","#newmsg");
resetMentionsCount(); resetMentionsCount();
} }
$("#mentions .rtitle").text("Mentions @" + user); $("#mentions .rtitle").text(polyglot.t("mentions_at", { user: user }));
var $ulMentions = $("#mentions ul.posts"); var $ulMentions = $("#mentions ul.posts");
setupHashtagOrMention( $ulMentions, user, "mention"); setupHashtagOrMention( $ulMentions, user, "mention");
}); });
@ -375,7 +375,7 @@ function installSubmitClick() {
newPostMsg(s, $postOrig); newPostMsg(s, $postOrig);
$replyText.val(""); $replyText.val("");
$replyText.attr("placeholder", "Your message was sent!"); $replyText.attr("placeholder", polyglot.t("Your message was sent!"));
setTimeout( function() {$.MAL.goHome();}, 1000); setTimeout( function() {$.MAL.goHome();}, 1000);
}); });
@ -451,7 +451,7 @@ function handleAvatarFileSelectMobile(evt) {
try { try {
reader = new FileReader(); reader = new FileReader();
} catch(e) { } catch(e) {
alert('File APIs not supported in this browser.'); alert(polyglot.t('File APIs not supported in this browser.'));
return; return;
} }

10
twister_actions.js

@ -130,9 +130,9 @@ function newPostMsg(msg, $postOrig) {
twisterRpc("newpostmsg", params, twisterRpc("newpostmsg", params,
function(arg, ret) { incLastPostId(); }, null, function(arg, ret) { incLastPostId(); }, null,
function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret; function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret;
alert("Ajax error: " + msg); }, null); alert(polyglot.t("ajax_error", { error: msg })); }, null);
} else { } else {
alert("Internal error: lastPostId unknown (following yourself may fix!)"); alert(polyglot.t("Internal error: lastPostId unknown (following yourself may fix!)"));
} }
} }
@ -150,9 +150,9 @@ function newRtMsg($postOrig) {
twisterRpc("newrtmsg", params, twisterRpc("newrtmsg", params,
function(arg, ret) { incLastPostId(); }, null, function(arg, ret) { incLastPostId(); }, null,
function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret; function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret;
alert("Ajax error: " + msg); }, null); alert(polyglot.t("ajax_error", { error: msg })); }, null);
} else { } else {
alert("Internal error: lastPostId unknown (following yourself may fix!)"); alert(polyglot.t("Internal error: lastPostId unknown (following yourself may fix!)"));
} }
} }
@ -214,7 +214,7 @@ function processHashtag(postboard, hashtag, data) {
displayHashtagPending(postboard); displayHashtagPending(postboard);
} else { } else {
var newTweetsBar = postboard.closest("div").find(".postboard-news"); var newTweetsBar = postboard.closest("div").find(".postboard-news");
newTweetsBar.text(String(_hashtagPendingPosts.length) + " new posts"); newTweetsBar.text(polyglot.t("new_posts", { count: _hashtagPendingPosts.length }));
newTweetsBar.fadeIn("slow"); newTweetsBar.fadeIn("slow");
} }
} }

6
twister_directmsg.js

@ -59,7 +59,7 @@ function requestDmConversation(dmConvo,dm_screenname) {
function(args, ret) { processDmConversation(args.dmConvo, args.dmUser, ret); }, function(args, ret) { processDmConversation(args.dmConvo, args.dmUser, ret); },
{dmConvo:dmConvo,dmUser:dm_screenname}, {dmConvo:dmConvo,dmUser:dm_screenname},
function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret; function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret;
alert("Ajax error: " + msg); }, null); alert(polyglot.t("ajax_error", { error: msg })); }, null);
} }
function processDmConversation(dmConvo, dm_screenname, dmData) { function processDmConversation(dmConvo, dm_screenname, dmData) {
@ -103,7 +103,7 @@ function newDirectMsg(msg, dm_screenname) {
function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret; function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret;
alert("Ajax error: " + msg); }, null); alert("Ajax error: " + msg); }, null);
} else { } else {
alert("Internal error: lastPostId unknown (following yourself may fix!)"); alert(polyglot.t("Internal error: lastPostId unknown (following yourself may fix!)"));
} }
} }
@ -117,7 +117,7 @@ function directMessagesPopup()
$( directMessagesContent ).clone().appendTo( ".directMessages .modal-content" ); $( directMessagesContent ).clone().appendTo( ".directMessages .modal-content" );
//título do modal //título do modal
$( ".directMessages h3" ).text( "Direct Messages" ); $( ".directMessages h3" ).text( polyglot.t("Direct Messages") );
requestDMsnippetList($(".directMessages").find(".direct-messages-list")); requestDMsnippetList($(".directMessages").find(".direct-messages-list"));
} }

8
twister_following.js

@ -472,9 +472,9 @@ function followingListPublicCheckbox(e) {
var public = false; var public = false;
$this.toggleClass( "private" ); $this.toggleClass( "private" );
if( $this.hasClass( "private" ) ) { if( $this.hasClass( "private" ) ) {
$this.text( "Private" ); $this.text( polyglot.t("Private") );
} else { } else {
$this.text( "Public" ); $this.text( polyglot.t("Public") );
public = true; public = true;
} }
@ -507,7 +507,7 @@ function processSwarmProgressFinal(lastHaves, numPieces)
var $userDiv = $(".mini-profile-info[data-screen-name='" + user + "']"); var $userDiv = $(".mini-profile-info[data-screen-name='" + user + "']");
if( $userDiv.length ) { if( $userDiv.length ) {
var $status = $userDiv.find(".swarm-status"); var $status = $userDiv.find(".swarm-status");
$status.text("Downloaded " + numPieces[user] + "/" + (lastHaves[user]+1) + " posts"); $status.text(polyglot.t("download_posts_status", { portion: numPieces[user] + "/" + (lastHaves[user]+1) }));
$status.fadeIn(); $status.fadeIn();
} }
} }
@ -535,7 +535,7 @@ function initInterfaceFollowing() {
initUser( function() { initUser( function() {
if( !defaultScreenName ) { if( !defaultScreenName ) {
alert("Username undefined, login required."); alert(polyglot.t("username_undefined"));
$.MAL.goLogin(); $.MAL.goLogin();
return; return;
} }

6
twister_io.js

@ -290,7 +290,7 @@ function clearAvatarAndProfileCache(username) {
function getFollowers( username, item ) { function getFollowers( username, item ) {
dhtget( username, "tracker", "m", dhtget( username, "tracker", "m",
function(args, ret) { function(args, ret) {
if( ret.length && ret[0]["followers"] ) { if( ret && ret.length && ret[0]["followers"] ) {
args.item.text(ret[0]["followers"]) args.item.text(ret[0]["followers"])
} }
}, {username:username,item:item} ); }, {username:username,item:item} );
@ -322,7 +322,7 @@ function checkPubkeyExists(username, cbFunc, cbArg) {
args.cbFunc(args.cbArg, ret.length > 0); args.cbFunc(args.cbArg, ret.length > 0);
}, {cbFunc:cbFunc, cbArg:cbArg}, }, {cbFunc:cbFunc, cbArg:cbArg},
function(args, ret) { function(args, ret) {
alert("Error connecting to local twister deamon."); alert(polyglot.t("error_connecting_to_daemon"));
}, {cbFunc:cbFunc, cbArg:cbArg}); }, {cbFunc:cbFunc, cbArg:cbArg});
} }
@ -336,7 +336,7 @@ function dumpPubkey(username, cbFunc, cbArg) {
args.cbFunc(args.cbArg, ret); args.cbFunc(args.cbArg, ret);
}, {cbFunc:cbFunc, cbArg:cbArg}, }, {cbFunc:cbFunc, cbArg:cbArg},
function(args, ret) { function(args, ret) {
alert("Error connecting to local twister deamon."); alert(polyglot.t("error_connecting_to_daemon"));
}, {cbFunc:cbFunc, cbArg:cbArg}); }, {cbFunc:cbFunc, cbArg:cbArg});
} }

17
twister_network.js

@ -27,7 +27,7 @@ function requestNetInfo(cbFunc, cbArg) {
$(".dht-nodes").text(twisterDhtNodes); $(".dht-nodes").text(twisterDhtNodes);
if( !twisterdConnections ) { if( !twisterdConnections ) {
$.MAL.setNetworkStatusMsg("Connection lost.", false); $.MAL.setNetworkStatusMsg(polyglot.t("Connection lost."), false);
twisterdConnectedAndUptodate = false; twisterdConnectedAndUptodate = false;
} }
@ -66,7 +66,7 @@ function addPeerClick() {
$(".new-peer-addr").val("") $(".new-peer-addr").val("")
}, {}, }, {},
function(args, ret) { function(args, ret) {
alert("Error: " + ret.message); alert(polyglot.t("error", { error: ret.message }));
}, {}); }, {});
} }
@ -77,7 +77,7 @@ function addDNSClick() {
$(".new-dns-addr").val("") $(".new-dns-addr").val("")
}, {}, }, {},
function(args, ret) { function(args, ret) {
alert("Error: " + ret.message); alert(polyglot.t("error", { error: ret.message }));
}, {}); }, {});
} }
@ -112,22 +112,19 @@ function networkUpdate(cbFunc, cbArg) {
var curTime = new Date().getTime() / 1000; var curTime = new Date().getTime() / 1000;
if( twisterdConnections ) { if( twisterdConnections ) {
if( twisterdLastBlockTime > curTime + 3600 ) { if( twisterdLastBlockTime > curTime + 3600 ) {
$.MAL.setNetworkStatusMsg("Last block is ahead of your computer time, check your clock.", false); $.MAL.setNetworkStatusMsg(polyglot.t("Last block is ahead of your computer time, check your clock."), false);
twisterdConnectedAndUptodate = false; twisterdConnectedAndUptodate = false;
} else if( twisterdLastBlockTime > curTime - (2 * 3600) ) { } else if( twisterdLastBlockTime > curTime - (2 * 3600) ) {
if( twisterDhtNodes ) { if( twisterDhtNodes ) {
$.MAL.setNetworkStatusMsg("Block chain is up-to-date, twister is ready to use!", true); $.MAL.setNetworkStatusMsg(polyglot.t("Block chain is up-to-date, twister is ready to use!"), true);
twisterdConnectedAndUptodate = true; twisterdConnectedAndUptodate = true;
} else { } else {
$.MAL.setNetworkStatusMsg("DHT network down.", false); $.MAL.setNetworkStatusMsg(polyglot.t("DHT network down."), false);
twisterdConnectedAndUptodate = true; twisterdConnectedAndUptodate = true;
} }
} else { } else {
var daysOld = (curTime - twisterdLastBlockTime) / (3600*24); var daysOld = (curTime - twisterdLastBlockTime) / (3600*24);
$.MAL.setNetworkStatusMsg("Downloading block chain, please wait before continuing " + $.MAL.setNetworkStatusMsg(polyglot.t("downloading_block_chain", { days: daysOld.toFixed(2) }), false);
"(block chain is " +
daysOld.toFixed(2) +
" days old).", false);
twisterdConnectedAndUptodate = false; twisterdConnectedAndUptodate = false;
} }
} }

18
twister_user.js

@ -67,7 +67,7 @@ function loadWalletlUsers(cbFunc, cbArg) {
args.cbFunc(args.cbArg); args.cbFunc(args.cbArg);
}, {cbFunc:cbFunc, cbArg:cbArg}, }, {cbFunc:cbFunc, cbArg:cbArg},
function(args, ret) { function(args, ret) {
alert("Error connecting to local twister deamon."); alert(polyglot.t("error_connecting_to_daemon"));
}, {}); }, {});
} }
@ -103,25 +103,25 @@ function checkUsernameAvailability() {
if( !username.length ) if( !username.length )
return; return;
if( username.length > 16 ) { if( username.length > 16 ) {
$availField.text("Must be 16 characters or less."); $availField.text(polyglot.t("Must be 16 characters or less."));
return; return;
} }
//Check for non-alphabetic characters and space //Check for non-alphabetic characters and space
if(username.search(/[^a-z0-9_]/) != -1) { if(username.search(/[^a-z0-9_]/) != -1) {
$availField.text("Only alphanumeric and underscore allowed."); $availField.text(polyglot.t("Only alphanumeric and underscore allowed."));
return; return;
} }
$availField.text("Checking..."); $availField.text(polyglot.t("Checking..."));
dumpPubkey(username, function(dummy, pubkey) { dumpPubkey(username, function(dummy, pubkey) {
var notAvailable = pubkey.length > 0 var notAvailable = pubkey.length > 0
var $availField = $(".availability"); var $availField = $(".availability");
if( notAvailable ) { if( notAvailable ) {
$availField.text("Not available"); $availField.text(polyglot.t("Not available"));
} else { } else {
$availField.text("Available"); $availField.text(polyglot.t("Available"));
var $createButton = $(".create-user"); var $createButton = $(".create-user");
$.MAL.enableButton( $createButton ); $.MAL.enableButton( $createButton );
@ -147,7 +147,7 @@ function createUserClick(cbFunc) {
args.cbFunc(args.username, ret); args.cbFunc(args.username, ret);
}, {username:username, cbFunc:cbFunc}, }, {username:username, cbFunc:cbFunc},
function(args, ret) { function(args, ret) {
alert("Error in 'createwalletuser' RPC."); alert(polyglot.t("Error in 'createwalletuser' RPC."));
}, {cbFunc:cbFunc}); }, {cbFunc:cbFunc});
} else { } else {
// user exists in wallet but transaction not sent // user exists in wallet but transaction not sent
@ -164,7 +164,7 @@ function sendNewUserTransaction(username, cbFunc) {
args.cbFunc(); args.cbFunc();
}, {cbFunc:cbFunc}, }, {cbFunc:cbFunc},
function(args, ret) { function(args, ret) {
alert("Error in 'sendnewusertransaction' RPC."); alert(polyglot.t("Error in 'sendnewusertransaction' RPC."));
}, {}); }, {});
} }
@ -190,7 +190,7 @@ function importSecretKeyClick() {
processNewSecretKeyImported(args.username); processNewSecretKeyImported(args.username);
}, {username:username}, }, {username:username},
function(args, ret) { function(args, ret) {
alert("Error in 'importprivkey' RPC: " + ret.message); alert(polyglot.t("Error in 'importprivkey'", {rpc: ret.message }));
}, {}); }, {});
} }

Loading…
Cancel
Save