> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Implement multi-language search in a single store

> Learn how to implement multi-language search on a single store view with the Algolia for Magento 2 extension.

export const Records = () => <Tooltip tip="A record is a searchable object in an Algolia index. Each record consists of named attributes." cta="Algolia records" href="/doc/guides/sending-and-managing-data/prepare-your-data#algolia-records">
    records
  </Tooltip>;

export const Index = () => <Tooltip tip="An Algolia index is a searchable dataset that consists of records and configuration settings. These settings define how the records are searched and ranked.">
    index
  </Tooltip>;

By default, the extension places each store view's data in a separate index:
each store view has a dedicated <Index /> in a specific language.
For example, searching for *Hemd* in an English store won't return any results.
To show the correct results when searching for *Hemd*,
customize the extension to merge those indices.

## Examples of default records

* **Index name:** `magento2_products_en`

  ```jsonc JSON icon=braces theme={"system"}
  {
    "name": "Shirt",
    "description": "Very nice blue shirt",
    // ... other attributes
  }
  ```

* **Index name:** `magento2_products_de`

  ```jsonc JSON icon=braces theme={"system"}
  {
    "name": "Hemd",
    "description": "Sehr schönes blaues Hemd",
    // ... other attributes
  }
  ```

* **Index name:** `magento2_products_es`

  ```jsonc JSON icon=braces theme={"system"}
  {
    "name": "Camisa",
    "description": "Muy bonita camisa azul",
   // ... other attributes
  }
  ```

## Implement multi-language search

The <Records /> must contain values in all [supported languages](/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/supported-languages) to search on one store view in those languages.

### Create a record in the extension

1. [Create a custom extension](/doc/integration/magento-2/guides/create-a-custom-extension),
   which lets you listen to the extension's custom events.

2. Create an event listener for the [`algolia_after_create_product_object`](/doc/integration/magento-2/customize/custom-back-end-events#dispatched-after-fetching-products-attributes-for-indexing) event,
   the same way as written in the [custom event extension](https://github.com/algolia/algoliasearch-custom-algolia-magento-2/blob/master/etc/events.xml#L6-L8) [`algolia_products_index_before_set_settings`](https://github.com/algolia/algoliasearch-custom-algolia-magento-2/blob/master/Observer/UpdateProductsSettings.php).

3. From the `$observer` variable passed to the `execute()` method, fetch:

   * `custom_data`
   * `productObject`
   * `subProducts`

4. The Algolia record is an `array` in the `custom_data` object and can be modified like any other PHP array.

5. Fetch searchable attributes, such as name, description, or manufacturer, in all other languages and add it to the record in `custom_data`.
   Structure the data according to the [example record](#showcase-record).

### Example of an observer's `execute()` method

```php PHP icon=code theme={"system"}
public function execute(Observer $observer)
{
    /* @var \Magento\Catalog\Model\Product $product */
    $product = $observer->getData('productObject');

    /*
     * Fetch language-specific values based on $product
     */

    $productRecord = $observer->getData('custom_data');

    $originalName = $productRecord['name'];
    $originalDescription = $productRecord['description'];

    $productRecord['name'] = [
        'en' => $originalName,
        'de' => $germanName,
        'es' => $spanishName,
    ];

    $productRecord['description'] = [
        'en' => $originalDescription,
        'de' => $germanDescription,
        'es' => $spanishDescription,
    ];
}
```

## Index settings

If your records are structured like the [example record](/doc/integration/magento-2/guides/multi-language-search#showcase-record),
you don't need to send specific settings to Algolia because you only need to make *parent* attributes, such as name, description, or manufacturer, searchable.
You can do this in the Magento Admin.

## Showcase record

```jsonc JSON icon=braces theme={"system"}
{
    "name": {
        "en": "Shirt",
        "de": "Hemd",
        "es": "Camisa"
    },
    "description": {
        "en": "Very nice blue shirt",
        "de": "Sehr schönes blaues Hemd",
        "es": "Muy bonita camisa azul"
    }
    // ... other attributes
}
```
