Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable translation for the remaining strings on the search results page #752

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 33 additions & 61 deletions pywb/static/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,13 @@ RenderCalendar.prototype.createContainers = function() {
},
{ tag: 'textNode', value: ' ' },
{
tag: 'b',
child: {
tag: 'textNode',
value: '',
ref: function(refToElem) {
renderCal.containers.versionsTextNode = refToElem;
}
tag: 'textNode',
value: '',
ref: function(refToElem) {
renderCal.containers.versionsTextNode = refToElem;
}
},
{ tag: 'textNode', value: ' of ' + this.queryInfo.url }
{ tag: 'b', innerText: ' ' + this.queryInfo.url }
]
});
// create the row that will hold the results of the regular query
Expand Down Expand Up @@ -440,11 +437,11 @@ RenderCalendar.prototype.createContainers = function() {
var forElems;

if (this.queryInfo.searchParams.matchType) {
forString = ' for matching ';
forString = ' ' + this.text.matching + ' ';
forElems = [
{ tag: 'b', innerText: this.queryInfo.url },
{ tag: 'textNode', value: ' by ' },
{ tag: 'b', innerText: this.queryInfo.searchParams.matchType }
{ tag: 'textNode', value: ' ' + this.text.by + ' ' },
{ tag: 'b', innerText: this.text.types[this.queryInfo.searchParams.matchType] }
];
} else {
forElems = [{ tag: 'b', innerText: this.queryInfo.url }];
Expand All @@ -463,23 +460,21 @@ RenderCalendar.prototype.createContainers = function() {
},
{
tag: 'b',
children: [
{
tag: 'textNode',
value: '',
ref: function(refToElem) {
renderCal.containers.countTextNode = refToElem;
}
},
{ tag: 'textNode', value: ' ' },
{
tag: 'textNode',
value: '',
ref: function(refToElem) {
renderCal.containers.versionsTextNode = refToElem;
}
child: {
tag: 'textNode',
value: '',
ref: function(refToElem) {
renderCal.containers.countTextNode = refToElem;
}
]
}
},
{ tag: 'textNode', value: ' ' },
{
tag: 'textNode',
value: '',
ref: function(refToElem) {
renderCal.containers.versionsTextNode = refToElem;
}
},
{ tag: 'textNode', value: forString }
].concat(forElems)
Expand Down Expand Up @@ -614,13 +609,13 @@ RenderCalendar.prototype.renderAdvancedSearchPart = function(cdxObj) {
if (cdxObj.mime) {
displayedInfo.push({
tag: 'small',
innerText: 'Mime Type: ' + cdxObj.mime
innerText: this.text.mimeType + cdxObj.mime
});
}
if (cdxObj.status) {
displayedInfo.push({
tag: 'small',
innerText: 'HTTP Status: ' + cdxObj.status
innerText: this.text.httpStatus + cdxObj.status
});
}
displayedInfo.push({
Expand Down Expand Up @@ -785,6 +780,11 @@ RenderCalendar.prototype.addRegYearMonthDayListItem = function(
a[href="replay url"]
span[id=count_ts].badge.badge-info.badge-pill.float-right
*/
const options = {
dateStyle: 'long',
timeStyle: 'medium',
};
var dateTimeString = this.tsToDate(cdxObj.timestamp, false, options);
this.createAndAddElementTo(ymlDL, {
tag: 'li',
className: 'list-group-item',
Expand All @@ -795,17 +795,7 @@ RenderCalendar.prototype.addRegYearMonthDayListItem = function(
href: this.prefix + cdxObj.timestamp + '/' + cdxObj.url,
target: '_blank'
},
innerText:
timeInfo.month +
' ' +
timeInfo.day +
this.dateOrdinal(timeInfo.day) +
', ' +
timeInfo.year +
' ' +
' at ' +
timeInfo.time +
' '
innerText: dateTimeString
},
{
tag: 'span',
Expand Down Expand Up @@ -1020,32 +1010,14 @@ RenderCalendar.prototype.displayYearMonthDaysListId = function(year, month) {
return '_' + year + '-' + month + '-Display-Days-List';
};

/**
* Returns a numbers ordinal string
* @param {number} d - The number to receive the ordinal string for
* @returns {string}
*/
RenderCalendar.prototype.dateOrdinal = function(d) {
if (d > 3 && d < 21) return 'th';
switch (d % 10) {
case 1:
return 'st';
case 2:
return 'nd';
case 3:
return 'rd';
default:
return 'th';
}
};

/**
* Converts the supplied timestamp to either a local data string or a gmt string (if is_gmt is true)
* @param {string} ts - The timestamp to be converted to a string
* @param {boolean} [is_gmt] - Should the timestamp be converted to a gmt string
* @param {Object} [options] - String formatting options
* @returns {string}
*/
RenderCalendar.prototype.tsToDate = function(ts, is_gmt) {
RenderCalendar.prototype.tsToDate = function(ts, is_gmt, options) {
if (ts.length < 14) return ts;
var datestr =
ts.substring(0, 4) +
Expand All @@ -1062,7 +1034,7 @@ RenderCalendar.prototype.tsToDate = function(ts, is_gmt) {
'-00:00';

var date = new Date(datestr);
return is_gmt ? date.toGMTString() : date.toLocaleString();
return is_gmt ? date.toUTCString() : date.toLocaleString(document.documentElement.lang, options);
};

/**
Expand Down
13 changes: 11 additions & 2 deletions pywb/templates/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ <h4 class="display-4 text-center text-sm-left p-0">{{ _('Search Results') }}</h4
'11': "{{ _('November') }}",
'12': "{{ _('December') }}",
},
version: "{{ _('capture') }}",
versions: "{{ _('captures') }}",
version: "{{ _('capture of') }}",
versions: "{{ _('captures of') }}",
result: "{{ _('result') }}",
results: "{{ _('results') }}",
matching: "{{ _('for matching') }}",
by: "{{ _('by') }}",
viewAllCaptures: "{{ _('View All Captures') }}",
dateTime: "{{ _('Date Time: ') }}",
mimeType: "{{ _('Mime Type: ') }}",
httpStatus: "{{ _('HTTP Status: ') }}",
types: {
'prefix': "{{ _('prefix') }}",
'host': "{{ _('host') }}",
'domain': "{{ _('domain') }}",
},
};

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