From 8f68911c21f8ab913a94303f4002553b88527042 Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Tue, 13 Aug 2024 16:01:24 +0100 Subject: [PATCH] Extract reviews-page strings Refs #1817 --- locales/en-US/reviews-page.json | 44 +++++++++++++++++ src/reviews-page/reviews-page.ts | 83 ++++++++++++++++++++++---------- 2 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 locales/en-US/reviews-page.json diff --git a/locales/en-US/reviews-page.json b/locales/en-US/reviews-page.json new file mode 100644 index 000000000..e3154e098 --- /dev/null +++ b/locales/en-US/reviews-page.json @@ -0,0 +1,44 @@ +{ + "title": { + "message": "Recent PREreviews" + }, + "titleWithDetails": { + "message": "Recent PREreviews ({details})" + }, + "skipResults": { + "message": "Skip to results" + }, + "filterTitle": { + "message": "Filter" + }, + "filterTitleAuthorLabel": { + "message": "Title or author" + }, + "filterLanguageLabel": { + "message": "Language" + }, + "filterLanguageAny": { + "message": "Any" + }, + "filterFieldLabel": { + "message": "Field" + }, + "filterFieldAny": { + "message": "Any" + }, + "filterButton": { + "message": "Filter results" + }, + "pagerNewer": { + "message": "Newer" + }, + "pagerOlder": { + "message": "Older" + }, + "noResults": { + "message": "No PREreviews have been published yet." + }, + "appearHere": { + "message": "When they do, they’ll appear here." + } +} diff --git a/src/reviews-page/reviews-page.ts b/src/reviews-page/reviews-page.ts index b122dcc70..cda59fde6 100644 --- a/src/reviews-page/reviews-page.ts +++ b/src/reviews-page/reviews-page.ts @@ -11,7 +11,7 @@ import rtlDetect from 'rtl-detect' import { match } from 'ts-pattern' import { getClubName } from '../club-details.js' import { type Html, html, plainText, rawHtml } from '../html.js' -import type { SupportedLocale } from '../locales/index.js' +import { type SupportedLocale, translate } from '../locales/index.js' import { PageResponse } from '../response.js' import { reviewMatch, reviewsMatch } from '../routes.js' import { renderDate } from '../time.js' @@ -27,9 +27,9 @@ export const createPage = ( ) => PageResponse({ title: title({ currentPage, field, language, locale, query }), - extraSkipLink: [html`Skip to results`, '#results'], + extraSkipLink: [html`${translate(locale, 'reviews-page', 'skipResults')()}`, '#results'], main: html` -

Recent PREreviews

+

${translate(locale, 'reviews-page', 'title')()}

${form({ canUseSearchQueries, field, language, locale, query })} @@ -41,13 +41,34 @@ export const createPage = (
  • - ${formatList(locale)(prereview.reviewers)} - ${prereview.club ? html`of the ${getClubName(prereview.club)}` : ''} reviewed - ${prereview.preprint.title} + ${rawHtml( + prereview.club + ? translate( + locale, + 'reviews-list', + 'clubReviewText', + )({ + club: html`${getClubName(prereview.club)}`.toString(), + reviewers: formatList(locale)(prereview.reviewers).toString(), + preprint: html`${prereview.preprint.title}`.toString(), + }) + : translate( + locale, + 'reviews-list', + 'reviewText', + )({ + reviewers: formatList(locale)(prereview.reviewers).toString(), + preprint: html`${prereview.preprint.title}`.toString(), + }), + )} ${prereview.subfields.length > 0 @@ -59,9 +80,9 @@ export const createPage = ( : ''}
    -
    Review published
    +
    ${translate(locale, 'reviews-list', 'reviewPublished')()}
    ${renderDate(locale)(prereview.published)}
    -
    Preprint server
    +
    ${translate(locale, 'reviews-list', 'reviewServer')()}
    ${match(prereview.preprint.id.type) .with('africarxiv', () => 'AfricArXiv Preprints') @@ -104,14 +125,14 @@ export const createPage = ( ? html`${translate(locale, 'reviews-page', 'pagerNewer')()}` : ''} ${currentPage < totalPages ? html`${translate(locale, 'reviews-page', 'pagerOlder')()}` : ''} @@ -127,16 +148,16 @@ export const emptyPage = ( ) => PageResponse({ title: title({ currentPage: 1, field, language, locale, query }), - extraSkipLink: [html`Skip to results`, '#results'], + extraSkipLink: [html`${translate(locale, 'reviews-page', 'skipResults')()}`, '#results'], main: html` -

    Recent PREreviews

    +

    ${translate(locale, 'reviews-page', 'title')()}

    ${form({ canUseSearchQueries, field, language, locale, query })}
    -

    No PREreviews have been published yet.

    +

    ${translate(locale, 'reviews-page', 'noResults')()}

    -

    When they do, they’ll appear here.

    +

    ${translate(locale, 'reviews-page', 'appearHere')()}

    `, canonical: format(reviewsMatch.formatter, { page: 1, field, language, query }), @@ -156,7 +177,13 @@ const title = ({ ), ) - return plainText`Recent PREreviews (${formatList(locale, { style: 'narrow' })(details)})` + return plainText( + translate( + locale, + 'reviews-page', + 'titleWithDetails', + )({ details: formatList(locale, { style: 'narrow' })(details).toString() }), + ) } const form = ({ @@ -176,21 +203,23 @@ const form = ({ role="search" aria-labelledby="filter-label" > -

    Filter

    +

    ${translate(locale, 'reviews-page', 'filterTitle')()}

    ${canUseSearchQueries ? html`
    - +
    ` : query ? html`` : ''}
    - +
    - + ${pipe( fieldIds, RA.map(field => [field, getFieldName(field, locale)] satisfies [FieldId, string]), @@ -217,7 +248,7 @@ const form = ({
    - + `