Copied to clipboard

Flag this post as spam?

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


  • Saba Tandashvili 29 posts 181 karma points
    Dec 07, 2018 @ 08:32
    Saba Tandashvili
    0

    Switch language on same page.

    Hi, I am using Vorto Package for multilanguage website. I have language switcher which redirects on home page on every switch. Isn't there any ready code which changes language on same page ? I mean without splitting Urls and so on, i need an easy way.

  • Frans de Jong 548 posts 1840 karma points MVP 3x c-trib
    Dec 07, 2018 @ 09:05
    Frans de Jong
    0

    How do you switch the language? By Url?

  • Saba Tandashvili 29 posts 181 karma points
    Dec 07, 2018 @ 09:33
    Saba Tandashvili
    0

    Hi Frans,

    First I have added Domains in Culture and Hostnames. For switching languages i use this code :

    IEnumerable<ILanguage> languages = ApplicationContext.Current.Services.LocalizationService.GetAllLanguages();
    
    @foreach (ILanguage language in languages)
    {
        if (language.IsoCode == "en-US")
        {
              <a href="/en">Eng</a>                              
        }
        if (language.IsoCode == "de-De")
        {
             <a href="/de">GER</a>
        }
     }
    

    Of course it redirects at home page. I need logic for redirecting on same page.

  • Frans de Jong 548 posts 1840 karma points MVP 3x c-trib
    Dec 07, 2018 @ 09:38
    Frans de Jong
    0

    What you could to is the following:

     if (language.IsoCode == "en-US")
     {
          string url = "/en" + Model.Content.Url;
          <a href="@url">Eng</a>                              
     }
    

    I don't know if the language prefix is present on Model.Content.Url. If you've set /en and /de on the hostname than I expect it not to be.

  • Saba Tandashvili 29 posts 181 karma points
    Dec 07, 2018 @ 09:43
    Saba Tandashvili
    0

    Yes language prefix is presented on Model.Content.Url :(

Please Sign in or register to post replies

Write your reply to:

Draft