Sample Use Cases and Flows

This article presents some possible use cases you can support using the Locale API. This can be a helpful jumping off point as you plan your implementation.

Implement a custom language switcher

You can create a custom language switcher presented as a dropdown of available languages or regions for site visitors to select from.

  1. Call Query Locales with { "visibility": "VISIBLE" } to retrieve a list of all visible locales for the site.

  2. Display the retrieved locales in your custom language switcher, showing each locale's displayName and flag.

  3. When a site visitor selects a different language, use the locale's id and effectiveUrlStructure to construct the appropriate URL for the newly selected language version of the current page, and then redirect the visitor to that URL.

Change primary locale

You can change the site's primary locale, for example if headquarters relocates to a different country.

  1. Call List Supported Locales to see a list of all locales supported by Wix.

  2. Choose a locale from the list and call Get Locale to ensure the locale doesn't already exist on the site as a secondary locale.

    If the locale already exists on the site, call Delete Locale to remove it and its data.

  3. Call Create New Primary Locale to create and set the new primary locale.

  4. Call Get New Primary Locale Status with the token returned from the Create New Primary Locale method and monitor the progress of the change, and continue checking the status until the it returns either FINISH_SUCCESSFUL or FINISH_WITH_ERROR.

  5. If the change is successful, update your app's UI to reflect the new primary locale. If there's an error, inform the Wix user and provide options for troubleshooting or retrying the operation.

Did this help?