Webround Runtime Utilities
The wr object exposes a set of core utilities designed to manage localization and navigation within the Webround runtime consistently. These tools ensure that the application remains synchronized with the user's preferred language and the site's configurations.
Localization Properties
The runtime exposes the current localization state through two primary properties:
wr.languages: An array of ISO codes (string[]) representing the languages enabled for the site. These are configurable via the Webround editor's left sidebar.wr.locale: A string identifying the currently active locale (e.g.,"en","it").
Utility Functions
changeLanguage(locale: string): void
Updates the application's global state to a new language. The function accepts an ISO code and switches the runtime context, automatically updating all localized components and content via the wr-change-language event.
Example:
wr.utils.changeLanguage('it');
generateHref(path: string): string
A pure function used to generate internal URLs. It calculates the correct path by automatically prepending the active locale to the provided path, ensuring that links point to the correct localized version of the page.
Example:
// If the current locale is 'en'
const link = wr.utils.generateHref('/contact');
// Returns: "/en/contact"
navigate(path: string): void
Performs an immediate client-side navigation to the specified path. This function is "locale-aware": it internally handles path resolution based on the current locale (via the wr-navigate event), ensuring the user remains within the correct linguistic context.
Example:
wr.utils.navigate('/checkout');