Edit

Client API languages (preview)

[This article is prerelease documentation and is subject to change.]

Use the Power Pages Client API languages object, $pages.languages, to retrieve the site's available languages, identify the active language, and switch languages when needed.

Important

  • This is a preview feature.
  • Preview features aren’t meant for production use and might have restricted functionality. These features are subject to supplemental terms of use, and are available before an official release so that customers can get early access and provide feedback.

$pages.languages object

Method Returns Description
getAll() string[] Returns the languages enabled for the website.
getActive() string Returns the currently active language.
setActive(language: string) void Sets the active language and reloads the page.

Client API language example

This example retrieves all languages enabled for the website, gets the active language, and then sets Hindi (India) as the active language, which reloads the page.

Microsoft.PowerPages.onPagesClientApiReady(async function ($pages) {
    const allLanguages = $pages.languages.getAll();
    const activeLanguage = $pages.languages.getActive();
    $pages.languages.setActive('hi-IN');
});