F #3951: Refactor translations (#314)

This commit is contained in:
Sergio Betanzos authored and GitHub committed 2020-10-13 19:55:05 +02:00
1 parent c95839dc66
commit 6f6c924fc4
12 files changed
+37 -21

No files matched your search

@@ -1,4 +1,4 @@
import React from 'react';
import React, { memo } from 'react';
import {
makeStyles,
@@ -44,11 +44,11 @@ const useStyles = makeStyles(theme => ({
icon: {}
}));
const ApplicationTemplateCard = React.memo(
({ value, handleEdit, handleDeploy, handleRemove }) => {
const ApplicationTemplateCard = memo(
({ value, handleEdit, handleDeploy, handleShow, handleRemove }) => {
const classes = useStyles();
const { ID, NAME, TEMPLATE } = value;
const { description, networks, roles } = TEMPLATE.BODY;
const { description, networks = [], roles = [] } = TEMPLATE.BODY;
const numberOfNetworks = Object.keys(networks)?.length ?? 0;
const numberOfTiers = Object.keys(roles)?.length ?? 0;
@@ -108,7 +108,12 @@ const ApplicationTemplateCard = React.memo(
)}
{handleDeploy && (
<Button variant="contained" size="small" onClick={handleDeploy}>
{Tr('Clone')}
{Tr('Deploy')}
</Button>
)}
{handleShow && (
<Button variant="contained" size="small" onClick={handleShow}>
{Tr('Info')}
</Button>
)}
{handleRemove && (
@@ -6,6 +6,7 @@ import { Autocomplete } from '@material-ui/lab';
import { Controller } from 'react-hook-form';
import ErrorHelper from 'client/components/FormControl/ErrorHelper';
import { Tr } from 'client/components/HOC/Translate';
const AutocompleteController = ({
control,
@@ -30,7 +31,7 @@ const AutocompleteController = ({
getOptionSelected={option => option.value === val}
renderInput={({ inputProps, ...inputParams }) => (
<TextField
label={label}
label={Tr(label)}
inputProps={{ ...inputProps, 'data-cy': cy }}
error={Boolean(error)}
helperText={
@@ -10,12 +10,13 @@ import {
import { Controller } from 'react-hook-form';
import ErrorHelper from 'client/components/FormControl/ErrorHelper';
import { Tr } from 'client/components/HOC/Translate';
const CheckboxController = memo(
({ control, cy, name, label, tooltip, error }) => (
<Controller
render={({ onChange, value }) => (
<Tooltip title={tooltip ?? ''}>
<Tooltip title={Tr(tooltip) ?? ''}>
<FormControl error={Boolean(error)}>
<FormControlLabel
control={
@@ -27,7 +28,7 @@ const CheckboxController = memo(
inputProps={{ 'data-cy': cy }}
/>
}
label={label}
label={Tr(label)}
labelPlacement="end"
/>
{Boolean(error) && <ErrorHelper label={error?.message} />}
@@ -9,6 +9,7 @@ import {
Typography
} from '@material-ui/core';
import { Info as InfoIcon } from '@material-ui/icons';
import { Tr } from 'client/components/HOC/Translate';
const useStyles = makeStyles(theme => {
const getColor = theme.palette.type === 'light' ? darken : lighten;
@@ -42,7 +43,7 @@ const ErrorHelper = ({ label, ...rest }) => {
component="span"
data-cy="error-text"
>
{label}
{Tr(label)}
</Typography>
</Box>
);
@@ -5,6 +5,7 @@ import { TextField, MenuItem } from '@material-ui/core';
import { Controller } from 'react-hook-form';
import ErrorHelper from 'client/components/FormControl/ErrorHelper';
import { Tr } from 'client/components/HOC/Translate';
const SelectController = memo(
({ control, cy, name, label, values, error }) => (
@@ -14,7 +15,7 @@ const SelectController = memo(
select
SelectProps={{ displayEmpty: true }}
fullWidth
label={label}
label={Tr(label)}
inputProps={{ 'data-cy': cy }}
error={Boolean(error)}
helperText={Boolean(error) && <ErrorHelper label={error?.message} />}
@@ -33,7 +33,7 @@ const SubmitButton = ({ isSubmitting, label, ...rest }) => {
SubmitButton.propTypes = {
isSubmitting: PropTypes.bool,
label: PropTypes.string
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node])
};
SubmitButton.defaultProps = {
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import { TextField } from '@material-ui/core';
import { Controller } from 'react-hook-form';
import { Tr } from 'client/components/HOC';
import ErrorHelper from 'client/components/FormControl/ErrorHelper';
@@ -13,7 +14,7 @@ const TextController = memo(
<TextField
fullWidth
type={type}
label={label}
label={Tr(label)}
inputProps={{ 'data-cy': cy }}
error={Boolean(error)}
helperText={Boolean(error) && <ErrorHelper label={error?.message} />}
@@ -32,7 +33,7 @@ TextController.propTypes = {
cy: PropTypes.string,
type: PropTypes.string,
name: PropTypes.string.isRequired,
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
label: PropTypes.string,
error: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.objectOf(PropTypes.any)
@@ -80,12 +80,15 @@ const TranslateProvider = ({ children }) => {
const translate = (str = '', values) => {
const context = useContext(TranslateContext);
let key = str;
if (context && context.hash && context.hash[key]) {
if (context?.hash[key]) {
key = context.hash[key];
}
if (!!values && Array.isArray(values)) {
key = sprintf(key, ...values);
}
return key;
};
@@ -97,7 +100,10 @@ const Tr = (str = '') => {
key = str[0] || '';
values = str[1];
}
return <Translate word={key} values={values} />;
const valuesTr = !!values && !Array.isArray(values) ? [values] : values;
return translate(key, valuesTr);
};
const SelectTranslate = () => {
@@ -2,7 +2,7 @@ import * as yup from 'yup';
export const STEP_FORM_SCHEMA = yup
.array(yup.string().trim())
.min(1, 'Select a cluster')
.min(1, 'Select cluster')
.max(1, 'Max. one cluster selected')
.required('Cluster field is required')
.default([]);
@@ -20,7 +20,7 @@ const ListMarketApp = ({ backButton, currentValue, handleSetData }) => {
const renderApp = app => (
<SelectCard
key={`app-${app.ID}`}
isSelected={app.ID === currentValue}
isSelected={app.ID === String(currentValue)}
handleSelect={handleSelect}
handleUnselect={handleUnselect}
{...app}
@@ -46,7 +46,7 @@ const ListMarketApp = ({ backButton, currentValue, handleSetData }) => {
ListMarketApp.propTypes = {
backButton: PropTypes.node,
currentValue: PropTypes.string,
currentValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
handleSetData: PropTypes.func
};
@@ -20,7 +20,7 @@ const ListTemplates = ({ backButton, currentValue, handleSetData }) => {
const renderTemplate = tmp => (
<SelectCard
key={`tmp-${tmp.ID}`}
isSelected={tmp.ID === currentValue}
isSelected={tmp.ID === String(currentValue)}
handleSelect={handleSelect}
handleUnselect={handleUnselect}
{...tmp}
@@ -46,7 +46,7 @@ const ListTemplates = ({ backButton, currentValue, handleSetData }) => {
ListTemplates.propTypes = {
backButton: PropTypes.node,
currentValue: PropTypes.string,
currentValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
handleSetData: PropTypes.func
};
@@ -96,7 +96,7 @@ const mapApplicationToForm = data => {
const {
NAME,
TEMPLATE: {
BODY: { networks, roles, ...application }
BODY: { networks = [], roles, ...application }
}
} = data;