0

I want to create a two hyperlink English|Malay so that when user click on any of the link and the website language should changed in the sitecore. I am new to Sitecore and I really have no idea how can i achieve it.

2 Answers 2

2

You're not saying much about how you generate the page, if it's view renderings, or so.

But in general, you can append the desired language code to any url. Use the sc_lang query parameter. http://yourhost.com/yoururl?sc_lang=en-MA.

2

This is really about getting the item in its different language versions, then getting the URL for each

I'll assume the item only has those 2 languages. I'll also assume that your site is configured to embed the language in the URL

First lets get the item in each language:

Item tempItem = Sitecore.Context.Database.GetItem(tempID);
foreach (var itemLanguage in tempItem.Languages)
{
    var item = tempItem.Database.GetItem(tempItem.ID, itemLanguage);
    if (item.Versions.Count > 0)
    {
        // do something 
    }
}

(Code copy/pasted from Mark Cassidy's answer to a related question)

Now that you have the item in its differnt languages you can use this code for each one

LinkManager.GetItemUrl(item);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.