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

Fixes translation issue of dynamic variables in workflows #4734

Merged
merged 4 commits into from Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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().replaceAll(" ", "_")}}`}
</div>
<div className="invisible text-left text-gray-600 md:visible md:col-span-1">
{t(`${variable}_info`)}
Expand Down
13 changes: 8 additions & 5 deletions packages/features/ee/workflows/lib/variableTranslations.ts
Expand Up @@ -21,9 +21,12 @@ export function getTranslatedText(text: string, language: { locale: string; t: T
variables?.forEach((variable) => {
const regex = new RegExp(variable, "g"); // .replaceAll is not available here for some reason
const translatedVariable = originalVariables.includes(variable.toLowerCase().concat("_workflow"))
? language.t(variable.toLowerCase().concat("_workflow")).replace(/ /g, "_").toLocaleUpperCase()
zomars marked this conversation as resolved.
Show resolved Hide resolved
? language.t(variable.toLowerCase().concat("_workflow")).replaceAll(/ /g, "_").toLocaleUpperCase()
: originalVariables.includes(variable.toLowerCase().concat("_name_workflow")) //for the old variables names (ORGANIZER_NAME, ATTENDEE_NAME)
? language.t(variable.toLowerCase().concat("_name_workflow")).replace(/ /g, "_").toLocaleUpperCase()
? language
.t(variable.toLowerCase().concat("_name_workflow"))
.replaceAll(/ /g, "_")
.toLocaleUpperCase()
: variable;

translatedText = translatedText.replace(regex, translatedVariable);
Expand All @@ -45,12 +48,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).replaceAll(/ /, "_").toUpperCase() === variable ||
language.t(originalVariable).replaceAll(/ /, "_").toUpperCase() === newVariableName
) {
newText = newText.replace(
variable,
language.t(originalVariable, { lng: "en" }).replace(" ", "_").toUpperCase()
language.t(originalVariable, { lng: "en" }).replaceAll(" ", "_").toUpperCase()
);
return;
}
Expand Down