Fixes translation issue of dynamic variables in workflows (#4734)

* replace all underscores for variable translations

* use g instead of replaceAll

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
Co-authored-by: Omar López <zomars@me.com>
This commit is contained in:
Carina Wollendorfer
2022-09-29 15:07:22 +02:00
committed by GitHub
co-authored by CarinaWolli Omar López
parent 6017806763
commit 47df21322d
3 changed files with 6 additions and 6 deletions
@@ -48,7 +48,7 @@ export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
onClick={() => props.addVariable(props.isEmailSubject, t(`${variable}_workflow`))}>
<div className="md:grid md:grid-cols-2">
<div className="mr-3 text-left md:col-span-1">
{`{${t(`${variable}_workflow`).toUpperCase().replace(" ", "_")}}`}
{`{${t(`${variable}_workflow`).toUpperCase().replace(/ /g, "_")}}`}
</div>
<div className="invisible text-left text-gray-600 md:visible md:col-span-1">
{t(`${variable}_info`)}
@@ -86,14 +86,14 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
const cursorPosition = refEmailSubject?.current?.selectionStart || currentEmailSubject.length;
const subjectWithAddedVariable = `${currentEmailSubject.substring(0, cursorPosition)}{${variable
.toUpperCase()
.replace(" ", "_")}}${currentEmailSubject.substring(cursorPosition)}`;
.replace(/ /g, "_")}}${currentEmailSubject.substring(cursorPosition)}`;
form.setValue(`steps.${step.stepNumber - 1}.emailSubject`, subjectWithAddedVariable);
} else {
const currentMessageBody = refReminderBody?.current?.value || "";
const cursorPosition = refReminderBody?.current?.selectionStart || currentMessageBody.length;
const messageWithAddedVariable = `${currentMessageBody.substring(0, cursorPosition)}{${variable
.toUpperCase()
.replace(" ", "_")}}${currentMessageBody.substring(cursorPosition)}`;
.replace(/ /g, "_")}}${currentMessageBody.substring(cursorPosition)}`;
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, messageWithAddedVariable);
}
}
@@ -45,12 +45,12 @@ export function translateVariablesToEnglish(text: string, language: { locale: st
originalVariables.forEach((originalVariable) => {
const newVariableName = variable.replace("_NAME", "");
if (
language.t(originalVariable).replace(/ /, "_").toUpperCase() === variable ||
language.t(originalVariable).replace(/ /, "_").toUpperCase() === newVariableName
language.t(originalVariable).replace(/ /g, "_").toUpperCase() === variable ||
language.t(originalVariable).replace(/ /g, "_").toUpperCase() === newVariableName
) {
newText = newText.replace(
variable,
language.t(originalVariable, { lng: "en" }).replace(" ", "_").toUpperCase()
language.t(originalVariable, { lng: "en" }).replace(/ /g, "_").toUpperCase()
);
return;
}