Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Osman Coskun 170 posts 404 karma points
    Jan 06, 2019 @ 12:38
    Osman Coskun
    0

    Generate urls in landing page for language selection

    Hello,

    I'm using Jeroen's approach for a long time. Thanks Jeroen :)

    The client wants to have a landing page with logo and language selection buttons. On domain home i added a content picker for home page selection and added a template view with the following code to get special url's for home page.

    @{
    Layout = null;
    var localService = ApplicationContext.Current.Services.LocalizationService;
    IPublishedContent startPage = (IPublishedContent)Model.Content.AncestorOrSelf(1).GetPropertyValue("umbracoInternalRedirectId1");
    <div class="langSelect">
        <ul>
            @foreach (var lang in localService.GetAllLanguages())
            {
                Culture = lang.CultureInfo.Name;
                var url = "http://" + HttpContext.Current.Request.ServerVariables["HTTP_HOST"] + "/" + lang.CultureInfo.TwoLetterISOLanguageName;
                <li><a href="@startPage.Url">@lang.CultureInfo.TwoLetterISOLanguageName.ToUpper()</a></li>
            }
        </ul>
    </div>}
    

    The idea was to list available languages and then change the culture to get language special urls. But it didn't work. I could list the language options but couldn't generate custom urls :(

    What is the best way to display the url for start page in all languages? Thanks in advance.

    Edit : When i change the culture by hard-coding the culture code i get the url.

Please Sign in or register to post replies

Write your reply to:

Draft