1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Make date format strings be translateable

Note for translators: I’m planning to release 5.1.3 later today.

Fixes #954
This commit is contained in:
Jermolene 2014-10-09 10:33:08 +01:00
parent e34b4f18e5
commit c6951ee912
3 changed files with 164 additions and 50 deletions

View File

@ -8,6 +8,77 @@ ConfirmCancelTiddler: Do you wish to discard changes to the tiddler "<$text text
ConfirmDeleteTiddler: Do you wish to delete the tiddler "<$text text=<<title>>/>"?
ConfirmOverwriteTiddler: Do you wish to overwrite the tiddler "<$text text=<<title>>/>"?
ConfirmEditShadowTiddler: You are about to edit a ShadowTiddler. Any changes will override the default system making future upgrades non-trivial. Are you sure you want to edit "<$text text=<<title>>/>"?
Date/DaySuffix/1: st
Date/DaySuffix/2: nd
Date/DaySuffix/3: rd
Date/DaySuffix/4: th
Date/DaySuffix/5: th
Date/DaySuffix/6: th
Date/DaySuffix/7: th
Date/DaySuffix/8: th
Date/DaySuffix/9: th
Date/DaySuffix/10: th
Date/DaySuffix/11: th
Date/DaySuffix/12: th
Date/DaySuffix/13: th
Date/DaySuffix/14: th
Date/DaySuffix/15: th
Date/DaySuffix/16: th
Date/DaySuffix/17: th
Date/DaySuffix/18: th
Date/DaySuffix/19: th
Date/DaySuffix/20: th
Date/DaySuffix/21: st
Date/DaySuffix/22: nd
Date/DaySuffix/23: rd
Date/DaySuffix/24: th
Date/DaySuffix/25: th
Date/DaySuffix/26: th
Date/DaySuffix/27: th
Date/DaySuffix/28: th
Date/DaySuffix/29: th
Date/DaySuffix/30: th
Date/DaySuffix/31: st
Date/Long/Day/0: Sunday
Date/Long/Day/1: Monday
Date/Long/Day/2: Tuesday
Date/Long/Day/3: Wednesday
Date/Long/Day/4: Thursday
Date/Long/Day/5: Friday
Date/Long/Day/6: Saturday
Date/Long/Month/1: January
Date/Long/Month/2: February
Date/Long/Month/3: March
Date/Long/Month/4: April
Date/Long/Month/5: May
Date/Long/Month/6: June
Date/Long/Month/7: July
Date/Long/Month/8: August
Date/Long/Month/9: September
Date/Long/Month/10: October
Date/Long/Month/11: November
Date/Long/Month/12: December
Date/Period/am: am
Date/Period/pm: pm
Date/Short/Day/0: Sun
Date/Short/Day/1: Mon
Date/Short/Day/2: Tue
Date/Short/Day/3: Wed
Date/Short/Day/4: Thu
Date/Short/Day/5: Fri
Date/Short/Day/6: Sat
Date/Short/Month/1: Jan
Date/Short/Month/2: Feb
Date/Short/Month/3: Mar
Date/Short/Month/4: Apr
Date/Short/Month/5: May
Date/Short/Month/6: Jun
Date/Short/Month/7: Jul
Date/Short/Month/8: Aug
Date/Short/Month/9: Sep
Date/Short/Month/10: Oct
Date/Short/Month/11: Nov
Date/Short/Month/12: Dec
DefaultNewTiddlerTitle: New Tiddler
DropMessage: Drop here (or click escape to cancel)
Encryption/ConfirmClearPassword: Do you wish to clear the password? This will remove the encryption applied when saving this wiki

View File

