Skip to main content

Search and localization

On this page we explain how to work with localization using search indexes. We cover the suggested approaches for both field level and content item localization. With field level localization, users create a single content item with fields for each supported locale, while with content item localization a separate content item is created for each locale.

The type of localization you choose will depend on your use case, but for both field level and content item localization we recommend creating a separate search index for each locale.

Field level localization
Link copied!

A content item created from the localized banner content type schema is shown below. We have added content for the en-GB, fr-FR and de-DE locales.

A field level localized banner with content in English, French and German.

In order to support search in multiple languages, we have created separate search indexes for each locale.

We recommend create a search index for each supported locale.

By default, when you browse records in an index created from a field level localized content item the content for all of the locales for each of the localized properties is shown.

By default all content for all locales is included in your search index.

Adding a locale to the custom payload
Link copied!

To index just the content for a specified locale you will need to modify the custom payload in the indexing webhook creating for the search index you want to work with.

To view the custom payload for a search index, go to the webhooks section and click the webhook name, or choose 'Open indexing webhook" from its menu.

Viewing the indexing webhook for a search index.

  • Scroll to the "payload" section in "Settings" to view or edit the custom payload.

  • Add a locale parameter to the custom payload and specify the locale of the content you want to return.

In the handlebars shown below, we are filtering on content created for the fr-FR locale.

handlebars

{{#withDeliveryContentItem contentItemId=payload.id account="ampproduct" stagingEnvironment="1vkz2i2i1hlau19hndnr03duvb.staging.bigcontent.io" locale="fr-FR"}}
{{{JSONstringify this}}}
{{/withDeliveryContentItem}}

The modified payload is shown in the image below.

The updated payload to filter by locale.

With the modified payload, when the search index is updated, only the content for the locale specified in the custom payload is indexed. So the french index will only contain content for the fr-FR locale.

The fr-FR index now contains just French content.

Content item localization
Link copied!

When using content item localization we recommend creating a search index for each locale you want to use, each with a filter for the corresponding locale.

For example, if you have English, French and German search indexes, each set up for a banner content type, then when a content item created from the banner content type is published, the filter ensures that content will only be added to the corresponding index. So, if you publish a banner content item with the fr-FR locale assigned, the content will be added to the search index that filters on fr-FR content.

We recommend creating a search index for each supported locale when using content item localization.

Filtering by locale
Link copied!

For each index you need to add a filter that matches by locale. To view the the indexing webhook for a search index, go to the webhooks section and click the name of the first webhook in the list, or choose 'Open indexing webhook" from its menu.

Viewing the indexing webhook for a search index.

Scroll down to the "Filters" section and click "Add filter". The filter should match payload.locale with the corresponding locale. In the example shown below we have an index for French content and so we will match with the fr-FR locale.

Adding a filter to index only fr-FR content.

Now when the content item of the specified content type is published (or created or updated if you have defined a staging index) then the content will be added to the index with the corresponding locale. In the example shown below, we are publishing a banner with the fr-FR locale assigned.

Publishing content with the fr-FR locale assigned.

The content is added to the index for the fr-FR locale.

The French content is added to the index with the fr-FR locale filter.

The Webhook delivery helper

Field level localization

Content item localization