refactor: Improve i18n for components

This commit is contained in:
Myzel394 2023-03-05 11:31:39 +01:00
parent e41825a614
commit 012d78f8ed
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
10 changed files with 57 additions and 61 deletions

View File

@ -0,0 +1,33 @@
{
"ResendMailButton": {
"label": "Resend Mail"
},
"OpenMailButton": {
"label": "Open Mail"
},
"TimedButton": {
"remainingTime_one": "({{count}})",
"remainingTime_other": "({{count}})"
},
"ErrorLoadingDataMessage": {
"tryAgain": "Try Again"
},
"LockNavigationContextProvider": {
"title": "Are you sure you want to leave?",
"description": "You have unsaved changes. If you leave, your changes will be lost.",
"continueLabel": "Leave"
},
"StringPoolField": {
"addCustom": {
"label": "Add custom"
},
"forms": {
"addNew": {
"title": "Add new value",
"description": "Enter your characters you would like to include",
"label": "Characters",
"submit": "Add"
}
}
}
}

View File

@ -22,24 +22,6 @@
}, },
"components": { "components": {
"ResendMailButton": {
"label": "Resend Mail"
},
"OpenMailButton": {
"label": "Open Mail"
},
"TimedButton": {
"remainingTime_one": "({{count}})",
"remainingTime_other": "({{count}})"
},
"ErrorLoadingDataMessage": {
"tryAgain": "Try Again"
},
"LockNavigationContextProvider": {
"title": "Are you sure you want to leave?",
"description": "You have unsaved changes. If you leave, your changes will be lost.",
"continueLabel": "Leave"
},
"passwordShareConfirmationDialog": { "passwordShareConfirmationDialog": {
"title": "Share Password?", "title": "Share Password?",
"description": "An extension is asking for your password. Do you want to share it? Only continue if you initiated this action.", "description": "An extension is asking for your password. Do you want to share it? Only continue if you initiated this action.",
@ -48,19 +30,6 @@
"doNotShare": "Do not share", "doNotShare": "Do not share",
"decideLater": "Decide later", "decideLater": "Decide later",
"doNotAskAgain": "Do not ask again" "doNotAskAgain": "Do not ask again"
},
"StringPoolField": {
"addCustom": {
"label": "Add custom"
},
"forms": {
"addNew": {
"title": "Add new value",
"description": "Enter your characters you would like to include",
"label": "Characters",
"submit": "Add"
} }
} }
} }
},
}

View File

