Skip to content

Commit

Permalink
feat(DatasetFiles): add internationalization
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Jul 3, 2023
1 parent a92ba33 commit ca561f6
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 25 deletions.
38 changes: 32 additions & 6 deletions public/locales/en/files.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
{
"metadataReleased": "Metadata Released",
"published": "Published",
"deposited": "Deposited",
"embargoedWillBeUntil": "Draft: will be embargoed until",
"embargoedUntil": "Embargoed until",
"embargoedWasThrough": "Was embargoed until"
"filesLoading": "Files loading spinner symbol",
"table": {
"pagination": {
"pageSize": "Files per page"
},
"tabularData": {
"variables": "Variables",
"observations": "Observations"
},
"embargoDate": {
"embargoedWillBeUntil": "Draft: will be embargoed until",
"embargoedUntil": "Embargoed until",
"embargoedWasThrough": "Was embargoed until"
},
"downloads": "Downloads",
"date": {
"metadataReleased": "Metadata Released",
"published": "Published",
"deposited": "Deposited"
},
"thumbnail": {
"restricted": {
"locked": "Locked File Icon",
"unlocked": "Unlocked File Icon"
}
},
"copyToClipboard": {
"clickToCopy": "Click to copy",
"correctlyCopiedIcon": "Correctly copied to clipboard icon",
"copyToClipboardIcon": "Copy to clipboard icon"
}
}
}
2 changes: 1 addition & 1 deletion src/sections/dataset/dataset-files/DatasetFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FileRepository } from '../../../files/domain/repositories/FileRepositor
import { useFiles } from './useFiles'
import { useEffect } from 'react'
import { FilesTable } from './files-table/FilesTable'
import { SpinnerSymbol } from './SpinnerSymbol'
import { SpinnerSymbol } from './files-table/spinner-symbol/SpinnerSymbol'

