Skip to content

Commit 3674643

Browse files
authored
Merge pull request #1891 from jicruz96/attachment-translations
extract translate-able strings -- Attachment component
2 parents 224631a + ef37381 commit 3674643

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

components/CommentModal/Attachment.tsx

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ChangeEventHandler, useCallback, useEffect, useState } from "react"
44
import { Button, Col, Form, InputGroup, Row, Spinner } from "../bootstrap"
55
import { AttachmentInfo, UseDraftTestimonyAttachment } from "../db"
66
import { External } from "../links"
7+
import { useTranslation } from "next-i18next"
78

89
export function Attachment({
910
attachment,
@@ -65,11 +66,10 @@ const Label = ({
6566
}: {
6667
attachment: UseDraftTestimonyAttachment
6768
}) => {
69+
const { t } = useTranslation("attachment")
6870
return (
6971
<Form.Label>
70-
<span className="me-1">
71-
(Optional) Provide your testimony as a file attachment
72-
</span>
72+
<span className="me-1">{t("provide_testimony_as_file")}</span>
7373
{status === "loading" && <Spinner animation="border" size="sm" />}
7474
{status === "error" && (
7575
<FontAwesomeIcon icon={faExclamationTriangle} className="text-danger" />
@@ -85,13 +85,10 @@ export const AttachmentLink = ({
8585
attachment: AttachmentInfo
8686
className?: string
8787
}) => {
88-
const linkLabel = [
89-
"Attached",
90-
name ?? "Testimony",
91-
size ? formatSize(size) : null
92-
]
93-
.filter(Boolean)
94-
.join(" - ")
88+
const { t } = useTranslation("attachment")
89+
const linkLabelParts = [t("attached"), name ?? t("testimony")]
90+
if (size) linkLabelParts.push(formatSize(size))
91+
const linkLabel = linkLabelParts.join(" - ")
9592
return (
9693
<External className={className} href={url}>
9794
{linkLabel}
@@ -106,13 +103,10 @@ const Attached = ({
106103
attachment: UseDraftTestimonyAttachment
107104
confirmRemove: boolean
108105
}) => {
106+
const { t } = useTranslation("attachment")
109107
const { url, name, size, id, remove, status } = attachment
110108
const onClick = () => {
111-
if (
112-
!confirmRemove ||
113-
confirm("Are you sure you want to remove your attachment?")
114-
)
115-
remove()
109+
if (!confirmRemove || confirm(t("confirm_remove"))) remove()
116110
}
117111
return (
118112
<Row className="align-items-center">
@@ -128,7 +122,7 @@ const Attached = ({
128122
onClick={onClick}
129123
disabled={status === "loading"}
130124
>
131-
Remove
125+
{t("remove")}
132126
</Button>
133127
</Col>
134128
</Row>
@@ -140,19 +134,18 @@ const StatusMessage = ({
140134
}: {
141135
attachment: UseDraftTestimonyAttachment
142136
}) => {
137+
const { t } = useTranslation("attachment")
143138
if (status === "error") {
144139
let message: string
145140
if (error?.code === "storage/unauthorized") {
146-
message = "Invalid file. Please upload PDF's less than 10 MB"
141+
message = t("error.storage_unauthorized")
147142
} else {
148-
message = "Something went wrong. Please try again."
143+
message = t("error.generic")
149144
}
150145

151146
return <Form.Text className="text-danger">{message}</Form.Text>
152147
} else if (status === "ok" && !id) {
153-
return (
154-
<Form.Text>Files must be PDF documents and less than 10 MB.</Form.Text>
155-
)
148+
return <Form.Text>{t("file_requirements")}</Form.Text>
156149
} else {
157150
return null
158151
}

pages/submit-testimony.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default createPage({
2323

2424
export const getStaticProps = createGetStaticTranslationProps([
2525
"auth",
26+
"attachment",
2627
"common",
2728
"footer",
2829
"testimony",

public/locales/en/attachment.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"attached": "Attached",
3+
"confirm_remove": "Are you sure you want to remove your attachment?",
4+
"error.generic": "Something went wrong. Please try again.",
5+
"error.storage_unauthorized": "Invalid file. Please upload PDF's less than 10 MB",
6+
"file_requirements": "Files must be PDF documents and less than 10 MB.",
7+
"provide_testimony_as_file": "(Optional) Provide your testimony as a file attachment",
8+
"remove": "Remove"
9+
}

0 commit comments

Comments
 (0)