magnattic
magnattic

Reputation: 12998

Generate localized URL for a translated page

According to How localization works I can translate pages and give them a different URL for every language.

Example from the tutorial:

My question is now: Assuming I know which language I am currently in, how do I find out what the URL title for my page is in C#?

What is the best way to use the C1 API to create the correct link to the page in the current language?

Upvotes: 1

Views: 319

Answers (2)

Dmitry Dzygin
Dmitry Dzygin

Reputation: 1308

Variant No1

    public string GetPageUrl(Guid pageId, CultureInfo locale)
    {
        using(var conn = new DataConnection(PublicationScope.Published, locale))
        {
            var pageNode = new SitemapNavigator(conn).GetPageNodeById(pageId);
            return pageNode != null ? pageNode.Url : null;
        }
    }

Variant No2

    public string GetPageUrl(Guid pageId, CultureInfo locale)
    {
        var pageUrlData = new PageUrlData(pageId, PublicationScope.Published, locale);
        return PageUrls.BuildUrl(pageUrlData, UrlKind.Public, new UrlSpace());
    }

Upvotes: 1

aeont
aeont

Reputation: 106

atticae, have a look to the CurrentPageNode - @CurrentPageNode.MenuTitle

Upvotes: 0

Related Questions