/// <summary>
        /// Ensures generated URL contains lang parameter for multilingual site
        /// </summary>
        /// <param name="dest"></param>
        /// <returns></returns>
        public static string Link(string dest)
        {
            string[] anchor = dest.Split('#');

            Uri link = GetUri(dest);

            string baseURL = link.GetLeftPart(UriPartial.Path);

            System.Collections.Specialized.NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(link.Query.ToString());

            queryString["lang"] = LangHelper.GetCurrentLangStringShort();

            return(baseURL + "?" + queryString.ToString() + (anchor.Count() > 1 ? "#" + anchor[1].ToString() : ""));
        }
Exemple #2
0
        /// <summary>
        /// Returns an alternate-language url for language switching.
        /// ie, if the current language is English, this will return the URL to switch to French.
        /// Preserves querystring attributes.
        /// Called by GetLanguageSwitchLink()
        /// </summary>
        /// <returns></returns>
        public static string GetTranslatedURL()
        {
            // first get the left part of the URI
            string url     = HttpContext.Current.Request.Url.ToString();
            Uri    uri     = new Uri(url);
            string baseURL = uri.GetLeftPart(UriPartial.Path);

            // get the query parameter collection and either add or change the "lang" parameter
            System.Collections.Specialized.NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(HttpContext.Current.Request.Url.Query.ToString());
            queryString["lang"] = LangHelper.GetCurrentLanguage() == Language.English ? "fr" : "en";

            // return the rebuilt url
            return(baseURL + "?" + queryString.ToString());
        }
Exemple #3
0
 /// <summary>
 /// Returns a hyperlink to alternate language uri
 /// ie: <a href="Default.aspx?lang=fr" lang="fr">Français</a>
 /// </summary>
 /// <returns></returns>
 public static string GetLanguageSwitchLink()
 {
     return(String.Format(@"<a href=""{0}"" lang=""{1}"">{2}</a>", GetTranslatedURL(), LangHelper.GetCurrentLanguage() == Language.French ? "en" : "fr", LangHelper.GetCurrentLanguage() == Language.French ? "English" : "Français"));
 }