interface DatasetFilesProps {
filesRepository: FileRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function FileDate({ date }: { date: FileDateModel }) {
return (
<div>
<span>
{t(date.type)} {date.date}
{t(`table.date.${date.type}`)} {date.date}
</span>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { FileStatus } from '../../../../../files/domain/models/File'
import { useTranslation } from 'react-i18next'

interface FileDownloadsProps {
downloads: number
status: FileStatus
}
export function FileDownloads({ downloads, status }: FileDownloadsProps) {
const { t } = useTranslation('files')
if (status !== FileStatus.RELEASED) {
return <></>
}

return (
<div>
<span>{downloads} Downloads</span>
<span>
{downloads} {t('table.downloads')}
</span>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export function FileEmbargoDate({ embargo, status }: FileEmbargoDateProps) {

const embargoTypeOfDate = (embargoIsActive: boolean, status: FileStatus) => {
if (status === FileStatus.RELEASED) {
return embargoIsActive ? 'embargoedUntil' : 'embargoedWasThrough'
return embargoIsActive
? 'table.embargoDate.embargoedUntil'
: 'table.embargoDate.embargoedWasThrough'
}

return 'embargoedWillBeUntil'
return 'table.embargoDate.embargoedWillBeUntil'
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { FileTabularData as FileTabularDataModel } from '../../../../../files/domain/models/File'
import { CopyToClipboardButton } from './copy-to-clipboard-button/CopyToClipboardButton'
import { useTranslation } from 'react-i18next'

export function FileTabularData({
tabularData
}: {
tabularData: FileTabularDataModel | undefined
}) {
const { t } = useTranslation('files')
if (!tabularData) {
return <></>
}
return (
<div>
{tabularData.variablesCount} Variables, {tabularData.observationsCount} Observations{' '}
{tabularData.unf} <CopyToClipboardButton text={tabularData.unf} />
{tabularData.variablesCount} {t('table.tabularData.variables')},{' '}
{tabularData.observationsCount} {t('table.tabularData.observations')} {tabularData.unf}{' '}
<CopyToClipboardButton text={tabularData.unf} />
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Check, ClipboardPlusFill } from 'react-bootstrap-icons'
import { OverlayTrigger } from 'dataverse-design-system'
import { useState } from 'react'
import styles from './CopyToClipboard.module.scss'
import { useTranslation } from 'react-i18next'

export function CopyToClipboardButton({ text }: { text: string }) {
const { t } = useTranslation('files')
const [copied, setCopied] = useState(false)
const copyToClipboard = () => {
navigator.clipboard
Expand All @@ -19,12 +21,16 @@ export function CopyToClipboardButton({ text }: { text: string }) {
}

return (
<OverlayTrigger placement="top" message={`Click to copy ${text}`}>
<OverlayTrigger placement="top" message={`${t('table.copyToClipboard.clickToCopy')} ${text}`}>
<span onClick={copyToClipboard} className={styles.container} role="button">
{copied ? (
<Check className={styles.check} role="img" title="Correctly copied to clipboard icon" />
<Check
className={styles.check}
role="img"
title={t('table.copyToClipboard.correctlyCopiedIcon')}
/>
) : (
<ClipboardPlusFill role="img" title="Copy to clipboard icon" />
<ClipboardPlusFill role="img" title={t('table.copyToClipboard.copyToClipboardIcon')} />
)}
</span>
</OverlayTrigger>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import { Lock, Unlock } from 'react-bootstrap-icons'
import styles from './FileThumbnail.module.scss'
import { useTranslation } from 'react-i18next'

export function FileThumbnailRestrictedIcon({ locked }: { locked: boolean }) {
const { t } = useTranslation('files')
if (locked) {
return (
<div>
<Lock className={styles.thumbnail__locked} role="img" title="Locked File Icon" />
<Lock
className={styles.thumbnail__locked}
role="img"
title={t('table.thumbnail.restricted.locked')}
/>
</div>
)
}

return (
<div>
<Unlock className={styles.thumbnail__unlocked} role="img" title="Unlocked File Icon" />
<Unlock
className={styles.thumbnail__unlocked}
role="img"
title={t('table.thumbnail.restricted.unlocked')}
/>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.container {
justify-content: center;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Col, Row, useTheme } from 'dataverse-design-system'
import { TailSpin } from 'react-loader-spinner'
import styles from './SpinnerSymbol.module.scss'
import { useTranslation } from 'react-i18next'

export function SpinnerSymbol() {
const theme = useTheme()
const { t } = useTranslation('files')
return (
<Row className="justify-content-md-center">
<Row className={styles.container}>
<Col md="auto">
<TailSpin
height="30"
width="30"
ariaLabel="tail-spin-loading"
ariaLabel={t('filesLoading')}
color={theme.color.primary}
radius="1"
wrapperStyle={{}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styles from './TablePagination.module.scss'
import { useTranslation } from 'react-i18next'

export function PageSizeSelector({
pageSize,
Expand All @@ -7,18 +8,21 @@ export function PageSizeSelector({
pageSize: number
setPageSize: (pageSize: number) => void
}) {
const { t } = useTranslation('files')
const availableSizes = [10, 25, 50]

return (
<div className={styles['size-selector-container']}>
<label htmlFor="page-size-selector" className={styles['size-selector-container__text']}>
Files per page
<label htmlFor="files-per-page-selector" className={styles['size-selector-container__text']}>
{t('table.pagination.pageSize')}
</label>
<select
id="page-size-selector"
id="files-per-page-selector"
value={pageSize}
onChange={(e) => {
setPageSize(Number(e.target.value))
}}>
{[10, 25, 50].map((pageSize) => (
{availableSizes.map((pageSize) => (
<option key={pageSize} value={pageSize}>
{pageSize}
</option>
Expand Down
2 changes: 1 addition & 1 deletion src/stories/files/FileMockLoadingRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { File } from '../../files/domain/models/File'
export class FileMockLoadingRepository implements FileRepository {
// eslint-disable-next-line unused-imports/no-unused-vars
getAllByDatasetPersistentId(persistentId: string, version?: string): Promise<File[]> {
return new Promise((resolve) => {
return new Promise(() => {
setTimeout(() => {
// Do nothing
}, 0)
Expand Down

0 comments on commit ca561f6

Please sign in to comment.