Locale
The context object in a request describes the location and visitor requesting data. The values in the object are used to select which rules are applied during search.
You have to use the locale object to set the locale in the context for a request included in Sitecore Search JavaScript SDK for React. The locale is represented by two-letter codes for country and language.
|
Property |
Type |
Description |
|---|---|---|
|
|
string |
Required. Two-letter country code in the ISO 3166 Alpha 2 format. For example, use us for the United States. |
|
|
string |
Required. Two-letter language code in the ISO 639-1 format. For example, use es for Spanish. |
Set or update context locale
We recommend you set the locale in your application in your first search or recommendation request so that the SDK stores the locale and populates it in future requests. If the locale changes during a visit, you must update the locale using the SDK for accurate reporting.
Locale settings apply to all requests and widgets. It is a page level setting.
To set or update the locale in context for search requests:
-
Use the following code block, replacing your own values:
RequestResponseimport { PageController } from '@sitecore-search/react'; const context = PageController.getContext(); context.setLocaleLanguage('en'); context.setLocaleCountry('us');
For a complete locale implementation, you can view the code in the starter kit website GitHub repository.