Appearance
useInternationalization
Definition
Composable for internationalization management.
Basic usage
ts
const {
languages,
currentLanguage,
currentPrefix,
getStorefrontUrl,
getAvailableLanguages,
changeLanguage,
getLanguageCodeFromId,
getLanguageIdFromCode,
replaceToDevStorefront,
formatLink
} = useInternationalization(pathResolver);
Signature
ts
export function useInternationalization(
pathResolver?: Function,
): UseInternationalizationReturn
Parameters
Name | Type | Description |
---|---|---|
pathResolver | Function |
Return type
See UseInternationalizationReturn
ts
export type UseInternationalizationReturn = {
/**
* StorefrontUrl is needed to specify language of emails
*
* @returns {string} storefront URL
*/
getStorefrontUrl(): string;
/**
* Get available languages from backend
*
* @returns {Promise<EntityResult<"language", Language>>} list of languages
*/
getAvailableLanguages(): Promise<EntityResult<"language", Language>>;
/**
* Change current language
*
* @param {string} languageId
* @returns {Promise<ContextTokenResponse>} context object
*/
changeLanguage(languageId: string): Promise<ContextTokenResponse>;
/**
* Get language code from backend language id
*
* @param {string} languageId
* @returns {string} language code
*/
getLanguageCodeFromId(languageId: string): string;
/**
* Get backend language id from language code
*
* @param {string} languageCode
* @returns {string} language
*/
getLanguageIdFromCode(languageCode: string): string;
/**
* Replace to dev url if it is set
*
* @param {string} url
* @returns {string} prefixed url
*/
replaceToDevStorefront(url: string): string;
/**
* List of available languages
*/
languages: Ref<Language[]>;
/**
* Currently used language
*/
currentLanguage: Ref<string>;
/**
* Current prefix from the context
*/
currentPrefix: Ref<string>;
/**
* Add prefix to the Url
* @param {string | RouteObject} link
*/
formatLink(link: string | RouteObject): string | RouteObject;
};
Properties
Name | Type | Description |
---|---|---|
languages | Ref<Array<Language>> | List of available languages |
currentLanguage | Ref<string> | Currently used language |
currentPrefix | Ref<string> | Current prefix from the context |
Methods
Name | Type | Description |
---|---|---|
getStorefrontUrl | string | StorefrontUrl is needed to specify language of emails |
getAvailableLanguages | Promise<EntityResult<, Language>> | Get available languages from backend |
changeLanguage | Promise<ContextTokenResponse> | Change current language |
getLanguageCodeFromId | string | Get language code from backend language id |
getLanguageIdFromCode | string | Get backend language id from language code |
replaceToDevStorefront | string | Replace to dev url if it is set |
formatLink | string | RouteObject | Add prefix to the Url |