Query all pages of a translation

Native API

To get all pages in a particular language, you use the GetPageDataList method. Then, you filter based on the Culture property, the LocalizationStrategy, theNodeType, and theRootNodeId. As a result, you get all pages for the specified language.

Use the following code sample:

C#
using System.Linq;
using System.Threading;
using Telerik.Sitefinity.Modules.Pages;

namespace SitefinityWebApp
{
    public class QueryPages_GetAllTranslationsOfPage_NativeAPI
    {
        public void GetAllTranslationsOfPage()
        {
            var cultureInfo = new System.Globalization.CultureInfo("cz");
            var currentCulture = Thread.CurrentThread.CurrentUICulture;
            var ci = System.Globalization.CultureInfo.GetCultureInfo("cz");
            var pageManager = PageManager.GetManager();
            var pages = pageManager.GetPageDataList().Where(pageData =>
                (pageData.Culture == "cz" ||
                pageData.NavigationNode.LocalizationStrategy != Telerik.Sitefinity.Localization.LocalizationStrategy.Split) &&
                pageData.NavigationNode.NodeType == Telerik.Sitefinity.Pages.Model.NodeType.Standard &&
                pageData.NavigationNode.RootNodeId == Telerik.Sitefinity.Abstractions.SiteInitializer.CurrentFrontendRootNodeId)
            .Select(x => x.NavigationNode);
            var filteredTranslations = pages.ToList();
        }

    }
}

Fluent API

To get all live pages, you use the plural facade to get all page nodes. Then, you filter based on the NodeType property and the PageData object.

Use the following code sample:

C#
using System.Globalization;
using Telerik.Sitefinity;

namespace SitefinityWebApp
{
    public class QueryPages_GetAllTranslationOfPage_FluentAPI
    {
        public void QueryPages_GetAllTranslationsOfPage_FluentAPI(CultureInfo ci)
        {
            var childNodes = App.WorkWith()
           .Pages()
           .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
           .Where(p => p.GetPageData() != null && p.NodeType == Telerik.Sitefinity.Pages.Model.NodeType.Standard)
           .ThatArePublished()
           .ThatAreForLanguage(ci)
           .Get();
        }
    }
}

Using Sitemap API

In a multilingual setup, you can query pages from the sitemap only for specific languages. Also, you can get the different translated versions of the same page. To do these, perform the following:

  1. Set the culture for which you want to query the pages using CultureRegion class.
  2. Enumerate the sitemap nodes and get only the PageSiteNodes.
  3. For each such page node, use AvailableLanguages to query its available languages.

Use the following code sample:

C#
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;

namespace SitefinityWebApp.Examples
{
    public partial class GetPagesFromSitemapInSpecificLanguageExample
    {
        public void GetPagesFromSitemapInSpecificLanguage(CultureInfo culture)
        {
            SiteMapProvider pro = SiteMapBase.GetSiteMapProvider(HttpContext.Current.Request.RequestContext);

            using (new CultureRegion(culture))
            {
                SiteMapNodeCollection nodes = pro.GetChildNodes(pro.RootNode);

                foreach (SiteMapNode node in nodes)
                {
                    PageSiteNode pageSiteNode = (node as PageSiteNode);

                    if (pageSiteNode != null)
                    {
                        CultureInfo[] availableLanguages = pageSiteNode.AvailableLanguages;
                        // check available languages for page node. A page node will be returned for pages in specific language even if the an actual page version in that language is not present 
                    }
                }
            }
        }
    }
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.