@ -17,20 +17,6 @@ exports.preferences = {};
exports.preferences.notificationDuration = 3 * 1000;
exports.preferences.jsonSpaces = 4;
exports.dateFormats = {
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November","December"],
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
// suffixes for dates, eg "1st","2nd","3rd"..."30th","31st"
daySuffixes: ["st","nd","rd","th","th","th","th","th","th","th",
"th","th","th","th","th","th","th","th","th","th",
"st","nd","rd","th","th","th","th","th","th","th",
"st"],
am: "am",
pm: "pm"
};
exports.htmlEntities = {quot:34, amp:38, apos:39, lt:60, gt:62, nbsp:160, iexcl:161, cent:162, pound:163, curren:164, yen:165, brvbar:166, sect:167, uml:168, copy:169, ordf:170, laquo:171, not:172, shy:173, reg:174, macr:175, deg:176, plusmn:177, sup2:178, sup3:179, acute:180, micro:181, para:182, middot:183, cedil:184, sup1:185, ordm:186, raquo:187, frac14:188, frac12:189, frac34:190, iquest:191, Agrave:192, Aacute:193, Acirc:194, Atilde:195, Auml:196, Aring:197, AElig:198, Ccedil:199, Egrave:200, Eacute:201, Ecirc:202, Euml:203, Igrave:204, Iacute:205, Icirc:206, Iuml:207, ETH:208, Ntilde:209, Ograve:210, Oacute:211, Ocirc:212, Otilde:213, Ouml:214, times:215, Oslash:216, Ugrave:217, Uacute:218, Ucirc:219, Uuml:220, Yacute:221, THORN:222, szlig:223, agrave:224, aacute:225, acirc:226, atilde:227, auml:228, aring:229, aelig:230, ccedil:231, egrave:232, eacute:233, ecirc:234, euml:235, igrave:236, iacute:237, icirc:238, iuml:239, eth:240, ntilde:241, ograve:242, oacute:243, ocirc:244, otilde:245, ouml:246, divide:247, oslash:248, ugrave:249, uacute:250, ucirc:251, uuml:252, yacute:253, thorn:254, yuml:255, OElig:338, oelig:339, Scaron:352, scaron:353, Yuml:376, fnof:402, circ:710, tilde:732, Alpha:913, Beta:914, Gamma:915, Delta:916, Epsilon:917, Zeta:918, Eta:919, Theta:920, Iota:921, Kappa:922, Lambda:923, Mu:924, Nu:925, Xi:926, Omicron:927, Pi:928, Rho:929, Sigma:931, Tau:932, Upsilon:933, Phi:934, Chi:935, Psi:936, Omega:937, alpha:945, beta:946, gamma:947, delta:948, epsilon:949, zeta:950, eta:951, theta:952, iota:953, kappa:954, lambda:955, mu:956, nu:957, xi:958, omicron:959, pi:960, rho:961, sigmaf:962, sigma:963, tau:964, upsilon:965, phi:966, chi:967, psi:968, omega:969, thetasym:977, upsih:978, piv:982, ensp:8194, emsp:8195, thinsp:8201, zwnj:8204, zwj:8205, lrm:8206, rlm:8207, ndash:8211, mdash:8212, lsquo:8216, rsquo:8217, sbquo:8218, ldquo:8220, rdquo:8221, bdquo:8222, dagger:8224, Dagger:8225, bull:8226, hellip:8230, permil:8240, prime:8242, Prime:8243, lsaquo:8249, rsaquo:8250, oline:8254, frasl:8260, euro:8364, image:8465, weierp:8472, real:8476, trade:8482, alefsym:8501, larr:8592, uarr:8593, rarr:8594, darr:8595, harr:8596, crarr:8629, lArr:8656, uArr:8657, rArr:8658, dArr:8659, hArr:8660, forall:8704, part:8706, exist:8707, empty:8709, nabla:8711, isin:8712, notin:8713, ni:8715, prod:8719, sum:8721, minus:8722, lowast:8727, radic:8730, prop:8733, infin:8734, ang:8736, and:8743, or:8744, cap:8745, cup:8746, int:8747, there4:8756, sim:8764, cong:8773, asymp:8776, ne:8800, equiv:8801, le:8804, ge:8805, sub:8834, sup:8835, nsub:8836, sube:8838, supe:8839, oplus:8853, otimes:8855, perp:8869, sdot:8901, lceil:8968, rceil:8969, lfloor:8970, rfloor:8971, lang:9001, rang:9002, loz:9674, spades:9824, clubs:9827, hearts:9829, diams:9830 };
exports.htmlVoidElements = "area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr".split(",");

View File

