Skip to content

Commit

Permalink
Adding support to l10n
Browse files Browse the repository at this point in the history
  • Loading branch information
Luiza Pagliari committed May 27, 2015
1 parent f31c86d commit a437dbf
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 71 deletions.
42 changes: 42 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"ep_comments_page.comment" : "Comment",
"ep_comments_page.comments" : "Comments",
"ep_comments_page.cancel" : "Cancel",
"ep_comments_page.add_comment.title" : "Add new comment on selection",
"ep_comments_page.show_comments" : "Show Comments",
"ep_comments_page.comments_template.suggested_change" : "Suggested Change:",
"ep_comments_page.comments_template.accept_change" : "Accept Change",
"ep_comments_page.comments_template.suggest_change_from" : "Suggest change From:",
"ep_comments_page.comments_template.to" : "To:",
"ep_comments_page.comments_template.include_suggestion" : "Include suggested change",
"ep_comments_page.time.seconds_ago" : "{{count}} seconds ago",
"ep_comments_page.time.seconds_from_now" : "{{count}} seconds from now",
"ep_comments_page.time.one_minute_ago" : "1 minute ago",
"ep_comments_page.time.one_minute_from_now" : "1 minute from now",
"ep_comments_page.time.minutes_ago" : "{{count}} minutes ago",
"ep_comments_page.time.minutes_from_now" : "{{count}} minutes from now",
"ep_comments_page.time.one_hour_ago" : "1 hour ago",
"ep_comments_page.time.one_hour_from_now" : "1 hour from now",
"ep_comments_page.time.hours_ago" : "{{count}} hours ago",
"ep_comments_page.time.hours_from_now" : "{{count}} hours from now",
"ep_comments_page.time.yesterday" : "yesterday",
"ep_comments_page.time.tomorrow" : "tomorrow",
"ep_comments_page.time.days_ago" : "{{count}} days ago",
"ep_comments_page.time.days_from_now" : "{{count}} days from now",
"ep_comments_page.time.last_week" : "last week",
"ep_comments_page.time.next_week" : "next week",
"ep_comments_page.time.weeks_ago" : "{{count}} weeks ago",
"ep_comments_page.time.weeks_from_now" : "{{count}} weeks from now",
"ep_comments_page.time.last_month" : "last month",
"ep_comments_page.time.next_month" : "next month",
"ep_comments_page.time.months_ago" : "{{count}} months ago",
"ep_comments_page.time.months_from_now" : "{{count}} months from now",
"ep_comments_page.time.last_year" : "last year",
"ep_comments_page.time.next_year" : "next year",
"ep_comments_page.time.years_ago" : "{{count}} years ago",
"ep_comments_page.time.years_from_now" : "{{count}} years from now",
"ep_comments_page.time.last_century" : "last century",
"ep_comments_page.time.next_century" : "next century",
"ep_comments_page.time.centuries_ago" : "{{count}} centuries ago",
"ep_comments_page.time.centuries_from_now" : "{{count}} centuries from now"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
],
"dependencies": {
"formidable": "*",
"socket.io-client": "*"
"socket.io-client": "*",
"expect": "*"
},
"engines": {
"node": "*"
Expand Down
73 changes: 17 additions & 56 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ var _, $, jQuery;
var $ = require('ep_etherpad-lite/static/js/rjquery').$;
var _ = require('ep_etherpad-lite/static/js/underscore');
var padcookie = require('ep_etherpad-lite/static/js/pad_cookie').padcookie;
var prettyDate = require('ep_comments_page/static/js/timeFormat').prettyDate;

var cssFiles = ['ep_comments_page/static/css/comment.css'];

/************************************************************************/
/* ep_comments Plugin */
/************************************************************************/
// Container
// Container
function ep_comments(context){
this.container = null;
this.padOuter = null;
Expand Down Expand Up @@ -84,7 +85,7 @@ ep_comments.prototype.init = function(){
if( count_comments > padComment.length ) {
window.setTimeout(function() {
self.collectComments();

}, 9000);
}
}, 3000);
Expand All @@ -94,13 +95,13 @@ ep_comments.prototype.init = function(){
}, 300);
});

