Skip to content

subscribeOnLanguageChange(callback: () => void): TUnsubscribeCallback

The subscribeOnLanguageChange method allows to subscribe to language change events and fire a callback function whenever such event occurs.

Input parameters

callback

callback is a mandatory parameter of arrow function type which represents a callback that will be fired whenever a language change event occurs.

Returned value

A returned value has a type of TUnsubscribeCallback which represents a function that should be called to unsubscribe from the event.

Example

In this example we make a TranslationsApi call to listen to the language change event.

useStorefront(async (storefront) => {
    const translationsApi = await storefront.getApi('TranslationsApi');

    const myCallback = () => {
        alert('Language changed!');
    }

    const unsubscribeFromLanguageChange = translationsApi.subscribeOnLanguageChange(myCallback);

    // at the end
    unsubscribeFromLanguageChange();
});

Translations API methods reference

Objects reference