Language switch problem at the News page

Topics: Standard packages
Coordinator
Dec 26, 2010 at 1:20 PM

Hi

1) Make sure that the news data you have exist in theother language

2) Check that "News Article" page has a call to "NewsDetails" in both languages

Coordinator
Dec 27, 2010 at 9:35 AM

The function "NewsDetails" - is it a part of one of the packages?  Anyway if you see "empty space where News should be" it is either function weren't called or it was called but it didn't work properly.

Try to edit this function and make it output something even if there's no input data. This way we will see whether the problem is with input data or with the function or with the way you're calling it.

Coordinator
Dec 27, 2010 at 4:01 PM

I checked the tutorial - the function keeps NewsID in url, could it be that when you switch the language it redirects to an incorrect url, which is missing some query string parameters? 

Coordinator
Dec 28, 2010 at 9:24 AM
Edited Dec 28, 2010 at 2:48 PM

You need to write an xslt extension that will be copying query string parameters

1) Create an xslt extension (http://docs.composite.net/C1/XSLT/Adding-an-XSLT-extension.aspx)
2) Add the following method

 

using Composite.Data;

....

        public static string GetTranslationLink(string culture)
        {
            var cultureInfo = new System.Globalization.CultureInfo(culture, false);

            System.Collections.Specialized.NameValueCollection notUsedQueryParameters;
            var rawUrl = System.Web.HttpContext.Current.Request.RawUrl;
            var pageInfo = PageUrl.Parse(rawUrl, out notUsedQueryParameters);
            
            if(pageInfo == null) {
               // In function preview there's no url 
               return string.Empty;
            }

            var urlBuilder = new PageUrl(pageInfo.PublicationScope, cultureInfo, pageInfo.PageId, PageUrlType.Published).Build();
            if (urlBuilder == null)
            {
                // It is possible that page doesn't exist/isn't available by public url
                return string.Empty;
            }

            urlBuilder.AddQueryParameters(notUsedQueryParameters);

            return urlBuilder.ToString();
        }

 

3) If you're using the "Omnicorp" demosite, edit xslt function Omnicorp.Navigation.Quick, find the <a .. /> tags that inser translation url and edit it:
before:

 

   <xsl:stylesheet version="1.0" ...>

    <a href="{$alt/@URL}" title="Change language">...</a>

 

after

 

    <xsl:stylesheet version="1.0" xmlns:example="http://c1.composite.net/Example" ...>
  
  ....
 
    <a href="{example:GetTranslationLink($alt/@Culture)}" title="Change language">

 

 

Coordinator
Dec 30, 2010 at 10:12 AM

It's even easier in this case. Edit /App_Code/Composite/Navigation/LanguageSwitcher/Functions.cs

Add method GetTranslationLink(...) {...}

Find

 new XAttribute("URL", match.Attribute("URL").Value)

replace with

new XAttribute("URL", GetTranslationLink(culture.Name))

Coordinator
Jan 3, 2011 at 9:06 AM

@tvn thanks for the input - it would make good sense to have path/query details from the original URL exposed - it's on our task list :-)