@ -22,7 +22,7 @@ export interface LockNavigationContextProviderProps {
export default function LockNavigationContextProvider({ export default function LockNavigationContextProvider({
children, children,
}: LockNavigationContextProviderProps): JSX.Element { }: LockNavigationContextProviderProps): JSX.Element {
const {t} = useTranslation() const {t} = useTranslation(["components", "common"])
const navigate = useNavigate() const navigate = useNavigate()
const [isLocked, setIsLocked] = useState<boolean>(false) const [isLocked, setIsLocked] = useState<boolean>(false)
@ -97,18 +97,18 @@ export default function LockNavigationContextProvider({
{children} {children}
</LockNavigationContext.Provider> </LockNavigationContext.Provider>
<Dialog open={showDialog} onClose={cancel}> <Dialog open={showDialog} onClose={cancel}>
<DialogTitle>{t("components.LockNavigationContextProvider.title")}</DialogTitle> <DialogTitle>{t("LockNavigationContextProvider.title")}</DialogTitle>
<DialogContent> <DialogContent>
<DialogContentText> <DialogContentText>
{t("components.LockNavigationContextProvider.description")} {t("LockNavigationContextProvider.description")}
</DialogContentText> </DialogContentText>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button startIcon={<TiCancel />} onClick={cancel}> <Button startIcon={<TiCancel />} onClick={cancel}>
{t("general.cancelLabel")} {t("general.cancelLabel", {ns: "common"})}
</Button> </Button>
<Button startIcon={<MdLogout />} onClick={leave}> <Button startIcon={<MdLogout />} onClick={leave}>
{t("components.LockNavigationContextProvider.continueLabel")} {t("LockNavigationContextProvider.continueLabel")}
</Button> </Button>
</DialogActions> </DialogActions>
</Dialog> </Dialog>

View File

@ -12,7 +12,7 @@ export default function ErrorLoadingDataMessage({
message, message,
onRetry, onRetry,
}: ErrorLoadingDataMessageProps): ReactElement { }: ErrorLoadingDataMessageProps): ReactElement {
const {t} = useTranslation() const {t} = useTranslation("components")
return ( return (
<Grid container spacing={2} flexDirection="column" alignItems="center"> <Grid container spacing={2} flexDirection="column" alignItems="center">
@ -20,9 +20,7 @@ export default function ErrorLoadingDataMessage({
<Alert severity="error">{message}</Alert> <Alert severity="error">{message}</Alert>
</Grid> </Grid>
<Grid item> <Grid item>
<Button onClick={onRetry}> <Button onClick={onRetry}>{t("ErrorLoadingDataMessage.tryAgain")}</Button>
{t("components.ErrorLoadingDataMessage.tryAgain")}
</Button>
</Grid> </Grid>
</Grid> </Grid>
) )

View File

@ -12,14 +12,14 @@ export interface OpenMailButtonProps {
} }
export default function OpenMailButton({domain}: OpenMailButtonProps): ReactElement { export default function OpenMailButton({domain}: OpenMailButtonProps): ReactElement {
const {t} = useTranslation() const {t} = useTranslation("components")
const userAgent = new UAParser() const userAgent = new UAParser()
if (userAgent.getOS().name === "Android" && APP_LINK_MAP[domain]) { if (userAgent.getOS().name === "Android" && APP_LINK_MAP[domain]) {
return ( return (
<Button startIcon={<IoMdMailOpen />} variant="text" href={APP_LINK_MAP[domain].android}> <Button startIcon={<IoMdMailOpen />} variant="text" href={APP_LINK_MAP[domain].android}>
{t("components.OpenMailButton.label")} {t("OpenMailButton.label")}
</Button> </Button>
) )
} }

View File

@ -28,22 +28,22 @@ export default function AddNewDialog({
open = false, open = false,
onClose, onClose,
}: StringPoolFieldProps): ReactElement { }: StringPoolFieldProps): ReactElement {
const {t} = useTranslation() const {t} = useTranslation(["components", "common"])
const [value, setValue] = useState<string>("") const [value, setValue] = useState<string>("")
return ( return (
<Dialog open={open} onClose={onClose}> <Dialog open={open} onClose={onClose}>
<DialogTitle>{t("components.StringPoolField.forms.addNew.title")}</DialogTitle> <DialogTitle>{t("StringPoolField.forms.addNew.title")}</DialogTitle>
<DialogContent> <DialogContent>
<DialogContentText> <DialogContentText>
{t("components.StringPoolField.forms.addNew.description")} {t("StringPoolField.forms.addNew.description")}
</DialogContentText> </DialogContentText>
<Box my={2}> <Box my={2}>
<TextField <TextField
value={value} value={value}
onChange={e => setValue(e.target.value)} onChange={e => setValue(e.target.value)}
label={t("components.StringPoolField.forms.addNew.label")} label={t("StringPoolField.forms.addNew.label")}
name="addNew" name="addNew"
fullWidth fullWidth
autoFocus autoFocus
@ -53,14 +53,14 @@ export default function AddNewDialog({
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button onClick={onClose} startIcon={<TiCancel />} variant="text"> <Button onClick={onClose} startIcon={<TiCancel />} variant="text">
{t("general.cancelLabel")} {t("general.cancelLabel", {ns: "common"})}
</Button> </Button>
<Button <Button
onClick={() => onCreated(value)} onClick={() => onCreated(value)}
variant="contained" variant="contained"
startIcon={<MdCheck />} startIcon={<MdCheck />}
> >
{t("components.StringPoolField.forms.addNew.submit")} {t("StringPoolField.forms.addNew.submit")}
</Button> </Button>
</DialogActions> </DialogActions>
</Dialog> </Dialog>

View File

@ -51,7 +51,7 @@ export default function StringPoolField({
fullWidth, fullWidth,
...props ...props
}: StringPoolFieldProps): ReactElement { }: StringPoolFieldProps): ReactElement {
const {t} = useTranslation() const {t} = useTranslation("components")
const reversedPoolsMap = useMemo( const reversedPoolsMap = useMemo(
() => Object.fromEntries(Object.entries(pools).map(([key, value]) => [value, key])), () => Object.fromEntries(Object.entries(pools).map(([key, value]) => [value, key])),
@ -155,9 +155,7 @@ export default function StringPoolField({
<ListItemIcon> <ListItemIcon>
<MdAdd /> <MdAdd />
</ListItemIcon> </ListItemIcon>
<ListItemText <ListItemText primary={t("StringPoolField.addCustom.label")} />
primary={t("components.StringPoolField.addCustom.label")}
/>
</MenuItem> </MenuItem>
)} )}
</Select> </Select>

View File

@ -18,7 +18,7 @@ export default function TimedButton({
disabled: parentDisabled = false, disabled: parentDisabled = false,
...props ...props
}: TimedButtonProps): ReactElement { }: TimedButtonProps): ReactElement {
const {t} = useTranslation() const {t} = useTranslation("components")
const [startDate, resetInterval] = useIntervalUpdate(1000) const [startDate, resetInterval] = useIntervalUpdate(1000)
@ -35,9 +35,7 @@ export default function TimedButton({
}} }}
> >
<span>{children} </span> <span>{children} </span>
{secondsLeft > 0 && ( {secondsLeft > 0 && <span>{t("TimedButton.remainingTime", {count: secondsLeft})}</span>}
<span>{t("components.TimedButton.remainingTime", {count: secondsLeft})}</span>
)}
</LoadingButton> </LoadingButton>
) )
} }

View File

@ -19,8 +19,8 @@ export default function ResendMailButton({
email, email,
sameRequestToken, sameRequestToken,
}: ResendMailButtonProps): ReactElement { }: ResendMailButtonProps): ReactElement {
const {t} = useTranslation("components")
const settings = useLoaderData() as ServerSettings const settings = useLoaderData() as ServerSettings
const {t} = useTranslation()
const mutation = useMutation<SimpleDetailResponse, AxiosError, void>(() => const mutation = useMutation<SimpleDetailResponse, AxiosError, void>(() =>
resendEmailLoginCode({ resendEmailLoginCode({
@ -37,7 +37,7 @@ export default function ResendMailButton({
startIcon={<MdMail />} startIcon={<MdMail />}
onClick={() => mutate()} onClick={() => mutate()}
> >
{t("components.ResendMailButton.label")} {t("ResendMailButton.label")}
</TimedButton> </TimedButton>
<MutationStatusSnackbar mutation={mutation} /> <MutationStatusSnackbar mutation={mutation} />
</> </>

View File

@ -19,7 +19,7 @@ export default function ResendMailButton({
email, email,
onEmailAlreadyVerified, onEmailAlreadyVerified,
}: ResendMailButtonProps): ReactElement { }: ResendMailButtonProps): ReactElement {
const {t} = useTranslation() const {t} = useTranslation("components")
const settings = useLoaderData() as ServerSettings const settings = useLoaderData() as ServerSettings
const mutation = useMutation<ResendEmailVerificationCodeResponse, AxiosError, void>( const mutation = useMutation<ResendEmailVerificationCodeResponse, AxiosError, void>(
@ -41,7 +41,7 @@ export default function ResendMailButton({
startIcon={<MdMail />} startIcon={<MdMail />}
onClick={() => mutate()} onClick={() => mutate()}
> >
{t("components.ResendMailButton.label")} {t("ResendMailButton.label")}
</TimedButton> </TimedButton>
<MutationStatusSnackbar mutation={mutation} /> <MutationStatusSnackbar mutation={mutation} />
</> </>