Skip to content

Commit

Permalink
feat: add fixed translations for add row label
Browse files Browse the repository at this point in the history
  • Loading branch information
siddarth2824 committed Dec 10, 2024
1 parent a06fa34 commit 2b5a9ec
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 29 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface CheckboxProps extends ChakraCheckboxProps {
colorScheme?: FieldColorScheme

/**
* Selected language to display label.
* Selected language to get translated label.
*/
selectedLanguage?: Language
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Field/Attachment/Attachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import { Language } from '~shared/types'

import { ATTACHMENT_THEME_KEY } from '~theme/components/Field/Attachment'
import { ThemeColorScheme } from '~theme/foundations/colours'
import { MAXIMUM_FILE_LABEL_TRANSLATIONS } from '~constants/fixedTranslations'

import { downloadFile } from './utils/downloadFile'
import { AttachmentStylesProvider } from './AttachmentContext'
import { AttachmentDropzone } from './AttachmentDropzone'
import { AttachmentFileInfo } from './AttachmentFileInfo'
import { MAXIMUM_FILE_LABEL_TRANSLATIONS } from './constants'
import {
getFileExtension,
getInvalidFileExtensionsInZip,
Expand Down
8 changes: 0 additions & 8 deletions frontend/src/components/Field/Attachment/constants.ts

This file was deleted.

45 changes: 45 additions & 0 deletions frontend/src/constants/fixedTranslations.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import simplur from 'simplur'

import { Language } from '~shared/types'

export const OTHERS_TRANSLATED_LABEL: Record<Language, string> = {
Expand All @@ -20,3 +22,46 @@ export const NOTHING_FOUND_LABEL_TRANSLATIONS: Record<Language, string> = {
[Language.MALAY]: 'Tiada hasil yang sepadan',
[Language.TAMIL]: 'முடிவுகள் எதுவும் பொருந்தவில்லை',
}

export const MAXIMUM_FILE_LABEL_TRANSLATIONS: Record<Language, string> = {
[Language.ENGLISH]: 'Maximum file size:',
[Language.CHINESE]: '文件限制:不超过',
[Language.MALAY]: 'Saiz fail maksimum:',
[Language.TAMIL]: 'கோப்பின் அதிகபட்ச அளவு:',
}

export const ADD_ANOTHER_ROW_LABEL_TRANSLATIONS: Record<Language, string> = {
[Language.ENGLISH]: 'Add another row',
[Language.CHINESE]: '添加另一行',
[Language.MALAY]: 'Tambah satu lagi baris',
[Language.TAMIL]: 'மற்றொரு வரிசையைச் சேர்க்கவும்',
}

export function getTranslationsForTableFieldRows({
maxRows,
currentRows,
selectedLanguage,
}: {
maxRows: number | ''
currentRows: number
selectedLanguage: Language
}) {
switch (selectedLanguage) {
case Language.CHINESE:
return maxRows
? `${currentRows} 行,最多 ${maxRows} 行`
: `${currentRows} 行`
case Language.MALAY:
return maxRows
? `${currentRows} daripada maksimum ${maxRows} baris`
: `${currentRows} baris`
case Language.TAMIL:
return maxRows
? `அதிகபட்சம் ${currentRows} வரிசைகளுக்கு ${maxRows}`
: `வரிசைகளுக்கு ${currentRows}`
default:
return maxRows
? simplur`${currentRows} out of max ${maxRows} row[|s]`
: simplur`${currentRows} row[|s]`
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@ import { VerifiableFieldBase, VerifiableFieldSchema } from '../../types'
import { useVerifiableField } from '../../VerifiableFieldContext'
import { VerificationBox } from '../VerificationBox'

type VerifyTranslations = {
Verify: string
Verified: string
}

const VERIFY_LABEL_TRANSLATIONS: Record<Language, VerifyTranslations> = {
[Language.ENGLISH]: { Verify: 'Verify', Verified: 'Verified' },
[Language.CHINESE]: { Verify: '验证', Verified: '已验证' },
[Language.MALAY]: { Verify: 'Sahkan', Verified: 'Disahkan' },
[Language.TAMIL]: {
Verify: 'சரிபார்க்கவும்',
Verified: 'சரிபார்க்கப்பட்டது',
},
}
import { VERIFY_LABEL_TRANSLATIONS } from './constants'

export interface BaseVerifiableFieldProps extends BaseFieldProps {
schema: VerifiableFieldSchema<FormFieldWithId<VerifiableFieldBase>>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Language } from '~shared/types'

type VerifyTranslations = {
Verify: string
Verified: string
}

export const VERIFY_LABEL_TRANSLATIONS: Record<Language, VerifyTranslations> = {
[Language.ENGLISH]: { Verify: 'Verify', Verified: 'Verified' },
[Language.CHINESE]: { Verify: '验证', Verified: '已验证' },
[Language.MALAY]: { Verify: 'Sahkan', Verified: 'Disahkan' },
[Language.TAMIL]: {
Verify: 'சரிபார்க்கவும்',
Verified: 'சரிபார்க்கப்பட்டது',
},
}
24 changes: 19 additions & 5 deletions frontend/src/templates/Field/Table/AddRowFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,38 @@ import { BiPlus } from 'react-icons/bi'
import { Box, Stack, Text, VisuallyHidden } from '@chakra-ui/react'
import simplur from 'simplur'

import { Language } from '~shared/types'

import {
ADD_ANOTHER_ROW_LABEL_TRANSLATIONS,
getTranslationsForTableFieldRows,
} from '~constants/fixedTranslations'
import Button from '~components/Button'

interface AddRowFooterProps {
isDisabled?: boolean
handleAddRow: () => void
currentRows: number
maxRows: number | ''
selectedLanguage?: Language
}

export const AddRowFooter = ({
isDisabled,
currentRows,
maxRows,
handleAddRow: handleAddRowProp,
selectedLanguage = Language.ENGLISH,
}: AddRowFooterProps): JSX.Element => {
// State to decide whether to announce row changes to screen readers
const [hasAddedRows, setHasAddedRows] = useState(false)
const maxRowDescription = useMemo(() => {
return maxRows
? simplur`${currentRows} out of max ${maxRows} row[|s]`
: simplur`${currentRows} row[|s]`
}, [currentRows, maxRows])
return getTranslationsForTableFieldRows({
maxRows,
currentRows,
selectedLanguage,
})
}, [currentRows, maxRows, selectedLanguage])

const maxRowAriaDescription = useMemo(() => {
return maxRows
Expand All @@ -37,6 +47,10 @@ export const AddRowFooter = ({
setHasAddedRows(true)
}, [handleAddRowProp])

const addRowLabel = useMemo(() => {
return ADD_ANOTHER_ROW_LABEL_TRANSLATIONS[selectedLanguage]
}, [selectedLanguage])

return (
<Stack
mt="0.75rem"
Expand All @@ -51,7 +65,7 @@ export const AddRowFooter = ({
type="button"
onClick={handleAddRow}
>
Add another row
{addRowLabel}
<VisuallyHidden>
to the table field. {maxRowAriaDescription}
</VisuallyHidden>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/templates/Field/Table/TableField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export const TableField = ({
currentRows={fields.length}
maxRows={schema.maximumRows}
handleAddRow={handleAddRow}
selectedLanguage={selectedLanguage}
/>
) : null}
</TableFieldContainer>
Expand Down

0 comments on commit 2b5a9ec

Please sign in to comment.