Skip to content

Commit 0cc912d

Browse files
authored
Enable translation for the remaining strings on the search results page (#752)
* Enable translation for the remaining strings on the search results page * Use toLocaleString() to format timestamps also for search results without matchType
1 parent f190190 commit 0cc912d

File tree

2 files changed

+44
-63
lines changed

2 files changed

+44
-63
lines changed

pywb/static/query.js

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -371,16 +371,13 @@ RenderCalendar.prototype.createContainers = function() {
371371
},
372372
{ tag: 'textNode', value: ' ' },
373373
{
374-
tag: 'b',
375-
child: {
376-
tag: 'textNode',
377-
value: '',
378-
ref: function(refToElem) {
379-
renderCal.containers.versionsTextNode = refToElem;
380-
}
374+
tag: 'textNode',
375+
value: '',
376+
ref: function(refToElem) {
377+
renderCal.containers.versionsTextNode = refToElem;
381378
}
382379
},
383-
{ tag: 'textNode', value: ' of ' + this.queryInfo.url }
380+
{ tag: 'b', innerText: ' ' + this.queryInfo.url }
384381
]
385382
});
386383
// create the row that will hold the results of the regular query
@@ -440,11 +437,11 @@ RenderCalendar.prototype.createContainers = function() {
440437
var forElems;
441438

442439
if (this.queryInfo.searchParams.matchType) {
443-
forString = ' for matching ';
440+
forString = ' ' + this.text.matching + ' ';
444441
forElems = [
445442
{ tag: 'b', innerText: this.queryInfo.url },
446-
{ tag: 'textNode', value: ' by ' },
447-
{ tag: 'b', innerText: this.queryInfo.searchParams.matchType }
443+
{ tag: 'textNode', value: ' ' + this.text.by + ' ' },
444+
{ tag: 'b', innerText: this.text.types[this.queryInfo.searchParams.matchType] }
448445
];
449446
} else {
450447
forElems = [{ tag: 'b', innerText: this.queryInfo.url }];
@@ -463,23 +460,21 @@ RenderCalendar.prototype.createContainers = function() {
463460
},
464461
{
465462
tag: 'b',
466-
children: [
467-
{
468-
tag: 'textNode',
469-
value: '',
470-
ref: function(refToElem) {
471-
renderCal.containers.countTextNode = refToElem;
472-
}
473-
},
474-
{ tag: 'textNode', value: ' ' },
475-
{
476-
tag: 'textNode',
477-
value: '',
478-
ref: function(refToElem) {
479-
renderCal.containers.versionsTextNode = refToElem;
480-
}
463+
child: {
464+
tag: 'textNode',
465+
value: '',
466+
ref: function(refToElem) {
467+
renderCal.containers.countTextNode = refToElem;
481468
}
482-
]
469+
}
470+
},
471+
{ tag: 'textNode', value: ' ' },
472+
{
473+
tag: 'textNode',
474+
value: '',
475+
ref: function(refToElem) {
476+
renderCal.containers.versionsTextNode = refToElem;
477+
}
483478
},
484479
{ tag: 'textNode', value: forString }
485480
].concat(forElems)
@@ -614,13 +609,13 @@ RenderCalendar.prototype.renderAdvancedSearchPart = function(cdxObj) {
614609
if (cdxObj.mime) {
615610
displayedInfo.push({
616611
tag: 'small',
617-
innerText: 'Mime Type: ' + cdxObj.mime
612+
innerText: this.text.mimeType + cdxObj.mime
618613
});
619614
}
620615
if (cdxObj.status) {
621616
displayedInfo.push({
622617
tag: 'small',
623-
innerText: 'HTTP Status: ' + cdxObj.status
618+
innerText: this.text.httpStatus + cdxObj.status
624619
});
625620
}
626621
displayedInfo.push({
@@ -785,6 +780,11 @@ RenderCalendar.prototype.addRegYearMonthDayListItem = function(
785780
a[href="replay url"]
786781
span[id=count_ts].badge.badge-info.badge-pill.float-right
787782
*/
783+
const options = {
784+
dateStyle: 'long',
785+
timeStyle: 'medium',
786+
};
787+
var dateTimeString = this.tsToDate(cdxObj.timestamp, false, options);
788788
this.createAndAddElementTo(ymlDL, {
789789
tag: 'li',
790790
className: 'list-group-item',
@@ -795,17 +795,7 @@ RenderCalendar.prototype.addRegYearMonthDayListItem = function(
795795
href: this.prefix + cdxObj.timestamp + '/' + cdxObj.url,
796796
target: '_blank'
797797
},
798-
innerText:
799-
timeInfo.month +
800-
' ' +
801-
timeInfo.day +
802-
this.dateOrdinal(timeInfo.day) +
803-
', ' +
804-
timeInfo.year +
805-
' ' +
806-
' at ' +
807-
timeInfo.time +
808-
' '
798+
innerText: dateTimeString
809799
},
810800
{
811801
tag: 'span',
@@ -1020,32 +1010,14 @@ RenderCalendar.prototype.displayYearMonthDaysListId = function(year, month) {
10201010
return '_' + year + '-' + month + '-Display-Days-List';
10211011
};
10221012

1023-
/**
1024-
* Returns a numbers ordinal string
1025-
* @param {number} d - The number to receive the ordinal string for
1026-
* @returns {string}
1027-
*/
1028-
RenderCalendar.prototype.dateOrdinal = function(d) {
1029-
if (d > 3 && d < 21) return 'th';
1030-
switch (d % 10) {
1031-
case 1:
1032-
return 'st';
1033-
case 2:
1034-
return 'nd';
1035-
case 3:
1036-
return 'rd';
1037-
default:
1038-
return 'th';
1039-
}
1040-
};
1041-
10421013
/**
10431014
* Converts the supplied timestamp to either a local data string or a gmt string (if is_gmt is true)
10441015
* @param {string} ts - The timestamp to be converted to a string
10451016
* @param {boolean} [is_gmt] - Should the timestamp be converted to a gmt string
1017+
* @param {Object} [options] - String formatting options
10461018
* @returns {string}
10471019
*/
1048-
RenderCalendar.prototype.tsToDate = function(ts, is_gmt) {
1020+
RenderCalendar.prototype.tsToDate = function(ts, is_gmt, options) {
10491021
if (ts.length < 14) return ts;
10501022
var datestr =
10511023
ts.substring(0, 4) +
@@ -1062,7 +1034,7 @@ RenderCalendar.prototype.tsToDate = function(ts, is_gmt) {
10621034
'-00:00';
10631035

10641036
var date = new Date(datestr);
1065-
return is_gmt ? date.toGMTString() : date.toLocaleString();
1037+
return is_gmt ? date.toUTCString() : date.toLocaleString(document.documentElement.lang, options);
10661038
};
10671039

10681040
/**

pywb/templates/query.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@ <h4 class="display-4 text-center text-sm-left p-0">{{ _('Search Results') }}</h4
3838
'11': "{{ _('November') }}",
3939
'12': "{{ _('December') }}",
4040
},
41-
version: "{{ _('capture') }}",
42-
versions: "{{ _('captures') }}",
41+
version: "{{ _('capture of') }}",
42+
versions: "{{ _('captures of') }}",
4343
result: "{{ _('result') }}",
4444
results: "{{ _('results') }}",
45+
matching: "{{ _('for matching') }}",
46+
by: "{{ _('by') }}",
4547
viewAllCaptures: "{{ _('View All Captures') }}",
4648
dateTime: "{{ _('Date Time: ') }}",
49+
mimeType: "{{ _('Mime Type: ') }}",
50+
httpStatus: "{{ _('HTTP Status: ') }}",
51+
types: {
52+
'prefix': "{{ _('prefix') }}",
53+
'host': "{{ _('host') }}",
54+
'domain': "{{ _('domain') }}",
55+
},
4756
};
4857

4958
var renderCal = new RenderCalendar({ prefix: "{{ prefix }}", staticPrefix: "{{ static_prefix }}", text: text });

0 commit comments

Comments
 (0)