Skip to content

Commit

Permalink
Merge pull request #2704 from glific/feature/auto-translate
Browse files Browse the repository at this point in the history
Added export without auto translation option
  • Loading branch information
mdshamoon authored Jan 18, 2024
2 parents 2f36c76 + b328a2f commit b921c28
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/containers/Flow/FlowTranslation.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
z-index: 100000;
font-size: 20px;
}

.FormHelper {
padding-left: 16px;
margin-bottom: 10px;
}

.Radio {
padding: 0px 8px;
}
47 changes: 42 additions & 5 deletions src/containers/Flow/FlowTranslation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Radio,
Backdrop,
CircularProgress,
FormHelperText,
} from '@mui/material';
import { useTranslation } from 'react-i18next';
import styles from './FlowTranslation.module.css';
Expand Down Expand Up @@ -82,14 +83,20 @@ export const FlowTranslation = ({ flowId, setDialog, loadFlowEditor }: FlowTrans
};

const handleExport = async () => {
exportFlowTranslations({ variables: { id: flowId } });
exportFlowTranslations({ variables: { id: flowId, addTranslation: false } });
};

const handleAutoExport = () => {
exportFlowTranslations({ variables: { id: flowId, addTranslation: true } });
};

const handleOk = () => {
if (action === 'auto') {
handleAuto();
} else if (action === 'export') {
handleExport();
} else if (action === 'export-auto') {
handleAutoExport();
}
};

Expand Down Expand Up @@ -119,6 +126,29 @@ export const FlowTranslation = ({ flowId, setDialog, loadFlowEditor }: FlowTrans
return <BackdropLoader text="Please wait while the flow is getting translated..." />;
}

const translationOptions = [
{
value: 'auto',
label: t('Automatic translation'),
description: t('Generate translations for all available languages automatically.'),
},
{
value: 'export-auto',
label: t('Export with auto translate'),
description: t('Translate the content and export it as a CSV file.'),
},
{
value: 'export',
label: t('Export translations'),
description: t('Export the content without any automatic translations.'),
},
{
value: 'import',
label: t('Import translations'),
description: t('Import translations from a CSV file into the application.'),
},
];

const dialogContent = (
<div>
<FormControl>
Expand All @@ -129,9 +159,16 @@ export const FlowTranslation = ({ flowId, setDialog, loadFlowEditor }: FlowTrans
onChange={handleChange}
data-testid="translation-options"
>
<FormControlLabel value="auto" control={<Radio />} label={t('Automatic translation')} />
<FormControlLabel value="export" control={<Radio />} label={t('Export translations')} />
<FormControlLabel value="import" control={<Radio />} label={t('Import translations')} />
{translationOptions.map((option) => (
<div key={option.value}>
<FormControlLabel
value={option.value}
control={<Radio className={styles.Radio} />}
label={option.label}
/>
<FormHelperText className={styles.FormHelper}>{option.description}</FormHelperText>
</div>
))}
</RadioGroup>
{action === 'import' ? importButton : ''}
</FormControl>
Expand All @@ -140,7 +177,7 @@ export const FlowTranslation = ({ flowId, setDialog, loadFlowEditor }: FlowTrans

return (
<DialogBox
title="Translate Flow"
title="Translate Options"
alignButtons="center"
buttonOk="Submit"
buttonCancel="Cancel"
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/queries/Flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export const RELEASE_FLOW = gql`
`;

export const EXPORT_FLOW_LOCALIZATIONS = gql`
query exportFlowLocalization($id: ID!) {
exportFlowLocalization(id: $id) {
query exportFlowLocalization($id: ID!, $addTranslation: Boolean) {
exportFlowLocalization(id: $id, addTranslation: $addTranslation) {
exportData
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/i18n/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,5 +442,10 @@
"Response JSON": "Response JSON",
"Webhook Logs": "Webhook Logs",
"Translate": "Translate",
"An error occured while translating flows.": "An error occured while translating flows."
"An error occured while translating flows.": "An error occured while translating flows.",
"Export with auto translate": "Export with auto translate",
"Generate translations for all available languages automatically.": "Generate translations for all available languages automatically.",
"Translate the content and export it as a CSV file.": "Translate the content and export it as a CSV file.",
"Export the content without any automatic translations.": "Export the content without any automatic translations.",
"Import translations from a CSV file into the application.": "Import translations from a CSV file into the application."
}

0 comments on commit b921c28

Please sign in to comment.