# Local Testing

In this tutorial, we will explain how to use the ACE **`Set Lang From String`** in the Legends of Learning (LoL) Plugin for Construct 3. We will cover what this ACE does, how to use it, and important considerations when implementing it in your game.

## **What is the `Set Lang From String` ACE?**

The **`Set Lang From String`** action is used to *<mark style="color:blue;">**manually load a language file for testing**</mark>* purposes while you develop your game locally. It allows you to simulate the text translations for different languages within your game.

{% hint style="danger" %} <mark style="color:orange;">**Important Note**</mark><mark style="color:orange;">:</mark> This action is <mark style="color:orange;">**only for testing**</mark> <mark style="color:orange;">**and should**</mark> <mark style="color:orange;">**not be used in the live version**</mark> of your game. In production, Legends of Learning automatically handles the language files and provides translations for the player based on their language settings.
{% endhint %}

### **Step 1: Create a `lang.json` File for Testing**

The **`Set Lang From String`** action requires a **language file in JSON format** that contains translations of the text in your game. This file should be structured like this:

**Example of `lang.json`:**

```json
{
  "en": {
    "ui-play": "Play the game",
    "ui-pause": "Pause",
    "level-complete": "Level Complete"
  },
  "es": {
    "ui-play": "Jugar al juego",
    "ui-pause": "Pausa",
    "level-complete": "Nivel Completado"
  }
}
```

* **"en"** is for English text.
* **"es"** is for Spanish text.
* Each key (e.g., `"ui-play"`) represents a string in your game, and the value is the actual translated text.

### **Step 2: Using the `Set Lang From String` ACE**

The **`Set Lang From String`** action allows you to load a language file (in JSON format) into your game during testing. This is crucial when you want to simulate how Legends of Learning will handle language localization in your game.

<figure><img src="https://3242409510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bZkqK9vYvPkvVDUO4Tp%2Fuploads%2FYN3usOH2Ri3lZZwjyLEh%2Fimage.png?alt=media&#x26;token=5802367a-42ec-457b-88ae-afb385cb12f8" alt=""><figcaption></figcaption></figure>

However, instead of hardcoding the language file in the action, it's better to **read the language file dynamically** using the **AJAX plugin** in Construct 3. This allows for a more flexible and scalable approach, especially if you plan to include multiple language files in your project.

### **Step 3: Create the `langTest.json` File**

Before you can read the language file dynamically, you need to create a **`langTest.json`** file in your Construct 3 project. The structure of this file should follow the same format as **`lang.json`** required by Legends of Learning.

<figure><img src="https://3242409510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bZkqK9vYvPkvVDUO4Tp%2Fuploads%2FKebmUfJJIV2QvLgeTHBo%2Fimage.png?alt=media&#x26;token=07ce4c7c-033e-43c7-a1c7-e82fe4bedf4f" alt=""><figcaption></figcaption></figure>

**Example of `langTest.json`** (This file simulates the content for testing):

```json
{
  "en": {
    "ui-play": "Play the game",
    "ui-pause": "Pause",
    "level-complete": "Level Complete"
  },
  "es": {
    "ui-play": "Jugar al juego",
    "ui-pause": "Pausa",
    "level-complete": "Nivel Completado"
  }
}
```

**Save this file** as `langTest.json` in the **Files** section of Construct 3. This will allow you to load it dynamically during runtime.

<figure><img src="https://3242409510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bZkqK9vYvPkvVDUO4Tp%2Fuploads%2FQ2mPI5WkXij2gzDm2YF9%2Fimage.png?alt=media&#x26;token=c4af27ef-eccd-4b62-b302-89d0dee46d15" alt=""><figcaption><p>Project Bar - Files Section</p></figcaption></figure>

### **Step 4: Set Up the AJAX Plugin and Read the File**

1. **Add the AJAX Plugin** to your project in Construct 3:

<figure><img src="https://3242409510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bZkqK9vYvPkvVDUO4Tp%2Fuploads%2FKjIbCRtmiGij4hJdY4oT%2Fimage.png?alt=media&#x26;token=24ac70de-3ce9-40a1-b5b1-18b472291bd6" alt="" width="300"><figcaption></figcaption></figure>

