예제 #1
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());
        }
예제 #2
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"));
 }