@ -168,60 +168,117 @@ exports.slowInSlowOut = function(t) {
};
exports.formatDateString = function(date,template) {
var t = template.replace(/0hh12/g,$tw.utils.pad($tw.utils.getHours12(date)));
t = t.replace(/hh12/g,$tw.utils.getHours12(date));
t = t.replace(/0hh/g,$tw.utils.pad(date.getHours()));
t = t.replace(/hh/g,date.getHours());
t = t.replace(/mmm/g,$tw.config.dateFormats.shortMonths[date.getMonth()]);
t = t.replace(/0mm/g,$tw.utils.pad(date.getMinutes()));
t = t.replace(/mm/g,date.getMinutes());
t = t.replace(/0ss/g,$tw.utils.pad(date.getSeconds()));
t = t.replace(/ss/g,date.getSeconds());
t = t.replace(/[ap]m/g,$tw.utils.getAmPm(date).toLowerCase());
t = t.replace(/[AP]M/g,$tw.utils.getAmPm(date).toUpperCase());
t = t.replace(/wYYYY/g,$tw.utils.getYearForWeekNo(date));
t = t.replace(/wYY/g,$tw.utils.pad($tw.utils.getYearForWeekNo(date)-2000));
t = t.replace(/YYYY/g,date.getFullYear());
t = t.replace(/YY/g,$tw.utils.pad(date.getFullYear()-2000));
t = t.replace(/MMM/g,$tw.config.dateFormats.months[date.getMonth()]);
t = t.replace(/0MM/g,$tw.utils.pad(date.getMonth()+1));
t = t.replace(/MM/g,date.getMonth()+1);
t = t.replace(/0WW/g,$tw.utils.pad($tw.utils.getWeek(date)));
t = t.replace(/WW/g,$tw.utils.getWeek(date));
t = t.replace(/DDD/g,$tw.config.dateFormats.days[date.getDay()]);
t = t.replace(/ddd/g,$tw.config.dateFormats.shortDays[date.getDay()]);
t = t.replace(/0DD/g,$tw.utils.pad(date.getDate()));
t = t.replace(/DDth/g,date.getDate()+$tw.utils.getDaySuffix(date));
t = t.replace(/DD/g,date.getDate());
var tz = date.getTimezoneOffset();
var atz = Math.abs(tz);
t = t.replace(/TZD/g,(tz < 0 ? '+' : '-') + $tw.utils.pad(Math.floor(atz / 60)) + ':' + $tw.utils.pad(atz % 60));
var t = template;
t = t.replace(/0hh12/g,function() {
return $tw.utils.pad($tw.utils.getHours12(date));
});
t = t.replace(/hh12/g,function() {
return $tw.utils.getHours12(date);
});
t = t.replace(/0hh/g,function() {
return $tw.utils.pad(date.getHours());
});
t = t.replace(/hh/g,function() {
return date.getHours();
});
t = t.replace(/mmm/g,function() {
return $tw.language.getString("Date/Short/Month/" + (date.getMonth() + 1));
});
t = t.replace(/0mm/g,function() {
return $tw.utils.pad(date.getMinutes());
});
t = t.replace(/mm/g,function() {
return date.getMinutes();
});
t = t.replace(/0ss/g,function() {
return $tw.utils.pad(date.getSeconds());
});
t = t.replace(/ss/g,function() {
return date.getSeconds();
});
t = t.replace(/[ap]m/g,function() {
return $tw.utils.getAmPm(date).toLowerCase();
});
t = t.replace(/[AP]M/g,function() {
return $tw.utils.getAmPm(date).toUpperCase();
});
t = t.replace(/wYYYY/g,function() {
return $tw.utils.getYearForWeekNo(date);
});
t = t.replace(/wYY/g,function() {
return $tw.utils.pad($tw.utils.getYearForWeekNo(date)-2000);
});
t = t.replace(/YYYY/g,function() {
return date.getFullYear();
});
t = t.replace(/YY/g,function() {
return $tw.utils.pad(date.getFullYear()-2000);
});
t = t.replace(/MMM/g,function() {
return $tw.language.getString("Date/Long/Month/" + (date.getMonth() + 1));
});
t = t.replace(/0MM/g,function() {
return $tw.utils.pad(date.getMonth()+1);
});
t = t.replace(/MM/g,function() {
return date.getMonth() + 1;
});
t = t.replace(/0WW/g,function() {
return $tw.utils.pad($tw.utils.getWeek(date));
});
t = t.replace(/WW/g,function() {
return $tw.utils.getWeek(date);
});
t = t.replace(/DDD/g,function() {
return $tw.language.getString("Date/Long/Day/" + date.getDay());
});
t = t.replace(/ddd/g,function() {
return $tw.language.getString("Date/Short/Day/" + date.getDay());
});
t = t.replace(/0DD/g,function() {
return $tw.utils.pad(date.getDate());
});
t = t.replace(/DDth/g,function() {
return date.getDate() + $tw.utils.getDaySuffix(date);
});
t = t.replace(/DD/g,function() {
return date.getDate();
});
t = t.replace(/TZD/g,function() {
var tz = date.getTimezoneOffset(),
atz = Math.abs(tz);
return (tz < 0 ? '+' : '-') + $tw.utils.pad(Math.floor(atz / 60)) + ':' + $tw.utils.pad(atz % 60);
});
t = t.replace(/\\(.)/g,"$1");
return t;
};
exports.getAmPm = function(date) {
return date.getHours() >= 12 ? $tw.config.dateFormats.pm : $tw.config.dateFormats.am;
return $tw.language.getString("Date/Period/" + (date.getHours() >= 12 ? "pm" : "am"));
};
exports.getDaySuffix = function(date) {
return $tw.config.dateFormats.daySuffixes[date.getDate()-1];
return $tw.language.getString("Date/DaySuffix/" + date.getDate());
};
exports.getWeek = function(date) {
var dt = new Date(date.getTime());
var d = dt.getDay();
if(d === 0) d=7;// JavaScript Sun=0, ISO Sun=7
dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week to calculate weekNo
var n = Math.floor((dt.getTime()-new Date(dt.getFullYear(),0,1)+3600000)/86400000);
return Math.floor(n/7)+1;
if(d === 0) {
d = 7; // JavaScript Sun=0, ISO Sun=7
}
dt.setTime(dt.getTime() + (4 - d) * 86400000);// shift day to Thurs of same week to calculate weekNo
var n = Math.floor((dt.getTime()-new Date(dt.getFullYear(),0,1) + 3600000) / 86400000);
return Math.floor(n / 7) + 1;
};
exports.getYearForWeekNo = function(date) {
var dt = new Date(date.getTime());
var d = dt.getDay();
if(d === 0) d=7;// JavaScript Sun=0, ISO Sun=7
dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week
if(d === 0) {
d = 7; // JavaScript Sun=0, ISO Sun=7
}
dt.setTime(dt.getTime() + (4 - d) * 86400000);// shift day to Thurs of same week
return dt.getFullYear();
};