// On click comment icon toolbar
// On click comment icon toolbar
$('.addComment').on('click', function(e){
$('iframe[name="ace_outer"]').contents().find('#comments').show();
$('iframe[name="ace_outer"]').contents().find('#comments').addClass("active");
e.preventDefault(); // stops focus from being lost
// If a new comment box doesn't already exist
// Add a new comment and link it to the selection
// If a new comment box doesn't already exist
// Add a new comment and link it to the selection
// $('iframe[name="ace_outer"]').contents().find('#sidediv').removeClass('sidedivhidden');
if (self.container.find('#newComment').length == 0) self.addComment();
// console.log("setting focus to .comment-content");
Expand Down Expand Up @@ -199,7 +200,7 @@ ep_comments.prototype.init = function(){

};

// Insert comments container on element use for linenumbers
// Insert comments container on element use for linenumbers
ep_comments.prototype.findContainers = function(){
var padOuter = $('iframe[name="ace_outer"]').contents();
this.padOuter = padOuter;
Expand Down Expand Up @@ -258,10 +259,10 @@ ep_comments.prototype.collectComments = function(callback){
} else {
var prevCommentPos = prevCommentElm.css('top');
var prevCommentHeight = prevCommentElm.innerHeight();

commentPos = parseInt(prevCommentPos) + prevCommentHeight + 30;
}

commentElm.css({ 'top': commentPos });
});

Expand All @@ -276,7 +277,7 @@ ep_comments.prototype.collectComments = function(callback){
// on hover we should show the reply option
}).on("mouseout", ".sidebar-comment", function(e){
var commentId = e.currentTarget.id;
var inner = $('iframe[name="ace_outer"]').contents().find('iframe[name="ace_inner"]');
var inner = $('iframe[name="ace_outer"]').contents().find('iframe[name="ace_inner"]');
inner.contents().find("head").append("<style>."+commentId+"{ color:black }</style>");
// TODO this could potentially break ep_font_color
});
Expand Down Expand Up @@ -347,7 +348,7 @@ ep_comments.prototype.removeComment = function(className, id){

// Insert comment container in sidebar
ep_comments.prototype.insertContainer = function(){
// Add comments
// Add comments
$('iframe[name="ace_outer"]').contents().find("#outerdocbody").prepend('<div id="comments"></div>');
this.container = this.padOuter.find('#comments');
};
Expand Down Expand Up @@ -399,7 +400,7 @@ ep_comments.prototype.insertNewComment = function(comment, callback){
},'getYofRep', true);
};

