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

233 auto translation flag #302

Merged
merged 35 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
eac769f
add translationVerified checkbox to identificationTab
sorochak Dec 19, 2023
d25815e
fix translationVerified checkbox
sorochak Dec 20, 2023
3ed8382
add translationVerified checkbox for abstract
sorochak Dec 20, 2023
1985a1f
add translationVerified checkbox for limitations
sorochak Dec 20, 2023
48feafc
add translationVerified checkbox for platformDescription
sorochak Dec 20, 2023
b2853a5
update component to receive props for dynamic checkbox
sorochak Dec 20, 2023
14b9dfd
move verifyTranslate into bilingualTextInput
sorochak Dec 20, 2023
da95ab6
move verifyTranslate into bilingualTextInput
sorochak Dec 20, 2023
e86d05b
update translationVerified variable names
sorochak Dec 20, 2023
b5b1b40
add new prop and invoke prop function to pass a message
sorochak Jan 10, 2024
199ad50
define translateMethod handler and pass to BilingualTextInput
sorochak Jan 10, 2024
56013f9
pass handler to Platform.jsx
sorochak Jan 10, 2024
25b77f8
pass handler to BilingualTextInput
sorochak Jan 10, 2024
73d436a
dynamically generate handler based on field name
sorochak Jan 10, 2024
922555b
pass field name to handler
sorochak Jan 10, 2024
ba87864
fix scoping issue with handleTranslationComplete
sorochak Jan 10, 2024
c912816
remove console log
sorochak Jan 11, 2024
5b72ce2
define verify_translation function
sorochak Jan 11, 2024
feeb56e
add translation method field to record_yaml
sorochak Jan 11, 2024
3fe64b2
remove unnecessary checkbox name
sorochak Jan 12, 2024
9da2234
Merge remote-tracking branch 'origin/main' into 233-auto-translation-…
sorochak Jan 12, 2024
e0fc89d
update hardcoded translate message, pass message directly to handleTr…
sorochak Jan 12, 2024
862fe64
Merge remote-tracking branch 'origin/main' into 233-auto-translation-…
sorochak Jan 26, 2024
de07a8e
add translation verification to resources
sorochak Jan 29, 2024
bd5155c
encapsulate verify translate checkbox logic into a function
sorochak Jan 29, 2024
f00a1e0
Merge remote-tracking branch 'origin/main' into 233-auto-translation-…
sorochak Jan 29, 2024
5c4b61a
replace dist with resourceItem
sorochak Jan 29, 2024
47a774e
Merge branch 'main' into 233-auto-translation-flag
fostermh Feb 14, 2024
86a49e7
add translation validation boolen and message to bilingual fields
fostermh Feb 14, 2024
3c9c8f5
update build test action
sorochak Feb 22, 2024
7002364
update build test action
sorochak Feb 22, 2024
e28be4f
remove node options from script
sorochak Feb 22, 2024
059803b
remove unused handlers
sorochak Feb 23, 2024
7c3ff0b
Ensure translations field exists on component mount/load
sorochak Feb 27, 2024
ed7314f
add variables to useEffect dependency array
sorochak Feb 27, 2024
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
20 changes: 7 additions & 13 deletions .github/workflows/run-build-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
name: Run Build and Tests
on: push
on:
push:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]
node-version: [16.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
cache: 'npm' # Enable automatic caching for npm
- run: npm ci
- run: npm run build --if-present
- run: npm run test
Expand Down
8 changes: 8 additions & 0 deletions firebase_to_xml/firebase_to_xml/record_json_to_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def eovs_to_fr(eovs_en):
""" Translate a list of EOVs in english to a list in french"""
return [eov_translations.get(eov,"") for eov in eovs_en if eov]

def verify_translation(verified, message):
if not verified:
return message
return ""

def strip_keywords(keywords):
"""Strips whitespace from each keyword in either language"""
Expand Down Expand Up @@ -73,6 +77,7 @@ def record_json_to_yaml(record):
+ "https://cioos-siooc.github.io/metadata-entry-form",
"use_constraints": {
"limitations": record.get("limitations", "None"),
"limitationsTranslationMethod": verify_translation(record.get("translationVerifiedLimitations"), record.get("limitationsTranslationMethod")),
"licence": licenses.get(
record.get(
"license",
Expand Down Expand Up @@ -103,8 +108,10 @@ def record_json_to_yaml(record):
},
"identification": {
"title": record.get("title"),
"titleTranslationMethod": verify_translation(record.get("translationVerifiedTitle"), record.get("titleTranslationMethod")),
"identifier": record.get("datasetIdentifier"),
"abstract": record.get("abstract"),
"abstractTranslationMethod": verify_translation(record.get("translationVerifiedAbstract"), record.get("abstractTranslationMethod")),
"dates": {
"creation": date_from_datetime_str(record.get("dateStart")),
"publication": date_from_datetime_str(record.get("datePublished")),
Expand Down Expand Up @@ -158,6 +165,7 @@ def record_json_to_yaml(record):
record_yaml["platform"] = {
"id": record.get("platformID"),
"description": record.get("platformDescription"),
"platformDescriptionTranslationMethod": verify_translation(record.get("translationVerifiedPlatformDescription"), record.get("platformDescriptionTranslationMethod")),
"type": record.get("platform"),
}

Expand Down
91 changes: 83 additions & 8 deletions src/components/FormComponents/BilingualTextInput.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useContext, useState } from "react";
import React, { useContext, useState, useEffect } from "react";
import {
Button,
InputAdornment,
TextField,
CircularProgress,
Tooltip,
} from "@material-ui/core";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import Checkbox from "@material-ui/core/Checkbox";
import TranslateIcon from "@material-ui/icons/Translate";
import ArrowDownwardIcon from "@material-ui/icons/ArrowDownward";
import { useParams } from "react-router-dom";
Expand All @@ -27,11 +29,6 @@ const BilingualTextInput = ({
const { translate } = useContext(UserContext);
const [awaitingTranslation, setAwaitingTranslation] = useState(false);

function handleEvent(e) {
const newData = { ...value, [e.target.name]: e.target.value };
const newDataEvent = { target: { name, value: newData } };
onChange(newDataEvent);
}
const { language } = useParams();
let languages;

Expand All @@ -40,6 +37,66 @@ const BilingualTextInput = ({

if (language === "en") languages = ["en", "fr"];
else languages = ["fr", "en"];
const alternateLanguage = languages[1];
const translateChecked =
value?.translations?.[alternateLanguage]?.verified || false;

function setTranslationData(translations, checked) {
return {
...translations,
[alternateLanguage]: {
verified: checked,
...(!checked && {
message: `text translated using the Amazon translate service / texte traduit à l'aide du service de traduction Amazon`,
}),
},
};
}

function handleEvent(e) {
const { translations, ...rest } = { ...value };
const newData = {
...rest,
[e.target.name]: e.target.value,
...(e.target.name === alternateLanguage &&
e.target.value && {
translations: value.translations || setTranslationData({}, false),
}),
};
const newDataEvent = { target: { name, value: newData } };
onChange(newDataEvent);
}

function handleTranslateCheckEvent(e) {
const { checked } = e.target;
const newData = {
...value,
translations: setTranslationData(value.translations, checked),
};
const newDataEvent = { target: { name, value: newData } };
onChange(newDataEvent);
}

// Ensure translations field exists on component mount/load
useEffect(() => {
if (value && !value.translations) {
const hasTranslations = value.en && value.fr;
if (hasTranslations) {
const updatedValue = {
...value,
translations: {
fr: {
verified: false,
message:
"text translated using the Amazon translate service / texte traduit à l'aide du service de traduction Amazon",
},
},
};
onChange({ target: { name, value: updatedValue } });
}
}
}, [name, onChange, value]);

return (
<div>
{languages.map((lang, i) => (
Expand All @@ -48,7 +105,7 @@ const BilingualTextInput = ({
name={lang}
fullWidth
value={value?.[lang] || ""}
onChange={handleEvent}
onChange={(e) => handleEvent(e)}
InputProps={{
startAdornment: (
<InputAdornment position="start">
Expand Down Expand Up @@ -87,7 +144,6 @@ const BilingualTextInput = ({
textTooBig
}
onClick={() => {
const alternateLanguage = languages[1];
setAwaitingTranslation(true);

translate({ text: value[lang], fromLang: lang }).then(
Expand All @@ -100,6 +156,7 @@ const BilingualTextInput = ({
value: translation,
},
});
// onTranslateComplete();
}
);
}}
Expand All @@ -109,6 +166,24 @@ const BilingualTextInput = ({
<Fr>Traduire</Fr>
</I18n>
</Button>
{value?.[alternateLanguage] && (
<FormControlLabel
control={
<Checkbox
checked={translateChecked}
onChange={(e) => handleTranslateCheckEvent(e)}
color="primary"
/>
}
label={
<I18n>
<En>I have verified this translation</En>
<Fr>J'ai vérifié cette traduction</Fr>
</I18n>
}
/>
)}

{textTooBig && (
<I18n>
<En>
Expand Down
2 changes: 2 additions & 0 deletions src/components/FormComponents/Instruments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const Instruments = ({
</I18n>
</Typography>
<BilingualTextInput
name="type"
label={typeLabel}
value={instrument.type}
onChange={updateInstrumentField("type")}
Expand All @@ -158,6 +159,7 @@ const Instruments = ({
<Grid item xs>
<Typography>Description</Typography>
<BilingualTextInput
name="description"
label={descriptionLabel}
value={instrument.description}
onChange={updateInstrumentField("description")}
Expand Down
1 change: 1 addition & 0 deletions src/components/FormComponents/Platform.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const Platform = ({ record, handleUpdateRecord, disabled }) => {
</SupplementalText>
</QuestionText>
<BilingualTextInput
name="platformDescription"
value={record.platformDescription}
onChange={handleUpdateRecord("platformDescription")}
multiline
Expand Down
1 change: 1 addition & 0 deletions src/components/FormComponents/Resources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const Resources = ({ updateResources, resources, disabled }) => {
<RequiredMark passes={resourceItem.name?.en || resourceItem.name?.fr} />
</QuestionText>
<BilingualTextInput
name="name"
label={nameLabel}
value={resourceItem.name}
onChange={handleResourceChange("name")}
Expand Down
21 changes: 10 additions & 11 deletions src/components/Tabs/IdentificationTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useParams } from "react-router-dom";
import { OpenInNew, Update } from "@material-ui/icons";
import { En, Fr, I18n } from "../I18n";
import { progressCodes } from "../../isoCodeLists";
import { eovs, eovCategories } from "../../eovs.json";
import { eovs, eovCategories } from "../../eovs";

import firebase from "../../firebase";
import BilingualTextInput from "../FormComponents/BilingualTextInput";
Expand Down Expand Up @@ -279,6 +279,7 @@ const IdentificationTab = ({
</QuestionText>

<BilingualTextInput
name="title"
value={record.title}
onChange={handleUpdateRecord("title")}
disabled={disabled}
Expand Down Expand Up @@ -423,6 +424,7 @@ const IdentificationTab = ({
</QuestionText>

<BilingualTextInput
name="abstract"
value={record.abstract}
onChange={handleUpdateRecord("abstract")}
disabled={disabled}
Expand Down Expand Up @@ -739,13 +741,12 @@ const IdentificationTab = ({
<SupplementalText>
<I18n>
<En>
<p>
Please save the form before generating a draft DOI.
</p>
<p>Please save the form before generating a draft DOI.</p>
</En>
<Fr>
<p>
Veuillez enregistrer le formulaire avant de générer un brouillon de DOI.
Veuillez enregistrer le formulaire avant de générer un
brouillon de DOI.
</p>
</Fr>
</I18n>
Expand Down Expand Up @@ -779,8 +780,8 @@ const IdentificationTab = ({
<div style={{ display: "flex", alignItems: "center" }}>
{loadingDoiUpdate ? (
<>
<CircularProgress size={24} style={{ marginRight: "8px" }} />
Loading...
<CircularProgress size={24} style={{ marginRight: "8px" }} />
Loading...
</>
) : (
"Update DOI"
Expand Down Expand Up @@ -817,10 +818,7 @@ const IdentificationTab = ({
)}
{doiUpdateFlag && (
<span>
<I18n
en="DOI has been updated"
fr="Le DOI a été mis à jour"
/>
<I18n en="DOI has been updated" fr="Le DOI a été mis à jour" />
</span>
)}

Expand Down Expand Up @@ -988,6 +986,7 @@ const IdentificationTab = ({
</SupplementalText>
</QuestionText>
<BilingualTextInput
name="limitations"
value={record.limitations}
onChange={handleUpdateRecord("limitations")}
multiline
Expand Down
1 change: 1 addition & 0 deletions src/components/Tabs/ResourcesTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { validateField } from "../../utils/validate";

const ResourcesTab = ({ disabled, record, updateRecord }) => {
const updateResources = updateRecord("distribution");

return (
<div>
<Paper style={paperClass}>
Expand Down
Loading
Loading