2. Call **`Request Project File`** action to load the language file dynamically:

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td>Step 1. Request the project file</td><td><a href="https://3242409510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bZkqK9vYvPkvVDUO4Tp%2Fuploads%2FVw8P8lwkmB5sqnKd57nm%2Fimage.png?alt=media&#x26;token=c4787c03-5662-4aef-be41-b19e2d8b9da7">image.png</a></td></tr><tr><td>Step 2. Set the callback tag and the filename to read</td><td><a href="https://3242409510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bZkqK9vYvPkvVDUO4Tp%2Fuploads%2FFZw1rVPNxWc0Yw8x8UrB%2Fimage.png?alt=media&#x26;token=aefa5748-2892-4006-a429-85eb0c601091">image.png</a></td></tr><tr><td>Step 3. Add <strong>On Completed</strong> of the AJAX plugin </td><td><a href="https://3242409510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bZkqK9vYvPkvVDUO4Tp%2Fuploads%2FvhJ7ygrg8fcYnrRMr4Uy%2Fimage.png?alt=media&#x26;token=e3bb8cb9-53df-4bbf-a42d-61a52cd000ab">image.png</a></td></tr><tr><td>Step 4. Assign the callback tag to filter the AJAX response.</td><td><a href="https://3242409510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bZkqK9vYvPkvVDUO4Tp%2Fuploads%2FdHEl0xN9UT2e1ftmRFnb%2Fimage.png?alt=media&#x26;token=11942cd4-10b6-4e8d-b489-dd35c2a015c0">image.png</a></td></tr></tbody></table>

3. Parse the AJAX response and inject it into the Legends of Learning plugin using **`Set Lang From String`** action.

<figure><img src="https://3242409510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bZkqK9vYvPkvVDUO4Tp%2Fuploads%2FKbrjwWOBWwByQOKmeegA%2Fimage.png?alt=media&#x26;token=4646bd6c-dbe2-4a69-8979-3ed8a7711240" alt="" width="410"><figcaption><p>Calling <strong>Set Lang From String</strong></p></figcaption></figure>

<figure><img src="https://3242409510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bZkqK9vYvPkvVDUO4Tp%2Fuploads%2FwrbdUATKDepAhfqxR91I%2Fimage.png?alt=media&#x26;token=50ba131e-51ce-45b4-b707-fde7388b918f" alt=""><figcaption><p>Inject the AJAX response and assign a language to operate</p></figcaption></figure>

{% hint style="warning" %}
Please note that the **Language** parameter of **Set Lang From String** indicates the plugin to read the entries from the AJAX.LastData that corresponds to the **es** language. <mark style="color:orange;">**If you want to change the language for testing, modify this parameter and run your project again**</mark><mark style="color:orange;">.</mark>
{% endhint %}

**Explanation:**

* **AJAX** is used to load the `langTest.json` file asynchronously.
* **`Set Lang From String`** loads the language data into the game from the `langTest.json` file, allowing your game to render the correct localized text during testing.

### **Step 5: Considerations for Using "Set Lang From String"**

While the **"Set Lang From String"** action is a helpful tool for **testing translations locally**, there are a few **important considerations** to keep in mind:

1. **For Testing Only**:
   * **`Set Lang From String`** should **only be used for testing**. In the live version of the game, Legends of Learning will automatically provide the correct translation based on the player's language settings when **`On Start`** condition is triggered. You do not need to manually load the language file in production.
2. **Language Files Must Be Complete**:
   * Ensure that the `lang.json` file you are using is **complete** and contains all the required text keys for your game. If some keys are missing, it might lead to **errors** or **missing translations** in the game.&#x20;

{% hint style="warning" %}
If you provide more than one language in the file, the <mark style="color:orange;">**keys should match in number and key-name, otherwise the platform will reject your language file.**</mark>
{% endhint %}

3. **Don't Use In Production**:

* The **`Set Lang From String`** action is **not necessary in the live game**. Legends of Learning automatically sends the appropriate translations, so your game should rely on the platform’s provided language files rather than hard-coding language changes.

4. **Test All Translations**:

* When you upload your `lang.json` file to Legends of Learning for review, make sure that you have properly tested the **Spanish,  English, or any other translations** in your game. You can use **Test**&#x20;