// Insert a comment node
// Insert a comment node
ep_comments.prototype.insertComment = function(commentId, comment, index, isNew){
var template = (isNew === true) ? 'newCommentTemplate' : 'commentsTemplate';
var content = null;
Expand Down Expand Up @@ -478,13 +479,13 @@ ep_comments.prototype.getCommentReplies = function (callback){
ep_comments.prototype.getCommentData = function (){
var data = {};

// Insert comment data
// Insert comment data
data.padId = this.padId;
data.comment = {};
data.comment.author = clientVars.userId;
data.comment.name = clientVars.userName;
data.comment.timestamp = new Date().getTime();

// Si le client est Anonyme
// In English please? :P
if(data.comment.name === undefined){
Expand All @@ -494,7 +495,7 @@ ep_comments.prototype.getCommentData = function (){
return data;
}

// Add a pad comment
// Add a pad comment
ep_comments.prototype.addComment = function (callback){
var socket = this.socket;
var data = this.getCommentData();
Expand Down Expand Up @@ -550,7 +551,7 @@ ep_comments.prototype.addComment = function (callback){
// Save comment
socket.emit('addComment', data, function (commentId, comment){
comment.commentId = commentId;

//callback(commentId);
ace.callWithAce(function (ace){
// console.log('addComment :: ', commentId);
Expand Down Expand Up @@ -630,7 +631,7 @@ ep_comments.prototype.pushComment = function(eventType, callback){

var hooks = {

// Init pad comments
// Init pad comments
postAceInit: function(hook, context){
if(!pad.plugins) pad.plugins = {};
var Comments = new ep_comments(context);
Expand Down Expand Up @@ -671,46 +672,6 @@ var hooks = {

};

function prettyDate(time){
var time_formats = [
[60, 'seconds', 1], // 60
[120, '1 minute ago', '1 minute from now'], // 60*2
[3600, 'minutes', 60], // 60*60, 60
[7200, '1 hour ago', '1 hour from now'], // 60*60*2
[86400, 'hours', 3600], // 60*60*24, 60*60
[172800, 'yesterday', 'tomorrow'], // 60*60*24*2
[604800, 'days', 86400], // 60*60*24*7, 60*60*24
[1209600, 'last week', 'next week'], // 60*60*24*7*4*2
[2419200, 'weeks', 604800], // 60*60*24*7*4, 60*60*24*7
[4838400, 'last month', 'next month'], // 60*60*24*7*4*2
[29030400, 'months', 2419200], // 60*60*24*7*4*12, 60*60*24*7*4
[58060800, 'last year', 'next year'], // 60*60*24*7*4*12*2
[2903040000, 'years', 29030400], // 60*60*24*7*4*12*100, 60*60*24*7*4*12
[5806080000, 'last century', 'next century'], // 60*60*24*7*4*12*100*2
[58060800000, 'centuries', 2903040000] // 60*60*24*7*4*12*100*20, 60*60*24*7*4*12*100
];
/*
var time = ('' + date_str).replace(/-/g,"/").replace(/[TZ]/g," ").replace(/^\s\s*/ /*rappel , '').replace(/\s\s*$/, '');
if(time.substr(time.length-4,1)==".") time =time.substr(0,time.length-4);
*/
var seconds = (new Date - new Date(time)) / 1000;
var token = 'ago', list_choice = 1;
if (seconds < 0) {
seconds = Math.abs(seconds);
token = 'from now';
list_choice = 2;
}
var i = 0, format;
while (format = time_formats[i++])
if (seconds < format[0]) {
if (typeof format[2] == 'string')
return format[list_choice];
else
return Math.floor(seconds / format[2]) + ' ' + format[1] + ' ' + token;
}
return time;
};

exports.aceEditorCSS = hooks.aceEditorCSS;
exports.postAceInit = hooks.postAceInit;
exports.aceAttribsToClasses = hooks.aceAttribsToClasses;
Expand Down
85 changes: 85 additions & 0 deletions static/js/timeFormat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
var localizable = typeof html10n !== "undefined";

l10nKeys = {
"seconds" : "ep_comments_page.time.seconds",
"1 minute ago" : "ep_comments_page.time.one_minute_ago",
"1 minute from now" : "ep_comments_page.time.one_minute_from_now",
"minutes" : "ep_comments_page.time.minutes",
"1 hour ago" : "ep_comments_page.time.one_hour_ago",
"1 hour from now" : "ep_comments_page.time.one_hour_from_now",
"hours" : "ep_comments_page.time.hours",
"yesterday" : "ep_comments_page.time.yesterday",
"tomorrow" : "ep_comments_page.time.tomorrow",
"days" : "ep_comments_page.time.days",
"last week" : "ep_comments_page.time.last_week",
"next week" : "ep_comments_page.time.next_week",
"weeks" : "ep_comments_page.time.weeks",
"last month" : "ep_comments_page.time.last_month",
"next month" : "ep_comments_page.time.next_month",
"months" : "ep_comments_page.time.months",
"last year" : "ep_comments_page.time.last_year",
"next year" : "ep_comments_page.time.next_year",
"years" : "ep_comments_page.time.years",
"last century" : "ep_comments_page.time.last_century",
"next century" : "ep_comments_page.time.next_century",
"centuries" : "ep_comments_page.time.centuries"
}

var time_formats = [
[60, 'seconds', 1], // 60
[120, '1 minute ago', '1 minute from now'], // 60*2
[3600, 'minutes', 60], // 60*60, 60
[7200, '1 hour ago', '1 hour from now'], // 60*60*2
[86400, 'hours', 3600], // 60*60*24, 60*60
[172800, 'yesterday', 'tomorrow'], // 60*60*24*2
[604800, 'days', 86400], // 60*60*24*7, 60*60*24
[1209600, 'last week', 'next week'], // 60*60*24*7*4*2
[2419200, 'weeks', 604800], // 60*60*24*7*4, 60*60*24*7
[4838400, 'last month', 'next month'], // 60*60*24*7*4*2
[29030400, 'months', 2419200], // 60*60*24*7*4*12, 60*60*24*7*4
[58060800, 'last year', 'next year'], // 60*60*24*7*4*12*2
[2903040000, 'years', 29030400], // 60*60*24*7*4*12*100, 60*60*24*7*4*12
[5806080000, 'last century', 'next century'], // 60*60*24*7*4*12*100*2
[58060800000, 'centuries', 2903040000] // 60*60*24*7*4*12*100*20, 60*60*24*7*4*12*100
];

function prettyDate(time){
/*
var time = ('' + date_str).replace(/-/g,"/").replace(/[TZ]/g," ").replace(/^\s\s*/ /*rappel , '').replace(/\s\s*$/, '');
if(time.substr(time.length-4,1)==".") time =time.substr(0,time.length-4);
*/
var seconds = (new Date - new Date(time)) / 1000;
var token = 'ago',
list_choice = 1,
l10n_appendix = '_ago';

if (seconds < 0) {
seconds = Math.abs(seconds);
token = 'from now';
l10n_appendix = '_from_now';
list_choice = 2;
}

var i = 0, format;
while (format = time_formats[i++])
if (seconds < format[0]) {
var count = Math.floor(seconds / format[2]);
var formatted_time;
if (localizable) {
var key = l10nKeys[format[list_choice]] + l10n_appendix;
formatted_time = html10n.get(key, { count: count });
}

// Wasn't able to localize properly the date, so use the default:
if (formatted_time === undefined) {
if (typeof format[2] == 'string')
formatted_time = format[list_choice];
else
formatted_time = count + ' ' + format[1] + ' ' + token;
}
return formatted_time;
}
return time;
};

exports.prettyDate = prettyDate;
Loading

0 comments on commit a437dbf

Please sign in to comment.