Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(settings): translate new persona and delegate rights labels #311

Merged
merged 4 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = {
defaultContexts: [],
defaultNS: 'en',
jsonSpace: 4,
compatibilityJSON: 'v3'
compatibilityJSON: 'v3',
discardOldKeys: false
}
]
]
Expand Down
13 changes: 10 additions & 3 deletions src/settings/accounts-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,19 @@ export const AccountsSettings = (): JSX.Element => {
ace,
(accumulator: Array<DelegateType>, item, idx) => {
const index = findIndex(accumulator, { email: item.d });
const translatedRight = t('settings.account.delegates.right', {
context: item.right.toLowerCase(),
defaultValue: item.right
});
if (index === -1) {
accumulator.push({ email: item.d || '', right: item.right, id: idx.toString() });
accumulator.push({ email: item.d || '', right: translatedRight, id: idx.toString() });
} else {
accumulator.push({
email: item.d || '',
right: `${item.right} and ${accumulator[index].right}`,
right: t('settings.account.delegates.multiple_rights', {
defaultValue: `{{rights.0]}} and {{rights.1}}`,
rights: [translatedRight, accumulator[index].right]
}),
id: idx.toString()
});
accumulator.splice(index, 1);
Expand All @@ -374,7 +381,7 @@ export const AccountsSettings = (): JSX.Element => {
setDelegates(result);
}
});
}, []);
}, [t]);

const personaSettings = useMemo<JSX.Element | null>(() => {
const identity = identities[selectedIdentityId];
Expand Down
16 changes: 11 additions & 5 deletions src/settings/components/account-settings/accounts-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ListV2,
ListItem
} from '@zextras/carbonio-design-system';
import type { TFunction } from 'i18next';
import { map } from 'lodash';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
Expand All @@ -31,11 +32,15 @@ const List = styled(ListV2)`

function getNewPersonaNextIdentityName(
numberToCheck: number,
unavailableIdentityNames: Array<string>
unavailableIdentityNames: Array<string>,
t: TFunction
): string {
const newPersonaNextIdentityName = `New Persona ${numberToCheck}`;
const newPersonaNextIdentityName = t('settings.account.new_identity', {
defaultValue: `New Persona {{number}}`,
number: numberToCheck
});
if (unavailableIdentityNames.includes(newPersonaNextIdentityName)) {
return getNewPersonaNextIdentityName(numberToCheck + 1, unavailableIdentityNames);
return getNewPersonaNextIdentityName(numberToCheck + 1, unavailableIdentityNames, t);
}
return newPersonaNextIdentityName;
}
Expand Down Expand Up @@ -69,7 +74,7 @@ const AccountsList = ({
[...identitiesDefault, ...identities],
(item) => item._attrs?.zimbraPrefIdentityName || ''
);
const newPersonaName = getNewPersonaNextIdentityName(1, unavailableIdentityNames);
const newPersonaName = getNewPersonaNextIdentityName(1, unavailableIdentityNames, t);

addIdentity(`${createListRequestIdRef.current}`, {
zimbraPrefIdentityName: newPersonaName,
Expand All @@ -80,12 +85,13 @@ const AccountsList = ({
});
createListRequestIdRef.current += 1;
setSelectedIdentityId(identities.length);
}, [identitiesDefault, identities, addIdentity, setSelectedIdentityId]);
}, [identitiesDefault, identities, addIdentity, setSelectedIdentityId, t]);

const onConfirmDelete = useCallback((): void => {
removeIdentity(identities[selectedIdentityId].id);
setSelectedIdentityId(selectedIdentityId - 1);
}, [identities, removeIdentity, selectedIdentityId, setSelectedIdentityId]);

const onDelete = useCallback((): void => {
const closeModal = createModal({
title: t('label.permanent_delete_title', 'Are you sure to permanently delete this Persona?'),
Expand Down
8 changes: 8 additions & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@
"unable_to_parse_query": "Unable to complete the search, clear it and retry"
},
"settings": {
"account": {
"delegates": {
"multiple_rights": "{{rights.0}} and {{rights.1}}",
"right_sendas": "SendAs",
"right_sendonbehalfof": "SendOnBehalfOf"
},
"new_identity": "New Persona {{number}}"
},
"accounts": "Accounts",
"app": "Settings",
"appearance": {
Expand Down