# Translations for Product Updates

Automate the translation process for product updates by modifying the [New Product Introduction](https://developer.emporix.io/value-stream-modeller/value-stream-library/new-product-introduction) value stream to trigger on product updates instead of product creation. This template helps you ensure that products are only translated once, preventing duplicate translation processes and improving efficiency.

{% hint style="info" %}
This is a technical documentation that requires working knowledge of the Orchestration Engine and Make. The setup process involves configuring mixins, modifying value stream triggers, and updating Make scenarios. For more information, see the [Orchestration Engine documentation](https://app.gitbook.com/s/8dAaH7DfB59pzZwLxmur/getting-started/understanding-make).
{% endhint %}

## Key features

| Feature / Component        | Description                                                                                        |
| -------------------------- | -------------------------------------------------------------------------------------------------- |
| **Conditional processing** | Ensures the translation process only runs for untranslated products using mixin-based tracking.    |
| **Update-based trigger**   | Responds to product update events instead of creation events, providing more flexibility.          |
| **Translation tracking**   | Uses custom mixins to track which products have been processed, preventing duplicate translations. |
| **Efficient automation**   | Automatically skips already-translated products, reducing unnecessary processing.                  |

This template modification of the New Product Introduction value stream includes the following configuration:

1. Trigger on `product.updated` events instead of `product.created` events
2. Add a condition to check if a product has already been translated
3. Mark products as translated after the translation process completes

The process uses a custom mixin (`TranslationValueStream`) to track whether a product has been processed, ensuring the translation workflow only runs for products that need translation.

## Prerequisites

Before setting up this process, ensure you have:

* A new [New product introduction](https://developer.emporix.io/value-stream-modeller/value-stream-library/new-product-introduction) value stream
* Access to the Mixin Schema MD Module
* Access to the scenario module "Update product with translation"

## Value stream configuration

### Modify the process trigger

Change the process trigger from **Product Created** to **Product Updated**. You can do the change directly in VSM, or later in Management Dashboard.

* In VSM, change the trigger by editing it's configuration and choosing `product updated` from the events list. Save your changes.

<figure><img src="https://1024162941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSc4haeKWrTrOPHzdrMO%2Fuploads%2Fgit-blob-681ea29a5da8ef4305a1d5ea1d2bc0d9269b61a9%2Fnp_update_vsm.png?alt=media" alt=""><figcaption></figcaption></figure>

* In MD, go to **Orchestration** -> **Value Streams** and select your process. Change the `product.created` to `product.updated` event for the trigger.

<figure><img src="https://1024162941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSc4haeKWrTrOPHzdrMO%2Fuploads%2Fgit-blob-6668a17b22a6a0b21ff9fa0bbf6048d1311ad70f%2Fnp_update_trigger.png?alt=media" alt=""><figcaption></figcaption></figure>

### Create the custom mixin schema

The mixin is used to track whether a product has already gone through the translation process.

{% stepper %}
{% step %}

#### Navigate to Mixin Schema MD Module

Go to the Management Dasboard -> **Settings** -> **Mixin Schemas**.
{% endstep %}

{% step %}

#### Create a new mixin

Choose **Add New Mixin Schema** and create a new mixin with the following configuration:

* Entity - PRODUCT
* Name - `TranslationValueStream`

<figure><img src="https://1024162941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSc4haeKWrTrOPHzdrMO%2Fuploads%2Fgit-blob-8b3f063496e13c41d5f6f772fae5ae94a72faaf7%2Fnp_mixin.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Define the mixin fields

Add a single boolean field to the new mixin schema:

* Type - boolean
* Name - `isTranslated`

<figure><img src="https://1024162941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSc4haeKWrTrOPHzdrMO%2Fuploads%2Fgit-blob-47cc0a63c95f01f89a54a8f02114b8f5a849e39f%2Fnp_mixin_fields.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### Add the pre-execution condition

To prevent the process from running on products that are already translated, add a condition to the value stream that checks for the existence and value of the `isTranslated` flag within the `TranslationValueStream` mixin.

The condition ensures the value stream only starts if:

* The `TranslationValueStream.isTranslated` field is missing (i.e., it's a new product or one never processed), OR
* The `isTranslated` field is present but set to `false`.

**Condition to add:**

```json
{
  "or": [
    {"missing": ["context.mixins.TranslationValueStream.isTranslated"]},
    {"==": [{"var": "context.mixins.TranslationValueStream.isTranslated"}, false]}
  ]
}
```

<figure><img src="https://1024162941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSc4haeKWrTrOPHzdrMO%2Fuploads%2Fgit-blob-916434a7848dc83c49d7f7c7eb8c5e93c74dbe54%2Fnp_update_condition.png?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
This condition prevents the value stream from running on products that have already been translated, improving efficiency and preventing duplicate translations.
{% endhint %}

### Modify the scenario to mark products as translated

After the translation process is complete, the product must be marked as translated by adding the mixin.

{% stepper %}
{% step %}

#### Open the scenario in Make

Go to the scenario named **Update product with translation**. You can open the scenario directly from the value stream's process step. It's the last one in the flow.

<figure><img src="https://1024162941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSc4haeKWrTrOPHzdrMO%2Fuploads%2Fgit-blob-cc3257f85603124f8626a8d3332d926635365f83%2Fnp_update_scenario.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1024162941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSc4haeKWrTrOPHzdrMO%2Fuploads%2Fgit-blob-75a763ba25b51c1386ca8a62263bcc0e1f125e74%2Fnp_update_Make.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Add a PATCH call

After the step that performs the actual translation (or as a final step in the scenario), add a new action. This action must be a PATCH API call to the Product endpoint, setting the `TranslationValueStream` mixin with `isTranslated` set to `true`.

**PATCH Call Details:**

* Method - PATCH
* Endpoint - `/products/{productId}` (using context ID)
* Body - See the payload structure below

The scenario already includes one Make an API Call module, do not modify it.

<figure><img src="https://1024162941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSc4haeKWrTrOPHzdrMO%2Fuploads%2Fgit-blob-e2daded2eaef0e531c785c7f5f71ca7e4313c00a%2Fnp_update_PATCH.png?alt=media" alt=""><figcaption></figcaption></figure>

It should be left as it is - clone the module and paste the clone at the end of the process.

<figure><img src="https://1024162941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSc4haeKWrTrOPHzdrMO%2Fuploads%2Fgit-blob-b18127bfb792af386925deceb7dcef17be9cf9be%2Fnp_update_MakePATCH.png?alt=media" alt=""><figcaption></figcaption></figure>

Modify the module's body:

```json
{
  "metadata": {
    "mixins": {
      "TranslationValueStream": "https://res.cloudinary.com/saas-ag/raw/upload/schemata2/testTenant/TranslationValueStream_v1.json"
    }
  },
  "mixins": {
    "TranslationValueStream": {
      "isTranslated": true
    }
  }
}
```

{% hint style="warning" %}
The `TranslationValueStream` link should point to the schema you created for your tenant. For example: `https://res.cloudinary.com/saas-ag/raw/upload/schemata2/featuredemo/694172749688306411960eaf_v1.json`.

The link pattern is `https://res.cloudinary.com/saas-ag/raw/upload/schemata2/yourtenant/yourschemaid.json`.

You can also copy the link from the GET response - open your schema in MD and check the response through inspect. Your schema URL is visible in metadata, you can copy it from there.

<img src="https://1024162941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSc4haeKWrTrOPHzdrMO%2Fuploads%2Fgit-blob-d6d24bd58e617ebb781fe0dbe0548315ef336cb0%2Fnp_schema_link.png?alt=media" alt="" data-size="original">
{% endhint %}
{% endstep %}

{% step %}

#### Save the scenario

Make sure to save your configuration changes in the Make scenario by clicking the floppy disc icon at the bottom.

<figure><img src="https://1024162941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSc4haeKWrTrOPHzdrMO%2Fuploads%2Fgit-blob-80d356c07c6e2da138905083566553ab193495ad%2Fnp_update_scenarioSave.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

## Verification and testing

After setting up the process, verify it works correctly with the following test cases:

| Test Case                   | Expected Outcome                                                                                                  | Condition Check                  |
| --------------------------- | ----------------------------------------------------------------------------------------------------------------- | -------------------------------- |
| New Product Creation        | Value stream runs (triggered by Product Updated following creation); translation module executes; mixin is added. | `isTranslated` is missing → TRUE |
| Update Untranslated Product | Value stream runs; translation module executes; mixin is added/updated.                                           | `isTranslated` is false → TRUE   |
| Update Translated Product   | Value stream does not run (stopped by pre-execution condition).                                                   | `isTranslated` is true → FALSE   |

{% hint style="info" %}

* To learn more about value stream triggers, see [Creating a Value Stream - Triggers](https://app.gitbook.com/s/8dAaH7DfB59pzZwLxmur/value-streams/working-with-value-streams/creating-value-streams#triggers).
* To learn more about conditions and filters, see [Conditions](https://developer.emporix.io/value-stream-modeller/value-stream-designer/process-components/conditions).
  {% endhint %}
