Add defaultMessage, add plural syntax

This commit is contained in:
bulby97 2021-08-23 10:49:57 +02:00
parent deb6859a56
commit e9dda123a5
9 changed files with 59 additions and 14 deletions

View File

@ -30,7 +30,10 @@ const ConditionsButton = ({ onClick, className, hasConditions, variant }) => {
return ( return (
<Wrapper hasConditions={hasConditions} className={className}> <Wrapper hasConditions={hasConditions} className={className}>
<Button variant={variant} startIcon={<Settings />} onClick={onClick}> <Button variant={variant} startIcon={<Settings />} onClick={onClick}>
{formatMessage({ id: 'app.components.LeftMenuLinkContainer.settings' })} {formatMessage({
id: 'app.components.LeftMenuLinkContainer.settings',
defaultMessage: 'Settings',
})}
</Button> </Button>
</Wrapper> </Wrapper>
); );

View File

@ -28,6 +28,7 @@ const ActionRow = ({
<TableLabel textColor="neutral500"> <TableLabel textColor="neutral500">
{formatMessage({ {formatMessage({
id: 'Settings.permissions.conditions.can', id: 'Settings.permissions.conditions.can',
defaultMessage: 'Can',
})} })}
&nbsp; &nbsp;
</TableLabel> </TableLabel>
@ -41,6 +42,7 @@ const ActionRow = ({
&nbsp; &nbsp;
{formatMessage({ {formatMessage({
id: 'Settings.permissions.conditions.when', id: 'Settings.permissions.conditions.when',
defaultMessage: 'When',
})} })}
</TableLabel> </TableLabel>
</Row> </Row>

View File

@ -118,16 +118,14 @@ const ConditionsModal = ({
const shouldDisplayChevron = index < translatedHeaders.length - 1; const shouldDisplayChevron = index < translatedHeaders.length - 1;
return ( return (
<> <React.Fragment key={key}>
<TextButton textColor="neutral800" key={key}> <TextButton textColor="neutral800">{element}</TextButton>
{element}
</TextButton>
{shouldDisplayChevron && ( {shouldDisplayChevron && (
<Icon> <Icon>
<After /> <After />
</Icon> </Icon>
)} )}
</> </React.Fragment>
); );
})} })}
</Stack> </Stack>
@ -137,12 +135,19 @@ const ConditionsModal = ({
<H2> <H2>
{formatMessage({ {formatMessage({
id: 'Settings.permissions.conditions.define-conditions', id: 'Settings.permissions.conditions.define-conditions',
defaultMessage: 'Define conditions',
})} })}
</H2> </H2>
<Separator /> <Separator />
<Box> <Box>
{actionsToDisplay.length === 0 && ( {actionsToDisplay.length === 0 && (
<Text>{formatMessage({ id: 'Settings.permissions.conditions.no-actions' })}</Text> <Text>
{formatMessage({
id: 'Settings.permissions.conditions.no-actions',
defaultMessage:
'You first need to select actions (create, read, update, ...) before defining conditions on them.',
})}
</Text>
)} )}
{actionsToDisplay.map(({ actionId, label, pathToConditionsObject }, index) => { {actionsToDisplay.map(({ actionId, label, pathToConditionsObject }, index) => {
const name = pathToConditionsObject.join('..'); const name = pathToConditionsObject.join('..');
@ -167,13 +172,14 @@ const ConditionsModal = ({
<ModalFooter <ModalFooter
startActions={ startActions={
<Button variant="tertiary" onClick={onToggle}> <Button variant="tertiary" onClick={onToggle}>
{formatMessage({ id: 'app.components.Button.cancel' })} {formatMessage({ id: 'app.components.Button.cancel', defaultMessage: 'Cancel' })}
</Button> </Button>
} }
endActions={ endActions={
<Button onClick={handleSubmit}> <Button onClick={handleSubmit}>
{formatMessage({ {formatMessage({
id: 'Settings.permissions.conditions.apply', id: 'Settings.permissions.conditions.apply',
defaultMessage: 'Apply',
})} })}
</Button> </Button>
} }

View File

@ -111,7 +111,9 @@ const Permissions = forwardRef(({ layout, isFormDisabled, permissions }, ref) =>
<TabGroup id="tabs"> <TabGroup id="tabs">
<Tabs> <Tabs>
{TAB_LABELS.map(tabLabel => ( {TAB_LABELS.map(tabLabel => (
<Tab key={tabLabel.id}>{formatMessage({ id: tabLabel.labelId })}</Tab> <Tab key={tabLabel.id}>
{formatMessage({ id: tabLabel.labelId, defaultMessage: tabLabel.defaultMessage })}
</Tab>
))} ))}
</Tabs> </Tabs>
<TabPanels> <TabPanels>

View File

@ -91,7 +91,7 @@ const SubCategory = ({ categoryName, isFormDisabled, subCategoryName, actions, p
indeterminate={hasSomeActionsSelected} indeterminate={hasSomeActionsSelected}
value={hasAllActionsSelected} value={hasAllActionsSelected}
> >
{formatMessage({ id: 'app.utils.select-all' })} {formatMessage({ id: 'app.utils.select-all', defaultMessage: 'Select all' })}
</Checkbox> </Checkbox>
</Box> </Box>
</Row> </Row>

View File

@ -63,7 +63,10 @@ function SettingsPage() {
return <Redirect to="/settings/application-infos" />; return <Redirect to="/settings/application-infos" />;
} }
const settingTitle = formatMessage({ id: 'app.components.LeftMenuLinkContainer.settings' }); const settingTitle = formatMessage({
id: 'app.components.LeftMenuLinkContainer.settings',
defaultMessage: 'Settings',
});
return ( return (
<SettingsSearchHeaderProvider value={{ toggleHeaderSearch }}> <SettingsSearchHeaderProvider value={{ toggleHeaderSearch }}>

View File

@ -127,7 +127,7 @@
"Settings.roles.create.title": "Create a role", "Settings.roles.create.title": "Create a role",
"Settings.roles.created": "Role created", "Settings.roles.created": "Role created",
"Settings.roles.edit.title": "Edit a role", "Settings.roles.edit.title": "Edit a role",
"Settings.roles.form.button.users-with-role": "{number} users with this role", "Settings.roles.form.button.users-with-role": "{number, plural, =0 {# users} one {# user} other {# users}} with this role",
"Settings.roles.form.created": "Created", "Settings.roles.form.created": "Created",
"Settings.roles.form.description": "Name and description of the role", "Settings.roles.form.description": "Name and description of the role",
"Settings.roles.form.input.description": "Description", "Settings.roles.form.input.description": "Description",

View File

@ -169,6 +169,7 @@ const CreatePage = () => {
<Text highlighted> <Text highlighted>
{formatMessage({ {formatMessage({
id: 'Settings.roles.form.title', id: 'Settings.roles.form.title',
defaultMessage: 'Details',
})} })}
</Text> </Text>
</Box> </Box>
@ -176,6 +177,7 @@ const CreatePage = () => {
<Text textColor="neutral500" small> <Text textColor="neutral500" small>
{formatMessage({ {formatMessage({
id: 'Settings.roles.form.description', id: 'Settings.roles.form.description',
defaultMessage: 'Name and description of the role',
})} })}
</Text> </Text>
</Box> </Box>
@ -184,6 +186,8 @@ const CreatePage = () => {
{formatMessage( {formatMessage(
{ {
id: 'Settings.roles.form.button.users-with-role', id: 'Settings.roles.form.button.users-with-role',
defaultMessage:
'{number, plural, =0 {# users} one {# user} other {# users}} with this role',
}, },
{ number: 0 } { number: 0 }
)} )}
@ -194,7 +198,10 @@ const CreatePage = () => {
<TextInput <TextInput
name="name" name="name"
error={errors.name && formatMessage({ id: errors.name })} error={errors.name && formatMessage({ id: errors.name })}
label={formatMessage({ id: 'Settings.roles.form.input.name' })} label={formatMessage({
id: 'Settings.roles.form.input.name',
defaultMessage: 'Name',
})}
onChange={handleChange} onChange={handleChange}
onBlur={handleBlur} onBlur={handleBlur}
value={values.name} value={values.name}
@ -202,7 +209,10 @@ const CreatePage = () => {
</GridItem> </GridItem>
<GridItem col={6}> <GridItem col={6}>
<Textarea <Textarea
label={formatMessage({ id: 'Settings.roles.form.input.description' })} label={formatMessage({
id: 'Settings.roles.form.input.description',
defaultMessage: 'Description',
})}
name="description" name="description"
error={errors.name && formatMessage({ id: errors.name })} error={errors.name && formatMessage({ id: errors.name })}
onChange={handleChange} onChange={handleChange}

View File

@ -0,0 +1,19 @@
/**
*
* Tests for CreatePage
*
*/
import React from 'react';
import { render } from '@testing-library/react';
import { CreatePage } from './index';
describe('<CreatePage />', () => {
it('renders and matches the snapshot', () => {
const {
container: { firstChild },
} = render(<CreatePage />);
expect(firstChild).toMatchInlineSnapshot();
});
});